Article ID: 212673 - Last Review: October 11, 2006 - Revision: 2.2 WD2000: Troubleshooting Variables and Data TypesThis article was previously published under Q212673 SUMMARY
This article offers suggestions for using variables and data types in Microsoft Visual Basic for Applications in the programs listed at the beginning of this article.
MORE INFORMATION
You can implicitly declare a variable in Visual Basic by using an assignment statement, such as the following:
Doing this can also reduce the incidence of naming-conflict errors and spelling mistakes. A naming conflict occurs when you try to create or use an identifier that was previously defined in the project. In some cases, naming conflicts generate error messages such as the following:
Ambiguous name detected
-or-
Duplicate declaration in current scope
If you do not want Visual Basic to make implicit declarations, you can place the Option Explicit statement in a module before any procedures. This statement requires you to explicitly declare all variables within the module. If a module includes the Option Explicit statement, a compile-time error occurs when Visual Basic encounters a variable name that you have not declared, or that you have spelled incorrectly. You can set an option in your Visual Basic programming environment to automatically include the Option Explicit statement in all new modules. To do this, follow these steps:
-or-
For example, if you explicitly declare a data type and assign a value for your variant, such as in the following arguments This feature can help you to avoid incorrect variable usage by displaying only the collection members, methods, or properties that are relevant to the data type of your variable. Incorrect variable usage can produce error messages such as the following:
Object doesn't support this property or method
-or-
Method or data member not found
REFERENCESFor additional information, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
212623
(http://support.microsoft.com/kb/212623/EN-US/
)
WD2000: Macro Programming Resources
226118
(http://support.microsoft.com/kb/226118/EN-US/
)
OFF2000: Programming Resources for Visual Basic for Applications
| Article Translations
|
Back to the top
