Results 1 to 9 of 9

Thread: VB 6.0 do loop error (resolved)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    9

    VB 6.0 do loop error (resolved)

    Hi, i've got a DO - LOOP, but after running it once, it stops, and exits the sub (I think, 'cause he doesnt do the actions after the loop)

    (the file he opens has more than 1 line, so he must run the loop more than 1 time)

    here is the code:

    fnum = FreeFile
    Open file_name For Input As fnum

    TreeView1.Nodes.Clear
    Do While Not EOF(fnum)
    ' Get a line.
    Line Input #fnum, text_line

    getip = Left(text_line, 15)
    getnick = Mid(text_line, 16, Len(text_line))

    TreeView1.Nodes.Add , , "ip" & getip, getnick, 1

    Loop

    Close fnum


    does anyone know why he does this?
    tnx
    Last edited by Deefeketje; Jun 7th, 2004 at 05:23 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Because he's not a good guy?



    Does the text file have just one line in it by any chance?

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: VB 6.0 do loop error

    Originally posted by Deefeketje
    Hi, i've got a DO - LOOP, but after running it once, it stops, and exits the sub (I think, 'cause he doesnt do the actions after the loop)

    (the file he opens has more than 1 line, so he must run the loop more than 1 time)

    here is the code:

    fnum = FreeFile
    Open file_name For Input As fnum

    TreeView1.Nodes.Clear
    Do While Not EOF(fnum)
    ' Get a line.
    Line Input #fnum, text_line

    getip = Left(text_line, 15)
    getnick = Mid(text_line, 16, Len(text_line))

    TreeView1.Nodes.Add , , "ip" & getip, getnick, 1

    Loop

    Close fnum


    does anyone know why he does this?
    tnx
    What is the value of file_name? Does it containd the path as well as the file name?

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    9
    yes, file_name is the path and filename

    this is the code for filr_name

    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
    file_name = file_name & "contacts.txt"

    the strange thing is..
    the first time he does this loop..everything goes perfect..
    but the second time..nothing is done of the actions..

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    9
    the txtfile has more lines

    it is like this:

    #1 ipadress, nickname
    #2 ipadress, nickname
    #3 ipadress, nickname
    #4 ipadress, nickname
    #5 ipadress, nickname
    ...

    every line is a different user

  6. #6
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    try this

    fnum = FreeFile
    Open file_name For Input As #fnum


    Close #fnum
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    9
    it's the same..

    I add 1 person..everything is perfect..
    1 restart..add another one.. still going good..

    but after the next restart he does the same as before..
    (with the restart of the program, it saves the treeview in the txt file, and if the program starts again, it opends the txtfile in the treeview)

    so I only get the first contact..and if I shut down the program..I get an error that it cant save the treeview 'cause the txt file is still open..so you see that he doesnt finishes the loop

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    9
    ok, thank you guys, but I've found the problem myselve

    he stopped the loop because he wanted to add a new contact with the same treeviewkey, so I changed the save procedure..and now everything is perfect!

    but thanks for helping!

  9. #9

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