Results 1 to 9 of 9

Thread: Annoying loop is stuck!

  1. #1

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    Annoying loop is stuck!

    VB Code:
    1. Private Sub LstSites_Click()
    2. If checkfile("links.txt") = True Then
    3. Open "links.txt" For Input As #1
    4.     While Not EOF(1)
    5.         Line Input #1, strleesin
    6.         If Not strleesin = "" Then
    7.                 If InStr(1, strleesin, ",") = True Then 'Categorie gevonden
    8.                     strtemp1 = Split(strleesin, " , ")(0)
    9.                     strtemp2 = Split(strleesin, " , ")(1)
    10.                         If strtemp1 = LstSites.Text Then
    11.                             LstSites.Text = strtemp1
    12.                             LstCat.Text = strtemp2
    13.                         End If
    14.                 Else 'Geen categorie gevonden
    15.                     strtemp1 = strleesin
    16.                     strtemp2 = ""
    17.                         If strtemp1 = LstSites.Text Then
    18.                             LstSites.Text = strtemp1
    19.                             LstCat.Refresh
    20.                         End If
    21.                 End If
    22.         End If
    23.     Wend
    24. Close #1
    25. End If
    26. End Sub

    Can somebody explain why he also loops the opening of the file en the filecheck procedure? It crashes and says: File already open. That's because something loops my whole sub again! I don't know how!
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    what line is the program stoppin at?

  3. #3

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    Unhappy The open file as #1 line

    The open file procedure!
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  4. #4
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Changing the value probably fires the Click event.

    Put something like this around all the code in your procedure:

    VB Code:
    1. If Not m_blnClick Then
    2.     m_blnClick = True
    3.  
    4. ...
    5.  
    6.     m_blnClick = False
    7. End If
    m_blnClick is a module level variable.

  5. #5
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373
    Try this...

    VB Code:
    1. Private Sub LstSites_Click()
    2. Dim MyFileNumber as Integer
    3. If checkfile("links.txt") = True Then
    4. MyFileNumber = FreeFile
    5. Open "links.txt" For Input As #MyFileNumber
    6.     While Not EOF(MyFileNumber)
    7.         Line Input #MyFileNumber, strleesin
    8.         If Not strleesin = "" Then
    9.                 If InStr(1, strleesin, ",") = True Then 'Categorie gevonden
    10.                     strtemp1 = Split(strleesin, " , ")(0)
    11.                     strtemp2 = Split(strleesin, " , ")(1)
    12.                         If strtemp1 = LstSites.Text Then
    13.                             LstSites.Text = strtemp1
    14.                             LstCat.Text = strtemp2
    15.                         End If
    16.                 Else 'Geen categorie gevonden
    17.                     strtemp1 = strleesin
    18.                     strtemp2 = ""
    19.                         If strtemp1 = LstSites.Text Then
    20.                             LstSites.Text = strtemp1
    21.                             LstCat.Refresh
    22.                         End If
    23.                 End If
    24.         End If
    25.     Wend
    26. Close #MyFileNumber
    27. End If
    28. End Sub


    I put there the FreeFile instruction so you'll get the next file handle available...Good luck!
    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

  6. #6

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267
    By changing the list text it indeed triggered the click event! Thx for all the help!

    Greetz Pierre
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  7. #7
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352
    Did you try to debug your application stepping one line at a time? If you did you would have seen that when it changed the text that it did not finish the routine and started the click routine over again. Stepping one line at a time can be very helpful in debugging your application. Hope that'll help you in the future.

    Joe

  8. #8
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    i think the bug is just in Open "links.txt" For Input As #1
    doesnt it always need a full path and drivename etc etc?

    try this:

    Filename = app.path &"\links.txt"
    Open filename For Input As #1
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  9. #9
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352
    No snake, the loop is the result of changing the text. The textfile automatically opens the file in the current directory if none is specified.

    Joe

    P.S. I hate using App.Path. There is one major problem with it; if your application is not run from the root of a drive then the App.Path has no '\', but if it is run from the root it contains the '\' which means any code written App.Path + "\myfile" fails when run from the root. I always declare a public variable called AppPath that always contains the '\' at the end.

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