VB读取TXT文件并获取指定内容
如"OK。TXT"文件内存如下:SMT2565215655658846224586OKSMT2569325655652567612556OKSMT256632265565...
如"OK。TXT"文件内存如下:
SMT 2565215655 658846224586 OK
SMT 2569325655 652567612556 OK
SMT 2566322655 658846224586 NO
如何用VB读取TXT内容,实现:
如果第四列内容等于NO,就把有NO的那一行数据的第二列和第三列,分别显示在TEXT1和TEXT2中!如何实现,
代码: 展开
SMT 2565215655 658846224586 OK
SMT 2569325655 652567612556 OK
SMT 2566322655 658846224586 NO
如何用VB读取TXT内容,实现:
如果第四列内容等于NO,就把有NO的那一行数据的第二列和第三列,分别显示在TEXT1和TEXT2中!如何实现,
代码: 展开
展开全部
Private Sub Form_Load()
On Error Resume Next
Open App.Path & "\ok.txt" For Input As #1
Do Until EOF(1)
Line Input #1, x
For Each i In Split(x, vbCrLf)
If LCase(Right(i, 2)) = LCase("no") Then Text2.Text = Text2.Text & Trim(Split(i, " ")(1)) & vbCrLf: Text1.Text = Text1.Text & Trim(Split(x, " ")(1)) & vbCrLf
Next
Loop
Close #1
End Sub
'2个textbox,multiline=1,scrollbars=2.代码可以自己改,这里是读取当前文件夹下的ok.txt
On Error Resume Next
Open App.Path & "\ok.txt" For Input As #1
Do Until EOF(1)
Line Input #1, x
For Each i In Split(x, vbCrLf)
If LCase(Right(i, 2)) = LCase("no") Then Text2.Text = Text2.Text & Trim(Split(i, " ")(1)) & vbCrLf: Text1.Text = Text1.Text & Trim(Split(x, " ")(1)) & vbCrLf
Next
Loop
Close #1
End Sub
'2个textbox,multiline=1,scrollbars=2.代码可以自己改,这里是读取当前文件夹下的ok.txt
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'假设你的 Ok.txt 在 E 盘下
Private Sub Command1_Click()
Open "E:\ok.txt" For Input As #1
Text2 = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
Text1 = Mid(Text2, InStr(Text2, "NO") - 34, 10)
Text2 = Mid(Text2, InStr(Text2, "NO") - 18, 12)
End Sub
Private Sub Command1_Click()
Open "E:\ok.txt" For Input As #1
Text2 = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
Text1 = Mid(Text2, InStr(Text2, "NO") - 34, 10)
Text2 = Mid(Text2, InStr(Text2, "NO") - 18, 12)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询