当前位置:编程学习 > VB >>

vb文件读取问题

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

例如 12,96

        86,200

        78,999

        99,6987

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

补充:当读取到符合的,就停止读取
		
追问:LineInput  #1,mytext,这句话有语法错误???
答案:文件名: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 请勿抄袭////////////////////////////////////////////////////////

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

 

上一个:vb.net问题
下一个:谁是VB高手?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,