|
Post by Psycho on May 7, 2008 20:14:04 GMT -5
Can arrays be globally defined? If so, is there a special way? I am trying to use a subroutine to load equipment names from a text file, then display them in a listbox. After pulling the names from the textfile, I am loading them into an array named "equipment$(a)". I have defined equipment$ as global but if I don't include the listbox command within the subroutine, it shows up completely blank. Stabbing in the dark, I tried defining equipment$() as global but that gives me an error. Obviously, using a gosub instead of a sub eliminates the problem as well but I'd like to know if and how you can globally define an array like this. Any advice would be appreciated. Psycho Computers
|
|
|
Post by StefanPendl on May 8, 2008 1:17:31 GMT -5
You can not use the GLOBAL command for arrays. To define a global array, you DIM it in the main part at the very top of your program. dim GlobalArray(100)
'some code ...
sub ... dim LocalArray(100)
'some code ... end sub
|
|
|
Post by Psycho on May 8, 2008 12:04:59 GMT -5
Thank you Stefan.
PC
|
|
|
Post by hsfrey on May 8, 2008 16:31:21 GMT -5
What worked fine for me was to declare the array name in the global statement, and then define it in a dim statement, as:
global arrayname dim arrayname(10)
If I didn't use the global statement, using the arrayname in a subroutine got me a new, empty version.
|
|
|
Post by StefanPendl on May 8, 2008 18:32:51 GMT -5
global arrayname dim arrayname(10) The variable used with the GLOBAL statement in the above example is a simple global numerical variable. The array used with DIM is a global array, if it is first dimmed in the main portion of the program. Please see the replies by Carl to the thread: weird bug in arrays
|
|