Local and global variables

by Solitaire (Login Solitaire1)
S

 

Any variables or arrays that you DIM inside a sub are local and are not remembered by any other sub. Local variables stay in memory only as long as the sub code executes, and then they die. If you want to share the variables or arrays throughout the entire program, then you need to either learn how to pass arguments to the parameters in the sub, or declare the variables/arrays as global at the top of the main program:

DIM SHARED myarray(1 TO 21) AS STRING

for a static array
or

REDIM SHARED myarray(1 TO n) AS STRING

for a dynamic array.


Try it both ways and see which works for your program.

Posted on Jan 4, 2010, 9:22 PM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement