12-10-2005, 12:59 AM
Don't use global vars/arrays.
I sure hope this is cool, coz it took its time
|
12-10-2005, 12:59 AM
Don't use global vars/arrays.
12-10-2005, 02:24 AM
Why shouldn't I use global vars/arrays, what if the var/array is used in 2 seperate routines, the you would have to make it global would you not?
12-10-2005, 04:09 AM
It's just bad practice. You can easily send an array to a sub like this...
By the way, it's FB code because of the underscores in the sub names, so it wont run in QB. Code: Declare Sub Print_Data( tArray() As Integer )
12-10-2005, 09:32 PM
How does this code solve my problems, and nevermind I solved it, I figure out that if I would go something like:
Code: declare sub fill(x AS INTEGER, y AS INTEGER,c AS INTEGER) Then when I want to fill somewhere I would simply go" Code: IF inkey$ = "f" OR inkey$ = "F" then Now the x% and y% are the current position and the colour% is... the color, duh. So I use 3 global vars, and it works fine. Now if you want to say that is bad practive go ahead and give me a better way to use the x%, y%, and colour% in otehr SUB's a better way.
12-11-2005, 05:01 AM
Those aren't global variables... They get passed by descriptor.
Once you are inside the sub, the variable names can use the same characters as those outside the sub, without screwing up your code. That's why I never use global variables.
12-11-2005, 08:22 AM
That's what you mean, well then I guess I don't use Global variables, I guess Global variables are those defined as CONST right???
12-11-2005, 08:28 AM
I always thought it was dim shared :???:
12-11-2005, 08:32 AM
I'm not sure, that's why I added ??? to the end, to show I'm not entirely sure, I guess they'd both be considered Global since they use the same values in and out of SUB's/FUNCTIONS's.
12-11-2005, 10:05 AM
Yeah, DIM SHARED creates a global variable. CONST stands for constant, which means it keeps a constant value throughout the program. You'll usually find things like Pi, Gravity, key defines, etc... as constants.
12-11-2005, 10:21 AM
So we were both right, yay, I was right about something I hadn't yet tested.
|
« Next Oldest | Next Newest »
|