Split Function gives rn-time error

D

davidm

The following code testing the usage of the SPLIT FUNCTION gives me a
run-time
error (on xl2003).

Sub test()

Dim x
Dim txt as String

txt = "abc;xyz;456m;9a6d"
x= Split(txt,";")

Msgbox x

End sub

What am I doing wrong? x is supposed to reurn [abc xyz 456m 9a6d].


David
 
D

Dave Peterson

Maybe you were looking for something like:

Option Explicit
Sub test()

Dim x As Variant
Dim txt As String
Dim iCtr As Long

txt = "abc;xyz;456m;9a6d"
x = Split(txt, ";")

For iCtr = LBound(x) To UBound(x)
MsgBox x(iCtr) & "--is element #: " & iCtr
Next iCtr

MsgBox Join(x, ";") & "--back together again!"

End Sub
The following code testing the usage of the SPLIT FUNCTION gives me a
run-time
error (on xl2003).

Sub test()

Dim x
Dim txt as String

txt = "abc;xyz;456m;9a6d"
x= Split(txt,";")

Msgbox x

End sub

What am I doing wrong? x is supposed to reurn [abc xyz 456m 9a6d].

David
 
D

davidm

Thanks Dave for this other dimension viz using the JOIN FUNCTION as
complement to reverse the process. Your example as well as Leith Ross'
settles the way the SPLIT is used. It is a pity, as I remarked earlier
that as a function, the Split should have very low utility rating. I
would appear that for what it accomplishes, there are probably
handful of better ways to explore. Little wonder, the Help file note
waxed darn little about it. The good is that it broadens the choices w
have, anyhow (<g>).

Thanks again, Dave
 
D

Dave Peterson

If you search google groups for split (or split97, split was added with xl2k),
you'll see some real-life examples of how useful spit can be.

I think most users of xl2k+ are happy it's there.
 

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