
vb怎样判断txt中的特定内容?
比如说在程序自身目录下有一个名为database.txt的文件,里面有a=1b=2c=3怎样判断文件里是否有c=3这个内容?如果有的话提示"有c=3"否则提示"没有c=3...
比如说在程序自身目录下有一个名为database.txt的文件,里面有
a=1
b=2
c=3
怎样判断文件里是否有c=3这个内容?如果有的话提示"有c=3"否则提示"没有c=3" 展开
a=1
b=2
c=3
怎样判断文件里是否有c=3这个内容?如果有的话提示"有c=3"否则提示"没有c=3" 展开
展开全部
Private Sub Command1_Click()
'先打开文件,把文件内容读入str。
Dim str As String, tmp As String
Open App.Path & "\database.txt" For Input As #1
Do While EOF(1) = False
Input #1, tmp
str = str & tmp
Loop
Close #1
'查找str中是否有“c=3”
Dim b As Boolean
Dim i As Long
For i = 1 To Len(str)
If InStr(i, str, "c=3", 1) Then
b = True
MsgBox "有c=3"
Exit For
End If
Next i
If b = False Then MsgBox "没有c=3"
End Sub
'先打开文件,把文件内容读入str。
Dim str As String, tmp As String
Open App.Path & "\database.txt" For Input As #1
Do While EOF(1) = False
Input #1, tmp
str = str & tmp
Loop
Close #1
'查找str中是否有“c=3”
Dim b As Boolean
Dim i As Long
For i = 1 To Len(str)
If InStr(i, str, "c=3", 1) Then
b = True
MsgBox "有c=3"
Exit For
End If
Next i
If b = False Then MsgBox "没有c=3"
End Sub
展开全部
最简单的就是:在窗体上画一个按钮command1和文本框text1,然后复制以下代码即可:
Private Sub Command1_Click()
Dim Strling As String, Have As Boolean
Open App.Path & "\database.txt" For Input As #1
Have = False
Do Until EOF(1)
Line Input #1, Strling
Strling = Trim(Strling)
If Strling = Trim(Text1.Text) Then Have = True
Loop
Close #1
If Have = True Then MsgBox "有“" & Trim(Text1.Text) & "”" Else MsgBox "没有“" & Trim(Text1.Text) & "”"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Command1.Caption = "开始查找"
End Sub
Private Sub Command1_Click()
Dim Strling As String, Have As Boolean
Open App.Path & "\database.txt" For Input As #1
Have = False
Do Until EOF(1)
Line Input #1, Strling
Strling = Trim(Strling)
If Strling = Trim(Text1.Text) Then Have = True
Loop
Close #1
If Have = True Then MsgBox "有“" & Trim(Text1.Text) & "”" Else MsgBox "没有“" & Trim(Text1.Text) & "”"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Command1.Caption = "开始查找"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询