ByRef Type Mismatch inconsistent

B

Bruce

I have two different Subs which each receive three string variables.
Both subs are based off the same code.

Here's the problem: calls to the first sub work no problem, calls to
the second sub produce a ByRef type mismatch compile error on the LAST
string variable only. If I mix the order of the variables (both in
the Call and in declaration) it will still error the last variable.

e.g. (selected statements)
Public Const PublicConstant1 = "Blah Blah" as String

Dim String1, String2, String3 as String
Dim StringTemp as String

String2 = "Blah Blah"
String3 = "Blah Blah"

StringTemp = String3

Call Sub DoThis(String1, String2, String3) 'String3 will produce
compile error
Call Sub DoThis(String1, String3, String2) 'String2 will produce
compile error
Call Sub DoThis(String1, String2, StringTemp) 'Will compile fine
Call Sub DoThis(String1, String2, PublicConstant1) 'Will compile fine
Call Sub DoThis(String1, String2, "Blah Blah") 'Will compile fine


Public Sub DoThis(PassString1, PassString2, PassString3 as String)

Has anybody come across this and discovered why? (I've tried
compacting and repairing but that doesn't fix it)

Cheers,
Bruce Walker
 
D

Dirk Goldgar

Bruce said:
I have two different Subs which each receive three string variables.
Both subs are based off the same code.

Here's the problem: calls to the first sub work no problem, calls to
the second sub produce a ByRef type mismatch compile error on the LAST
string variable only. If I mix the order of the variables (both in
the Call and in declaration) it will still error the last variable.

e.g. (selected statements)
Public Const PublicConstant1 = "Blah Blah" as String

Dim String1, String2, String3 as String
Dim StringTemp as String

String2 = "Blah Blah"
String3 = "Blah Blah"

StringTemp = String3

Call Sub DoThis(String1, String2, String3) 'String3 will produce
compile error
Call Sub DoThis(String1, String3, String2) 'String2 will produce
compile error
Call Sub DoThis(String1, String2, StringTemp) 'Will compile fine
Call Sub DoThis(String1, String2, PublicConstant1) 'Will compile fine
Call Sub DoThis(String1, String2, "Blah Blah") 'Will compile fine


Public Sub DoThis(PassString1, PassString2, PassString3 as String)

Has anybody come across this and discovered why? (I've tried
compacting and repairing but that doesn't fix it)

Cheers,
Bruce Walker

The declaration line:
Dim String1, String2, String3 as String

declares only String3 to be a String; the others are both of type
Variant by default, because you haven't specified a type for them.
Multi-variable Dim statements must specify the type for each variable.
If you restate your declarations as:

Dim String1 As String
Dim String2 As String
Dim String3 As String

or:

Dim String1 As String, String2 As String, String3 As String

I'll bet your problem will go away.
 
D

Douglas J. Steele

Dirk Goldgar said:
The declaration line:


declares only String3 to be a String; the others are both of type
Variant by default, because you haven't specified a type for them.
Multi-variable Dim statements must specify the type for each variable.
If you restate your declarations as:

Dim String1 As String
Dim String2 As String
Dim String3 As String

or:

Dim String1 As String, String2 As String, String3 As String

I'll bet your problem will go away.

While I know what you're pointing out, Dirk, I'm not sure it's the culprit
in this case.

Note that the subroutine's declaration is

Public Sub DoThis(PassString1, PassString2, PassString3 as String)


I'd expect

Dim String1, String2, String3 as String

Call Sub DoThis(String1, String2, String3)

to work, since String3 IS declared as a string.

Having said that, though, I have no idea what's going on...
 
D

Dirk Goldgar

Douglas J. Steele said:
While I know what you're pointing out, Dirk, I'm not sure it's the
culprit in this case.

Note that the subroutine's declaration is

Public Sub DoThis(PassString1, PassString2, PassString3 as String)


I'd expect

Dim String1, String2, String3 as String

Call Sub DoThis(String1, String2, String3)

to work, since String3 IS declared as a string.

Having said that, though, I have no idea what's going on...

I'm guessing his example code isn't completely accurate. I could be
wrong.
 

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