Help with split() function in VB

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
 
M

Marshall Barton

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)
 
G

Guest

The split function does not require a variant.

Here is an example that I have used:
Dim strRtn() As String
strRtn() = Split(Me.OpenArgs, " ")
 
M

Marshall Barton

Dirk said:
Not exactly. You can also do it like this:

Dim a() As String
a = Split(...)


Thanks guys. I guess you can tell how often I've used Split
;-)
 
M

Marshall Barton

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.
 
D

Dirk Goldgar

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.
 
G

Guest

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.
 

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