vb中如何读取txt文本中的具体一行

来源:百度知道 编辑:UC知道 时间:2024/09/25 08:24:21
在txt文本中有以下内容及格式
x:25.558,y:32.698z:35.548
x:85.845,y:98.964,z:68.489
x:79.124,y:35.002,z:94.532
x:35.005,y:89.989,z:52.443
x:93.335,y:35.902,z:26.006
x:36.103,y:68.489,z:98.245
在vb中如果满足一定条件,如:m>100
如何把txt文本中的某一行(如弟3行)中的x,y,z值分别赋予程序中的变量a,b,c

请大家多多指教!!

Private Sub Command1_Click()
Dim n As Integer, temp, filestr, abcstr, aa, bb, cc, a, b, c

Open "d:\m.txt" For Binary As #1
temp = StrConv(InputB(LOF(1), 1), vbUnicode) '把指定的文件全部读出来
Close #1
filestr = Split(temp, vbCrLf)

k:
n = Int(Val(Trim(InputBox("读取第几行?"))))
If n < 1 Or n > UBound(filestr) + 1 Then
MsgBox "输入错误!请重试!"
GoTo k
End If

abcstr = Split(filestr(n - 1), ",") '把指定的第n行全部读出来
aa = Trim(abcstr(0))
bb = Trim(abcstr(1))
cc = Trim(abcstr(2))

Rem 以下为获取a、b、c的数值
a = Val(Right(aa, Len(aa) - 2))
b = Val(Right(bb, Len(bb) - 2))
c = Val(Right(cc, Len(cc) - 2))
Print a, b, c
End Sub