Multi string declaration in one line

  • Thread starter Thread starter John J.
  • Start date Start date
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
 
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
 
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 <--
 
Your sample declares str1 as variant and str2 as string

Ah, now I see what happened, thanks a lot!
John
 
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)
 

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

Back
Top