Split Function Creates Error 13 Type Mismatch

D

Dirk Goldgar

vanderghast said:
A Variant can hold a string and an array of string. The problem is...like
once Jim Ferguson said, is that "who tells you VB is logical?" (and he was
an active defender of VB)

The first part is standard poutine, but the second part is a case of as
"logical as VB can be" (not to denigrate VB, in general, though)


Dim v() As Variant
ReDim v(0 To 1) As Variant
v(0) = "1 2 3 4" ' String
v(1) = Split(v(0), " ") ' array of strings


Dim q As Variant
Dim w() As Variant
Dim z() As String


q = Array("one", "two", "three")
w = q
' z = q ' line c2

q = Split(v(0), " ")
' w = q ' line c1
z = q




About the second part.
As it is, w( ) as Variant accept an array of string returned by Array, but
not by Split.

I believe that the Array() function returns a Variant containing an array of
Variant, not of String, even if all the arguments to the function are
strings. That explains the behavior you have documented.
 
D

Dirk Goldgar

Dirk Goldgar said:
I believe that the Array() function returns a Variant containing an array
of Variant, not of String, even if all the arguments to the function are
strings. That explains the behavior you have documented.


To provide some technical underpinning for this, consider:

a = Array("a", "b", "c") : ?VarType(a)
8204

a = Split("a b c"): ?Vartype(a)
8200

Notes on the VarType values:

8204 = 8192 (Array) + 12 (Variant)
8200 = 8192 (Array) + 8 (String)
 

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