Qbasicnews.com

Full Version: sub and variables.... where must they be declared....
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If you have two or more sub functions that use the same variable, where must i declare that variable...

Imagine the sub doA reads a file and give a valor to a variable called X, then in the suB we use the X variable, if I declare the X variable at the beginning of the program it gives an error, if I declare the X variable in every sub function with dim X, it erase the X valor.....

Sorry if this question is silly, but I am starting using sub functions...

thanks.
It seems to me that you want a global variable. This is performed using a DIM SHARED i.e.

Code:
DECLARE SUB READINA
DECLARE SUB PRINTA
DIM SHARED A$

READINA
PRINTA

SUB READINA
  A$="Hello World"
END SUB

SUB PRINTA
  PRINT A$
END SUB
Thanks, I'll try it, but I think this is I am looking for.