Results 1 to 9 of 9

Thread: Runtime Error '55':[Resolved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    uk liverpool
    Posts
    238

    Runtime Error '55':[Resolved]

    HI.

    If i double click the cmdDisplay button i get the error below.

    Runtime error '55': File already open

    Code:

    Private Sub cmdDisplay_Click()

    Dim nom As String, phoneNum As String
    picNumbers2.Cls
    Open "C:\PHONE.TXT" For Input As #1
    Do While Not EOF(1)
    Input #1, nom, phoneNum
    picNumbers2.Print nom, phoneNum
    Loop
    End Sub
    .............................................................................

    Can i prevent it being double clicked ..?

    Thanks

    Paul
    Last edited by whothis; Sep 19th, 2004 at 02:25 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    You aren't really double clicking, you are clicking the same thing twice.

    The simple problem is that you are opening a file and not closing it, which is pretty bad practice. Now, you might be keeping it open for a reason, but don't. Far easier to open it again later than to try to remember whether or not it is open.

    On the other hand, you don't really want that code to run twice, anyways. Therefore, you might want to set a boolean at the form level to tell you when it has been run, and don't run it if the boolean is set.

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    well, the error is caused by not having a CLOSE #1 after you read the file. otherwise, you would display the info again.
    you need to put the whole section in the form load section, and hide the section until you press the button, or else use an IF statement for the whole read section.

    Code:
    Private Sub cmdDisplay_Click()
    If alreadyreadflag=0 Then
      alreadyreadflag=1
      Dim nom As String, phoneNum As String
      picNumbers2.Cls
      Open "C:\PHONE.TXT" For Input As #1 
      Do While Not EOF(1)
        Input #1, nom, phoneNum
        picNumbers2.Print nom, phoneNum
      Loop
      Close #1
    endif
    End Sub
    set the flag to 0 in the form load event
    Last edited by dglienna; Sep 18th, 2004 at 06:27 PM.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    lost by 3 minutes!
    add [RESOLVED] to the subject of the first post to mark it as resolved.
    Last edited by dglienna; Sep 18th, 2004 at 06:29 PM.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    uk liverpool
    Posts
    238
    I carnt see the file to close it ..?

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I've posted the code above. sorry if it's a little late.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    uk liverpool
    Posts
    238
    I get the a compile error : varible not defined.

    With that code dglienna....?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    uk liverpool
    Posts
    238
    Dont realy know what this was about (If alreadyreadflag=0 Then
    alreadyreadflag=1) ,but took it out and left this in (Close #1)
    and it worked fine .

    Thanks

    Paul

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    you have to use DIM allreadyreadflag and set it to 0 before you can use it so that it doesn't read things twice. it doesn't hurt to keep it the way you have it, unless the file is BIG.

    add [RESOLVED] to the subject of the first post to mark it as resolved.

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