我改了一点,可出现了错误了,怎么办?
Sub ReadTextDrawCircle()
'数据文件位置
Dim File As String
CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
File = CommonDialog1.FileName
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
在窗体中插入CommonDialog控件,添加CommandButton控件:
Private Sub CommandButton1_Click()
On Error Resume Next
Dim File As String
CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
File = CommonDialog1.FileName
If File = "" Then Exit Sub
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