求VB代码:读取txt文件某一行中某一位置的字段
例如:当前文件目录下1.txt1.txt内容:a学号:123b姓名:张三a班级:(10)c电话号码:110用一个按钮将所有含有小写字母a的行中的空格与冒号中间的字段分别显...
例如:当前文件目录下1.txt
1.txt内容:
a 学号: 123
b 姓名: 张三
a 班级: (10)
c 电话号码: 110
用一个按钮将所有含有小写字母a的行中的空格与冒号中间的字段分别显示到text1中和text2中:
即实现:
Text1中显示为:学号
Text2中显示为:班级 展开
1.txt内容:
a 学号: 123
b 姓名: 张三
a 班级: (10)
c 电话号码: 110
用一个按钮将所有含有小写字母a的行中的空格与冒号中间的字段分别显示到text1中和text2中:
即实现:
Text1中显示为:学号
Text2中显示为:班级 展开
1个回答
展开全部
Private Sub Command1_Click()
Open App.Path & "\1.txt" For Binary As #1
T = Input(LOF(1), 1)
Close #1
T1 = Split(T, vbCrLf)
Dim T2(1 To 2) As String
For i = 0 To UBound(T1)
If InStr(1, T1(i), "a") > 0 Then
i1 = i1 + 1
If i1 > UBound(T2) Then Exit For
T1(i) = Replace(T1(i), ":", ":")
T2(i1) = Trim(Mid$(T1(i), InStr(1, T1(i), " "), InStr(1, T1(i), ":") - InStr(1, T1(i), " ")))
End If
Next
Text1.Text = T2(1)
Text2.Text = T2(2)
End Sub
'任务中,请采纳!谢谢!
Open App.Path & "\1.txt" For Binary As #1
T = Input(LOF(1), 1)
Close #1
T1 = Split(T, vbCrLf)
Dim T2(1 To 2) As String
For i = 0 To UBound(T1)
If InStr(1, T1(i), "a") > 0 Then
i1 = i1 + 1
If i1 > UBound(T2) Then Exit For
T1(i) = Replace(T1(i), ":", ":")
T2(i1) = Trim(Mid$(T1(i), InStr(1, T1(i), " "), InStr(1, T1(i), ":") - InStr(1, T1(i), " ")))
End If
Next
Text1.Text = T2(1)
Text2.Text = T2(2)
End Sub
'任务中,请采纳!谢谢!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询