Posts: 121
Threads: 33
Joined: Jun 2007
I've got a sprawling macro made up of lots of functions as subroutines. To make troubleshooting easier - and so I don't have to run through the entire macro process and subroutines every time I change a line of code to see if it works - I've made judicious use of global variables.
My questions are:
1. Is there a way to clear out (a.) all and (b.) specified global variables (without completely shutting down QM and restarting). I've noticed that on rerunning certain sections of the macro, the new value written to a global variable doesn't completely overwrite the old value.
2. If everything operates within the macro just fine when using global variables, are there any cautions/restrictions when it comes to compiling to EXE?
Thanks!
Posts: 12,073
Threads: 140
Joined: Dec 2002
To clear variables, assign 0 values or new empty variables or use member functions (eg str.all) that clear them. There is no other way. Also you cannot delete variables without restarting QM or reloading file.
Global variables that are used in exe but initialized (assigned some values) somewhere else, eg when QM starts: In exe they will be empty. You have to initialize in exe too.
Posts: 121
Threads: 33
Joined: Jun 2007
Thanks!
On a related question, I haven't had much luck having "thread" variables be accessible throughout the many functions in my macro (while global always works, of course). I'm not talking about the variables passed to/from functions for processing but general stored variables (such as user settings) and declarations that need to be referenced throughout the the macro and function sub processes. Is this where it is appropriate to use global variables? I feel that I should be able to get away with thread variables but perhaps I am wrong.
For an example, my main macro looks something like below, and I need the declarations from the LoadVars and values from INI functions throughout:
Fnc_LoadVars
Fnc_ReadAppIni
Fnc_ReadUserIni
Fnc_DataEntry
if this goto skipped
Fnc_SomeProcess
...
skipped
...
FncAnotherProcess
etc.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Thread variables must be declared in every functions that use them.
If your project uses multiple threads, eg uses mac("Function") to run functions, to share data between threads you have to use global variables.
Posts: 121
Threads: 33
Joined: Jun 2007
Funny, I forgot to ask about the root problem I was seeing:
Is it possible that, using a global variable and without shutting down QM, that on successive runs of the macro some data can be left in the variable's buffer/register? The contents of the str+ variable in question is from a combo box selection that is then processed with some replacerx and other formatting operations. I've seen on several occasions that the last few characters of longer combo box choices sometimes remain when a cb item with shorter text is selected.
Not really concerned because this will be an exe so they will be cleared out each run, but if it's something else I should be worried about I would like to know...
Posts: 12,073
Threads: 140
Joined: Dec 2002