关于读取文本的紧急求助!
我现在急需要将文本格式(比如hac.txt)的数据根据X,Y坐标和半径Radius调到CAD里面画圆,请各位帮帮忙! 以下是数据的格式.其中"MaximumHeight"是没有用的.X Y MaximumHeight Radius<BR> -38 0 11110 0.0474054054054<BR> -38 0.44 11110 0.0474054054054<BR> -37.6189488223 0.22 11110 0.0476319763759<BR> -38.3810511777 0.22 11110 0.0471788344349<BR> -37.6189488223 -0.22 11110 0.0476319763759<BR> -38.3810511777 -0.22 11110 0.0471788344349<BR> -38 -0.44 11110 0.0474054054054<BR> -38 0.88 11110 0.0474054054054<BR> -37.56 0.76210235533 11110 0.047667027027<BR> -38.44 0.76210235533 11110 0.0471437837838<BR> -37.2378976447 0.44 11110 0.0478585473464<BR> -38.7621023553 0.44 11110 0.0469522634644<BR> -37.12 1.03087894124e-015 11110 0.0479286486486<BR> -38.88 1.03087894124e-015 11110 0.0468821621622<BR> -37.2378976447 -0.44 11110 0.0478585473464<BR> -38.7621023553 -0.44 11110 0.0469522634644<BR> -37.56 -0.76210235533 11110 0.047667027027<BR> -38.44 -0.76210235533 11110 0.0471437837838<BR> -38 -0.88 11110 0.0474054054054<BR> -38 1.32 11110 0.0474054054054 Sub ReadTextDrawCircle()
'数据文件位置
Dim File As String
File = "d:/program/vba/data.txt"
Dim txtLine As String
Dim Center(2) As Double
Dim Radius As Double
Open File For Input As #1
Line Input #1, txtLine ' 读第一行标题行。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。
Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标
Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标
Radius = Val(Right(txtLine, 20)) '半径
ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆
Loop
Close #1
ZoomExtents '缩放到全图
End Sub 实在太谢谢老大了!终于搞定了!再谢谢! File = "d:/program/vba/data.txt"<BR>这一句可不可以改成由用户打开并寻找txt文件呢? 可以啊,在实用函数栏目中找吧。 CommonDialog1.Filter = "文本文件 (*.txt)|*.txt|"<BR> CommonDialog1.DialogTitle = "打开文件"<BR> CommonDialog1.FilterIndex = 2<BR> CommonDialog1.ShowOpen<BR> File = CommonDialog1.FileName<BR> 在此感谢二楼的先生,帮我解决CAD与*.TXT连通问题。
------------------------------------------------------------------------
CQY 如果再把修改过的CAD文件(全是圆点)怎么导出到txt中呢? 我改了一点,可出现了错误了,怎么办?
Sub ReadTextDrawCircle()<BR>'数据文件位置<BR> Dim File As String<BR> CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"<BR> CommonDialog1.DialogTitle = "打开文件"<BR> CommonDialog1.ShowOpen<BR> File = CommonDialog1.FileName<BR> Dim txtLine As String<BR> Dim Center(2) As Double<BR> Dim Radius As Double<BR> Open File For Input As #1<BR> Line Input #1, txtLine ' 读第一行标题行。<BR> Do While Not EOF(1) ' 循环至文件尾。<BR> Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。<BR> Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标<BR> Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标<BR> Radius = Val(Right(txtLine, 20)) '半径<BR> ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆<BR> Loop<BR> Close #1<BR> ZoomExtents '缩放到全图<BR>End Sub<BR> 在窗体中插入CommonDialog控件,添加CommandButton控件:
Private Sub CommandButton1_Click()<BR>On Error Resume Next<BR>Dim File As String<BR> CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"<BR> CommonDialog1.DialogTitle = "打开文件"<BR> CommonDialog1.ShowOpen<BR> File = CommonDialog1.FileName
If File = "" Then Exit Sub<BR> Dim txtLine As String<BR> Dim Center(2) As Double<BR> Dim Radius As Double<BR> Open File For Input As #1<BR> Line Input #1, txtLine ' 读第一行标题行。<BR> Do While Not EOF(1) ' 循环至文件尾。<BR> Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。<BR> Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标<BR> Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标<BR> Radius = Val(Right(txtLine, 20)) '半径<BR> ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆<BR> Loop<BR> Close #1<BR> ZoomExtents '缩放到全图<BR>End Sub
页:
[1]
2