Results 1 to 3 of 3

Thread: Quick open question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    Ok this reads line 1 on a text file

    Open "c:\yourfile.txt" For Input As #1
    Dim sFirst
    Line Input #1, sFirst
    If sFirst = "yes" Then
    Label1.Visible = True
    Else
    Exit Sub
    End If

    Close #1

    y when i switch line input#1 to 2 it doesnt read line 2? How would i go about change it to line 2.
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Hyperactive Member mikef's Avatar
    Join Date
    Jun 2000
    Location
    Beach bound...
    Posts
    510

    open question


    The #1 stands for the FileNumber that you are accessing not the line #. If you want to get more lines add more line inputs like so:

    Open "c:\yourfile.txt" For Input As #1
    Dim sFirst, sSecond, sThird, sFourth
    Line Input #1, sFirst
    Line Input #1, sSecond
    Line Input #1, sThird
    Line Input #1, sFourth
    If sFirst = "yes" Then
    Label1.Visible = True
    Else
    Exit Sub
    End If

    Close #1


    ...later

    mikeF

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    81
    "Line Input #1" means read a line from file with file descriptor number 1...to read the second line, just call it again. While we're on the subject, you should really get a free file descriptor using FreeFile(), as in:

    Code:
    Dim FNUM as Integer
    
    FNUM=FreeFile()
    Open "C:\whatever.txt" For Input Access Read As #FNUM
    
    ...
    then you'll never have a problem reading the wrong file.



    HTH,

    Toot
    Some cause happiness wherever they go; others, whenever they go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width