Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Error 521
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HazySmoke)345




PostPosted: Fri Feb 03, 2006 9:30 pm   Post subject: Error 521

I'm editing a program that clears the clipboard automatically, but occasionally, that run-time error comes out, telling me that the computer "Cannot open clipboard", but if I wait for a while, and run the program again, it will work once more. So I'm just trying to make the computer to keep trying to clear it if the error comes out.
VisualBASIC:
Sub ClearClipboard()
    On Error GoTo tryagain
   
tryagain:
    Clipboard.Clear
    DoEvents
End Sub


But the run-time error still comes out. Can we make the computer omit it and try again?
Sponsor
Sponsor
Sponsor
sponsor
Brightguy




PostPosted: Sun Feb 05, 2006 9:10 pm   Post subject: Re: Error 521

Of course you could just call ClearClipboard again in your error handling, but to avoid the possibility of an infinite loop you might want to add something like:

VisualBASIC:
intResponse = MsgBox("Another application is using the Clipboard. Retry?", vbRetryCancel)
HazySmoke)345




PostPosted: Mon Feb 06, 2006 9:43 pm   Post subject: Re: Error 521

Brightguy wrote:
Of course you could just call ClearClipboard again in your error handling

What do you mean by that? The thing is that, as my program bumps into an error, it stops no matter what, even if there's the "On Error Goto" statement. I just need some help clearing that problem.
Brightguy




PostPosted: Tue Feb 07, 2006 1:06 pm   Post subject: Re: Error 521

HazySmoke)345 wrote:
The thing is that, as my program bumps into an error, it stops no matter what, even if there's the "On Error Goto" statement.

The problem is that you call Clipboard.Clear again in the error handling, and this has a good chance of causing another error. You can't handle errors when error handling.

If all you want to do is retry until it's free, you wouldn't have to do anything inside your error handling at all - just use Resume to try the line which caused the error again. However, this could cause an infinite loop if the other application really doesn't want to let go of the clipboard.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: