Results 1 to 9 of 9

Thread: equivalent of #defines in VB

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    equivalent of #defines in VB

    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

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: equivalent of #defines in VB

    er... make a module, put:
    Code:
    Public dblPreprocessorFactor as double
    Perhaps similar to this?
    (I have a feeling that this is too easy )

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: equivalent of #defines in VB

    if i were to assign some value to this statement globally then how would i do it

  4. #4
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: equivalent of #defines in VB

    If you put the following in a module

    VB Code:
    1. Public dblPreprocessorFactor as double

    you can reference it from anywhere in your project.

    VB Code:
    1. dblPreprocessorFactor = 0.5
    if you fail to plan, you plan to fail

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: equivalent of #defines in VB

    Code:
    dblPreprocessorFactor=44
    If it is in a module and declared public - you can change it from anywhere in the app.
    If its private, only in that module can it be changed.

    For more infor - search or read the help files for Variables and Scope.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: equivalent of #defines in VB

    ah i understand what you mean,
    i declare all my globals in a module, set them to values, and i am good to go

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: equivalent of #defines in VB

    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?

  8. #8
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: equivalent of #defines in VB

    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
    if you fail to plan, you plan to fail

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: equivalent of #defines in VB

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width