Multi string declaration in one line

J

John J.

I have some subs in which I have defined strings like this:

Dim str1, str2 as string

Now I notice that I get an ByRef-error when I want to use those strings as
arguments in another sub. I get no error if I declare explicitely per
variable.

Just curious, can someone explain why this is happening? Should I always
use:
Dim str1 as string
Dim str3 as string

Thank you,
John
 
R

RoyVidar

John said:
I have some subs in which I have defined strings like this:

Dim str1, str2 as string

Now I notice that I get an ByRef-error when I want to use those
strings as arguments in another sub. I get no error if I declare
explicitely per variable.

Just curious, can someone explain why this is happening? Should I
always use:
Dim str1 as string
Dim str3 as string

Thank you,
John

You can place declarations on one line, but then like this

Dim str1 as string, str2 as string

Your sample declares str1 as variant and str2 as string
 
S

Stefan Hoffmann

hi John,
Dim str1, str2 as string
In VBA there is not such a thing like an enumerating declaration. Your
line is the same as

Dim str1 As Variant, str2 As String
Just curious, can someone explain why this is happening? Should I always
use:
Dim str1 as string
Dim str3 as string
I do, and would say yes.


mfG
--> stefan <--
 
J

John J.

Your sample declares str1 as variant and str2 as string

Ah, now I see what happened, thanks a lot!
John
 
D

david

why this is happening?

Writing "as string" works the same as writing "$", it only
applies to the one variable:

dim A!,B#,C$, D%
dim A as Single, B as Double, C as String, D as Integer.

The suffixes are like Reverse Polish Notation, only with
compiler support. Suffixes were used instead of prefixes
because there was agreement at that time that suffixes
were better than prefixes. That kind of argument ebbs and
flows.

(david)
 
Top