Hi
what is the equivalent of a #define preprocessor parameter in VB.
i have got this factor spread across my VB project and i was wondering if there was some way i could just change it in one place. and voila!! it changes globally
Printable View
Hi
what is the equivalent of a #define preprocessor parameter in VB.
i have got this factor spread across my VB project and i was wondering if there was some way i could just change it in one place. and voila!! it changes globally
er... make a module, put:
Perhaps similar to this?Code:Public dblPreprocessorFactor as double
(I have a feeling that this is too easy :) )
if i were to assign some value to this statement globally then how would i do it
If you put the following in a module
VB Code:
Public dblPreprocessorFactor as double
you can reference it from anywhere in your project.
VB Code:
dblPreprocessorFactor = 0.5
If it is in a module and declared public - you can change it from anywhere in the app.Code:dblPreprocessorFactor=44
If its private, only in that module can it be changed.
For more infor - search or read the help files for Variables and Scope.
ah i understand what you mean,
i declare all my globals in a module, set them to values, and i am good to go
i need to add them in a module not a form, correct?
are there any pitfalls i need to watch out for when programming a module? i mean in what ways does a module differ from a form?
a form and module code are the same.
as the code for a form is held within the forms module. (you can turn 'Has Module' on or off)
the stand alone module can be coded the same way, but usually contains functions, and public subs, where a forms module contains private subs.
if you are using Global variables you need to ensure you initialise them when you are using them for different functions/features of your code.
modules are very good for holding repetitive pieces of code.
I use them a lot to carry out selects for report/form opening and pass the variables to the module. similarly for SQL statements, passing variables from the form to the global code.
HTH
is the best way to declare and initialise the global variable in a function say myFunction present in the module and then in the startup module/form cal the fuction myFunction?