Click to See Complete Forum and Search --> : Declaring global variables
wick77
Jul 6th, 2000, 02:38 PM
How can you declare global variables that can be used throughout all the forms in a project?
An answer would be nice, thanks,
Wick
Jony5
Jul 6th, 2000, 04:04 PM
declare the global variables in the Moudle
Glenn
Jul 6th, 2000, 04:06 PM
Declare them in the declarations section of a code module like:
Global x as integer
BTW, you should proabably post this type of question in the General VB forum.
SteveCRM
Jul 6th, 2000, 09:45 PM
You don't need the as integer part. But its a good idea.
If its going to always change (like some of mine do) then you can just say
Global x
MrPOSTMAN
Jul 7th, 2000, 06:46 AM
You should add a module to 'ur project
and have x variable declaration in there.
JHausmann
Jul 7th, 2000, 01:28 PM
Originally posted by SteveCRM
You don't need the as integer part. But its a good idea.
If its going to always change (like some of mine do) then you can just say
Global x
If you don't declare the type, doesn't it default to a variant data type (which is horribly slower than other declared types)?
Glenn
Jul 7th, 2000, 01:48 PM
JHausmann you are correct (give that man a cigar :)). Undeclared variables are treated as variants. They tend to be slower because VB has to figure out the storage at runtime, instead of compile time. They also waste memory, because VB allocates memory for the largest possible data type.
Variants are not considered good programming practice for the above reasons. They also should a design weakness (the programmer doesn't know what to store ? :( ) There are legitimate uses for variants. Such as null values in databases or when passing optional paramaters to functions and subroutines.
However I try to avoid them at all costs.
Just my 2 cents worth.
:):)
JHausmann
Jul 7th, 2000, 02:04 PM
You can get them if you're not careful with your Dims. Consider:
Dim a,b,c as integer
only c will be an integer, a and b will be created as variants
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.