Help with split() function in VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear firends,

I need to divide an input string variable into separate strings and I tried
the split function from VBA.

Allthough my input in defined as string (it is the "newdata" argument from a
combo which fires "not in list" event) and I always receive Error 13 "Type
mismatch".

The variable whch received the functions' output is a string array which I
define it: redim strSide(3) - I should have only 3 strings.

Thnks and regards
Catalin
 
Catalin said:
I need to divide an input string variable into separate strings and I tried
the split function from VBA.

Allthough my input in defined as string (it is the "newdata" argument from a
combo which fires "not in list" event) and I always receive Error 13 "Type
mismatch".

The variable whch received the functions' output is a string array which I
define it: redim strSide(3) - I should have only 3 strings.


Only a Variant variable can contain an array:

Dim varStuff As Variant
varStuff = Split( . . . )
x = varStuff(0)
y = varStuff(1)
 
The split function does not require a variant.

Here is an example that I have used:
Dim strRtn() As String
strRtn() = Split(Me.OpenArgs, " ")
 
Catalin said:
I need to divide an input string variable into separate strings and I tried
the split function from VBA.

Allthough my input in defined as string (it is the "newdata" argument from a
combo which fires "not in list" event) and I always receive Error 13 "Type
mismatch".

The variable whch received the functions' output is a string array which I
define it: redim strSide(3) - I should have only 3 strings.


As the other guys said, try changing the ReDim to:
Dim strSide() As String
or, as I said:
Dim varSide As Variant

There is no need to ReDim, Split takes care of that for you.
 
In
Marshall Barton said:
Thanks guys. I guess you can tell how often I've used Split

<g>

It may be that, in an earliler version, you couldn't do that. That
wouldn't surprise me.
 
Thanks.

You have been very helpful.

Catalin

Marshall Barton said:
As the other guys said, try changing the ReDim to:
Dim strSide() As String
or, as I said:
Dim varSide As Variant

There is no need to ReDim, Split takes care of that for you.
 
Back
Top