|
-
Mar 21st, 2010, 05:19 AM
#1
Thread Starter
Junior Member
global variable
Hi,
I just wanted to be sure that the value of a global variable in VBA is lost when an error is produced. There is not way to solve this problem?? Then , it is not good to use this kind of variables??
Thank you
-
Mar 21st, 2010, 05:53 AM
#2
Re: global variable
the variable may have nothing to do with the error,
the value of the global variables are retained, you should use proper error handling
vb Code:
On Error GoTo errh vtest = "whynot" 'public global variable Err.Raise 99 MsgBox "will not show" Exit Sub errh: vtest = vbNullString
if you comment out the on error goto, excel will break, but the variable will still retain value
Last edited by westconn1; Mar 21st, 2010 at 05:57 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|