明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: 馨馨

VBA开发,刚学请多指教

[复制链接]
发表于 2016-4-27 19:49 | 显示全部楼层

Dim L As Integer
Dim H(10000) As Double, X(10000) As Double, Y(10000) As Double, Z(10000) As Double
Dim Xmax As Double, Xmin As Double, Ymax As Double, Ymin As Double
Sub txt_read()
Dim txtname As String
Dim L As Integer
    Xmax = 0 '初始值
    Ymax=0
    Xmin=0
    Ymin=0       
    Open "E:\demdata.txt" For Input As #1  '打开文件
    Do While Not EOF(1) '文件读取循环
    L = L + 1 '个数加1
    Input #1, H(L), X(L), Y(L), Z(L) '读取文件数据, H贮存点序号,XYZ为坐标
    if Xmax<X(L) then Xmax=X(L)'x找最大
    if Ymax<Y(L) then Ymax=Y(L)'y找最大
    if Xmin>X(L) then Xmin=X(L)'x找最小
    if Ymin>Y(L) then Ymin=Y(L)'y找最小
    Loop '文件读取循环
    Close #1 '关闭文件
debug.print "x最大:";Xmax
debug.print "y最大:";Ymax
End Sub
 楼主| 发表于 2016-4-27 20:04 | 显示全部楼层
vbcad 发表于 2016-4-27 19:49
Dim L As Integer
Dim H(10000) As Double, X(10000) As Double, Y(10000) As Double, Z(10000) As Doub ...

谢谢,我想用求出的最大最小值画一个格网,写的代码指画出一个框,不知道大神会不会,非常感谢
  1. Sub txt_read()
  2. Dim txtname As String
  3. Dim L As Integer

  4.   '读取文件
  5.     L = 0 '初始值
  6.     Open "E:\demdata.txt" For Input As #1  '打开文件
  7.     Xmax = X(0): Xmin = X(0)
  8.     Ymax = Y(0): Ymin = Y(0)
  9.     Do While Not EOF(1) '文件读取循环
  10.     If X(L) >= Xmax Then
  11.     Xmax = X(L)
  12.     End If
  13.     If Y(L) >= Ymax Then
  14.     Ymax = Y(L)
  15.     End If
  16.     If X(L) <= Xmin Then
  17.     Xmin = X(L)
  18.     End If
  19.     If Y(L) <= Ymin Then
  20.     Ymin = Y(L)
  21.     End If
  22.     L = L + 1 '个数加1
  23.     Input #1, H(L), X(L), Y(L), Z(L) '读取文件数据, H贮存点序号,XYZ为坐标
  24.     Loop '文件读取循环
  25.     Close #1 '关闭文件
  26.    
  27. '绘制格网
  28. Dim plineObj As AcadLWPolyline
  29. Dim points(0 To 11) As Double
  30. Dim M As Integer  '行数
  31. Dim N As Integer  '列数
  32. Dim Dx As Double  '每个网格x值
  33. Dim Dy As Double  '每个网格y值
  34. ' 定义多段线的点
  35.     Dx = 14.5
  36.     Dy = 15.6
  37.     M = (Xmax - Xmin) / Dx '求出行数
  38.     N = (Ymax - Ymin) / Dy '求出列数
  39.     points(0) = Xmin: points(1) = Ymin: points(2) = 0
  40.     points(3) = Xmin: points(4) = Ymax: points(5) = 0
  41.     points(6) = Xmax: points(7) = Ymax: points(8) = 0
  42.     points(9) = Xmax: points(10) = Ymin: points(11) = 0
  43.     '在模型空间中创建一个多段线对象
  44.     Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  45.     ZoomAll
  46. End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-26 20:39 , Processed in 0.205856 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表