I noted a long time ago, that in a large (as in humongous)
SUB I had written, trying to use a MSGBOX in it would always
cause an error #9 to crop up, so I simply removed the MSGBOX,
and it has worked perfectly ever since, with no errors showing
up. However, in a short SUB I recently did, I really, really
need to ask the user a Yes/No question, and so I tried to use
a MSGBOX function, but if I do, it causes the SUB to zero out
GLOBAL variables (in that SUB, at least).
So, for testing, I replaced the MSGBOX function with the two
simple message boxes below, with no intervening lines of code,
and found out that the first MSGBOX was zeroing out my GLOBAL
variables, which was causing the error messages and other havoc.
(If I remove the MSGBOXes entirely, the SUB works fine, all the
way through.)
Code Snippet I used to test:
'---------------
X=10 'GLOBAL variable (renamed X here to keep it readable)
MSGBOX "X is: " & str$(X)
' Displays "X is: 10" (So far, so good)
MSGBOX "X still 10? X=" & str$(X)
'Displays "X still 10? X= 0" (Not so good.)
'------------------
Needless to say, when X and other GLOBALs used in the SUB
all get zeroed out after the first MSGBOX, it creates havoc,
including out of bounds errors, and the MSGBOX also repeats
itself several (or several dozen) times, for no understandable
reason, as no loops are involved.
This occurs in a relatively short SUB, that's only nested one
level below the Callback function for a particular menu button.
I guess the solution is to never use MSGBOXes for getting user
input or otherwise, in a large program??
I tried to kludge it, by breaking the SUB in question into 3
parts, each just a few lines of code, and calling the 3 in
sequence to do one operation, but still got the same problem in
the one in which I needed to place the MSGBOX.
I'm sure other people have had the same problem, and was
wondering how you worked around it. Do I need to write my
own message box function and call it, rather than being lazy
and using the built-in MSGBOX or INPUTBOX features?
------------------
[This message has been edited by Mike Jenkins (edited July 10, 2001).]
SUB I had written, trying to use a MSGBOX in it would always
cause an error #9 to crop up, so I simply removed the MSGBOX,
and it has worked perfectly ever since, with no errors showing
up. However, in a short SUB I recently did, I really, really
need to ask the user a Yes/No question, and so I tried to use
a MSGBOX function, but if I do, it causes the SUB to zero out
GLOBAL variables (in that SUB, at least).
So, for testing, I replaced the MSGBOX function with the two
simple message boxes below, with no intervening lines of code,
and found out that the first MSGBOX was zeroing out my GLOBAL
variables, which was causing the error messages and other havoc.
(If I remove the MSGBOXes entirely, the SUB works fine, all the
way through.)
Code Snippet I used to test:
'---------------
X=10 'GLOBAL variable (renamed X here to keep it readable)
MSGBOX "X is: " & str$(X)
' Displays "X is: 10" (So far, so good)
MSGBOX "X still 10? X=" & str$(X)
'Displays "X still 10? X= 0" (Not so good.)
'------------------
Needless to say, when X and other GLOBALs used in the SUB
all get zeroed out after the first MSGBOX, it creates havoc,
including out of bounds errors, and the MSGBOX also repeats
itself several (or several dozen) times, for no understandable
reason, as no loops are involved.
This occurs in a relatively short SUB, that's only nested one
level below the Callback function for a particular menu button.
I guess the solution is to never use MSGBOXes for getting user
input or otherwise, in a large program??
I tried to kludge it, by breaking the SUB in question into 3
parts, each just a few lines of code, and calling the 3 in
sequence to do one operation, but still got the same problem in
the one in which I needed to place the MSGBOX.
I'm sure other people have had the same problem, and was
wondering how you worked around it. Do I need to write my
own message box function and call it, rather than being lazy
and using the built-in MSGBOX or INPUTBOX features?
------------------
[This message has been edited by Mike Jenkins (edited July 10, 2001).]
Comment