Results 1 to 5 of 5

Thread: Some more reading from a file help please

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Posts
    18

    Some more reading from a file help please

    Grr.. this is really starting to annoy me. I'm trying to read the first thing from each line, but the code I've got is now only reading the first thing on the last line.

    Code:
    Private Sub Form_Load()
    Dim name As String
    Dim i As Integer
    
    'to make sure that it starts at i=0
    i = -1
    
    Open filename For Input As #1
        While Not EOF(1)
        Input #1, name
        i = i + 1
        Wend
    Close #1
    
    
    lblName(i).Caption = name
    Any ideas? Please?

    Thanks.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Well, you actually are reading the first thing from each line, but you are not doing anything with any of the data you pull in, except for the last line try this :
    VB Code:
    1. Private Sub Form_Load()
    2. Dim name As String
    3. Dim i As Integer
    4.  
    5. 'to make sure that it starts at i=0
    6. i = -1
    7.  
    8. Open filename For Input As #1
    9.     While Not EOF(1)
    10.       Input #1, name
    11.       lblName(i).Caption = name
    12.       i = i + 1
    13.     Wend
    14. Close #1
    15.  
    16.  
    17.  
    18. End Sub

    see if that works...

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Posts
    18
    Thanks for that, but there's still a problem. Instead of reading one thing from each line, its reading the first, second, third, fourth thing etc. on each line before going to the next line. Is there a way to JUST read the last line?

    And yes, I *did* put commas between all the entries in the text file

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    try using Line Input, and trim off what you don't need :
    VB Code:
    1. Private Sub Form_Load()
    2. Dim name As String
    3. Dim i As Integer
    4.  
    5. 'to make sure that it starts at i=0
    6. i = -1
    7.  
    8. Open filename For Input As #1
    9.     While Not EOF(1)
    10.       Line Input #1, name
    11.       lblName(i).Caption = Left(name, Instr(1,name",")-1)
    12.       i = i + 1
    13.     Wend
    14. Close #1
    15.  
    16. End Sub

    see if that works
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Command1_Click()
    'if it's comma delimited you can do this.
    'assuming there are four fields per line.
    Dim one, two, three, four
    
    Open "C:\my documents\myfile.txt" For Input As #1
     Do While Not EOF(1)
       Input #1, one, two, three, four
       List1.AddItem one  'list only the 1st variable
     Loop
       Close
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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