|
-
Sep 18th, 2004, 06:16 PM
#1
Thread Starter
Addicted Member
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.
-
Sep 18th, 2004, 06:19 PM
#2
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.
-
Sep 18th, 2004, 06:22 PM
#3
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.
-
Sep 18th, 2004, 06:24 PM
#4
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.
-
Sep 18th, 2004, 06:25 PM
#5
Thread Starter
Addicted Member
I carnt see the file to close it ..?
-
Sep 18th, 2004, 06:28 PM
#6
I've posted the code above. sorry if it's a little late.
-
Sep 18th, 2004, 06:34 PM
#7
Thread Starter
Addicted Member
I get the a compile error : varible not defined.
With that code dglienna....?
-
Sep 18th, 2004, 07:32 PM
#8
Thread Starter
Addicted Member
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
-
Sep 18th, 2004, 09:07 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|