variable declaration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shimon1963
    New Member
    • Aug 2008
    • 1

    variable declaration

    May I prevent the VB ask for Variant Declaration, if i didnt declare it by Dim or Public ? (in Excel VB)

    I wants the VB to recognised the variant automatically.

    thank you,
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    If you are asking if you can avoid having to declare variables the answer is yes. While in the visual basic editor go to tools..options on the editor tab uncheck require variable declaration. When this is checked whenever you add a module it will place the words Option Explicit at the top of the module (if it is unchecked it won't). This is what tells the interpreter to enforce variable declaration. Any existing modules will have to have this line erased. That being said, it is considered bad practice to not declare your variables as it makes the intent difficult to decipher and can lead to bugs that are hard to trace down, additionally it will always type the variable as a variant which is more resource intensive than other types.

    Comment

    Working...