Vb6 如何从文本文件中查找字符串并加载其行内容

Vb6 如何从文本文件中查找字符串并加载其行内容,vb6,Vb6,我是VB6编程新手。我正在尝试从包含所需字符串的整个文本文件中加载一行 1 abc 2 def 4 ghi 5 klm 6 opq 如果我要查找的单词是“klm”,我希望字符串中包含整行“5 klm”。如何获取它?假设您在变量sFileName中有文件名: Dim iFile as Integer Dim sLine as String, sNewText as string iFile = FreeFile Open "C:\Folder\replacewithpath\db.txt"

我是VB6编程新手。我正在尝试从包含所需字符串的整个文本文件中加载一行

1 abc
2 def
4 ghi
5 klm
6 opq

如果我要查找的单词是“klm”,我希望字符串中包含整行“5 klm”。如何获取它?

假设您在变量sFileName中有文件名:

Dim iFile as Integer
Dim sLine as String, sNewText as string

iFile = FreeFile

Open "C:\Folder\replacewithpath\db.txt" For Input As #iFile
Do While Not EOF(iFile)
  Line Input #iFile, sLine
  If sLine Like "*klm*" Then
   'sLine has got the line , use 
  End If
Loop
Close

抱歉4我的初学者问题,如何或在哪里加载我的db.txt?谢谢!我明白了使用“EAT\db.txt”作为输入,而不是EOF(iFile)行输入,如果sLine类似于“853822DCEE4C6B59D4A9F0C4CDAF97989E29C83A”,则MsgBox sLine End If Loop Close当我得到这一行时如何发出声音。因为msgbox反复显示该行。请再帮我一次:D。哇。它又起作用了!你太棒了!再次感谢你。