vb6逐行读取文本内容并判断是否与两个text里的内容是否一样
vb6逐行读取文本内容并判断是否与两个text里的内容是否一样,如果有一样的行则显示到另一个窗体的文本上.如有多行则多行显示.以下为详细资料.读取d:a.txt的内容,内...
vb6逐行读取文本内容并判断是否与两个text里的内容是否一样,如果有一样的行则显示到另一个窗体的文本上.如有多行则多行显示.
以下为详细资料.
读取d:a.txt的内容,内容如下:
4,对讲机,456,789,2014-9-27 9:33:30
5,测底,741,852,2014-9-28 19:33:30
...
当对讲机与789分别有text1.text和text4.text内容相对时,显示form2窗体. 并在窗体的text1.text多行显示中显示.如有多个对比一样的.则多行显示.
d.txt的对比内容都是第一个逗号与第二个逗号之间对比text1.text 第三个逗点与第四个逗点之间对比text4.text
麻烦给出个详细代码,我对vb不太了解.谢谢了.
对比结束的时候有个msgbox提示对比结束. 展开
以下为详细资料.
读取d:a.txt的内容,内容如下:
4,对讲机,456,789,2014-9-27 9:33:30
5,测底,741,852,2014-9-28 19:33:30
...
当对讲机与789分别有text1.text和text4.text内容相对时,显示form2窗体. 并在窗体的text1.text多行显示中显示.如有多个对比一样的.则多行显示.
d.txt的对比内容都是第一个逗号与第二个逗号之间对比text1.text 第三个逗点与第四个逗点之间对比text4.text
麻烦给出个详细代码,我对vb不太了解.谢谢了.
对比结束的时候有个msgbox提示对比结束. 展开
5个回答
展开全部
Dim MyStr() As String
Private Sub Command1_Click()
Dim t1 As Long, t2 As Long, t3 As Long
Randomize
t1 = Int(UBound(MyStr) * Rnd + 1)
Text1.Text = MyStr(t1)
If UBound(MyStr) < 2 Then Exit Sub
Do
t2 = Int(UBound(MyStr) * Rnd + 1)
Loop While t2 = t1
Text2.Text = MyStr(t2)
If UBound(MyStr) < 3 Then Exit Sub
Do
t3 = Int(UBound(MyStr) * Rnd + 1)
Loop While t3 = t2 Or t3 = t1
Text3.Text = MyStr(t3)
End Sub
Private Sub Form_Load()
Dim fn As Integer, Str As String
ReDim MyStr(0)
fn = FreeFile
Open "C:\TXT.txt" For Input As #fn 'TXT 是文件名
Do Until EOF(fn)
Line Input #fn, Str
If Str <> "" Then
ReDim Preserve MyStr(UBound(MyStr) + 1)
MyStr(UBound(MyStr)) = Str
End If
Loop
Close #fn
End Sub
Private Sub Command1_Click()
Dim t1 As Long, t2 As Long, t3 As Long
Randomize
t1 = Int(UBound(MyStr) * Rnd + 1)
Text1.Text = MyStr(t1)
If UBound(MyStr) < 2 Then Exit Sub
Do
t2 = Int(UBound(MyStr) * Rnd + 1)
Loop While t2 = t1
Text2.Text = MyStr(t2)
If UBound(MyStr) < 3 Then Exit Sub
Do
t3 = Int(UBound(MyStr) * Rnd + 1)
Loop While t3 = t2 Or t3 = t1
Text3.Text = MyStr(t3)
End Sub
Private Sub Form_Load()
Dim fn As Integer, Str As String
ReDim MyStr(0)
fn = FreeFile
Open "C:\TXT.txt" For Input As #fn 'TXT 是文件名
Do Until EOF(fn)
Line Input #fn, Str
If Str <> "" Then
ReDim Preserve MyStr(UBound(MyStr) + 1)
MyStr(UBound(MyStr)) = Str
End If
Loop
Close #fn
End Sub
追问
代码很好,可惜不是我需要的.麻烦了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-30
展开全部
Private Sub Command1_Click()
Dim myData() As String, myLine() As String, myOutput As String, myInputStr As String, i As Integer
Open "D:\a.txt" For Binary As #1
myInputStr = Input(LOF(1), 1)
Close
myData = Split(myInputStr, vbCrLf)
For i = 0 To UBound(myData)
myLine = Split(myData(i), ",")
If myLine(1) = Text1.Text And myLine(3) = Text4.Text Then myOutput = myOutput & myData(i) & vbCrLf
Next
If myOutput <> "" Then
Form2.Show
Form2.Text1.Text = myOutput
End If
MsgBox "处理完毕"
End Sub
Dim myData() As String, myLine() As String, myOutput As String, myInputStr As String, i As Integer
Open "D:\a.txt" For Binary As #1
myInputStr = Input(LOF(1), 1)
Close
myData = Split(myInputStr, vbCrLf)
For i = 0 To UBound(myData)
myLine = Split(myData(i), ",")
If myLine(1) = Text1.Text And myLine(3) = Text4.Text Then myOutput = myOutput & myData(i) & vbCrLf
Next
If myOutput <> "" Then
Form2.Show
Form2.Text1.Text = myOutput
End If
MsgBox "处理完毕"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看不懂这个,我不是学计算机的呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询