永发信息网

vb文件读取问题

答案:2  悬赏:40  手机版
解决时间 2021-08-12 12:27
  • 提问者网友:半生酒醒
  • 2021-08-11 18:10

假如一个文件有4行数据,怎样让它一行一行的读,然后分别验证text1.text和text2.text 的内容是否和里面的相同。只要有一行对了即可

例如 12,96

        86,200

        78,999

        99,6987

能不能就这个文件举个例子啊

最佳答案
  • 五星知识达人网友:枭雄戏美人
  • 2021-08-11 18:21

文件名:C:\A.TXT


文件内容:



程序界面:



代码:(控件:label1 label2 command1 timer1)


Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Public Sub putifd()
Static i As Integer
i = Label1.Caption
i = i + 2
Dim a As String, b As Integer, d As Integer
a = ""
b = 0
c = i
Open "c:\a.txt" For Input As #1
Do While Not EOF(1)
a = Input$(1, #1)
If a = Chr(13) Then b = b + 1
If b = c Then
Line Input #1, a
Text1.Text = a
Label1.Caption = i
Exit Do
End If
Loop
Close
End Sub


Public Sub putifs()
Static i As Integer
i = Label2.Caption
i = i + 2
Dim a As String, b As Integer, d As Integer
a = ""
b = 0
c = i
Open "c:\a.txt" For Input As #1
Do While Not EOF(1)
a = Input$(1, #1)
If a = Chr(13) Then b = b + 1
If b = c Then
Line Input #1, a
Text2.Text = a
Label2.Caption = i
Exit Do
End If
Loop
Close
End Sub


Private Sub Timer1_Timer()
Call putifd
Call putifs
If Text1 = "" Or Text2 = "" Then
Timer1.Enabled = False
MsgBox "已经读取至文件尾。", 64
End If


If Text1 = Text2 Then
MsgBox "发现重复行:第" & Label1.Caption & "与第" & Label2.Caption & "行重复。内容为: " & Text1, 64
Timer1.Enabled = False
End If
'//////////////////////////////////////版权所有 QQ 363488415 请勿抄袭////////////////////////////////////////////////////////

全部回答
  • 1楼网友:有你哪都是故乡
  • 2021-08-11 18:56

Dim MyText as string,a as integer

a=0 Open app.path & "\1.txt" for input as #1 do While Not EOF(1)      LineInput  #1,mytext

    if mytext=text.text then

    a=1

    end if

   if mytext=text2.text then

    a=2

   end if

   if a=1 or a=2 then

    exit do

   end if

loop close #1

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯