How to read the line one by one and read out the data correspond?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • youqing
    New Member
    • Aug 2006
    • 3

    How to read the line one by one and read out the data correspond?

    Hello, all:
    I have a problem like this:
    I created a database in txt.like this:
    "143483",12 34
    "143484",12 35
    "143485",55 88
    "143486",58 76
    "143488",85 68
    "143487",87 56
    .......
    I want to make a program which can search the data and read out the data using VB.
    If I input the 143483 into the program, the result will be 1234.
    I programmed like this:
    Private Sub Command1_Click( )
    Dim Target As String
    Dim Current As String
    Open "E:\test1.t xt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, Current
    If (Current = Target) Then
    Label3.Enabled = True
    Text2.Enabled = True
    Text2.Text = Barcode.Width
    Exit Do
    ElseIf (Current <> Target) Then
    Do Until EOF(1)
    Loop
    End Sub
    But it is not working. Hope someone can help me to slove this problem. thanksssss a lot!
  • BSOB
    New Member
    • Jul 2006
    • 77

    #2
    first things first:
    you have opened file as 1, you NEED TO CLOSE IT. bad form to leave it hanging.
    second thing:
    you have an if statment, you have no end if...?
    third thing:
    you have 2 do's, and only 1 loop...?

    Private Sub Command1_Click( )
    Dim Target As String
    Dim Current As String
    Dim Result As Long
    'input target ("143483")
    Open "E:\test1.t xt" For Input As #1
    Do
    Input #1, Current
    If (Current = Target) Then
    Label3.Enabled = True
    Text2.Enabled = True
    Text2.Text = Barcode.Width
    Input #1, Result
    Exit Do
    End If
    Input #1, Result
    Loop Until EOF(1)
    Close 1
    'output result (1234)
    End Sub

    Comment

    Working...