Simple Declaration Question

A

Andibevan

If I want to declare values String1 and String2 as strings can I use the
following:-

Dim String1, String2 as String

Or do I need

Dim String1 as string, String2 as string?

Ta

Andi
 
D

DaveO

The difference between your 2 statements;

Statement 1 - Only declares String2 as a string. String1 would be considered
a Variant.

Statement 2 - Declares both as a string.

Not sure why this is the case, but I know that the first option doesn't
initaiate an instance of the property for the 1st variable.

HTH.
 
J

JE McGimpsey

From XL/VBA Help ("Declaring Variables"):
You can declare several variables in one statement. To specify a data
type, you must include the data type for each variable. In the
following statement, the variables intX, intY, and intZ are declared
as type Integer.

Dim intX As Integer, intY As Integer, intZ As Integer

In the following statement, intX and intY are declared as type
Variant; only intZ is declared as type Integer.

Dim intX, intY, intZ As Integer

You don't have to supply the variable's data type in the declaration
statement. If you omit the data type, the variable will be of type
Variant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top