Variable handling?
-
- Coder
- Posts: 19
- Joined: Thu Sep 08, 2005 3:14 am
Variable handling?
I need to know how I can not lose the value of a variable when leaving a sub, so that I can go back to it and access that value again.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Code: Select all
DECLARE SUB yoursub ()
DIM SHARED yourvariable
CALL yoursub
PRINT yourvariable
SUB yoursub()
LET yourvariable = 4
END SUB
A more common method is to use a parameter list with the sub, like so:
The SUB doesn't use the value of "subvariable" from the CALL, which the SUB refers to as "yourvariable".
However, it does modify "yourvariable" to 4 which will be returned to the CALL with "subvariable" equal to 4.
*****
Code: Select all
DECLARE SUB yoursub (yourvariable)
CALL yoursub (subvariable)
PRINT subvariable
END
SUB yoursub (yourvariable)
LET yourvariable = 4
END SUB
However, it does modify "yourvariable" to 4 which will be returned to the CALL with "subvariable" equal to 4.
*****
Here's the definition of the COMMON statement:Nathan1993 wrote:You can also use the common statement, but thats really messy and un-good... use it like this... i ferget how to use it though, so check qbs help.[/code]
Code: Select all
COMMON - a non-executable statement that declares global variables for
sharing between modules, or for chaining to another program
*****