Discussion:
VB6 and SPLIT
(too old to reply)
JoeBananas
2005-06-02 17:33:38 UTC
Permalink
Is there anyway to force the VB6 Split function to return an Integer
array rather then a String array?
Ken Halter
2005-06-02 17:46:39 UTC
Permalink
Post by JoeBananas
Is there anyway to force the VB6 Split function to return an Integer
array rather then a String array?
Nope (not that I know of anyway)... a function that converts the array is
pretty simple. Wouldn't want to run this 1000's of times or anything, but
for the occasional Split, it should be fine.
'=================
Option Explicit

Private Sub Form_Load()
Dim s As String
Dim x As Integer
Dim i() As Integer

s = "1,2,3,4,5"

i = SplitToInt(s)

For x = 0 To UBound(i)
Debug.Print i(x)
Next

End Sub

Private Function SplitToInt(ByVal Arg As String, Optional ByVal Delim As
String = ",") As Integer()
Dim vTmp As Variant
Dim i As Integer
Dim iRet() As Integer

vTmp = Split(Arg, Delim)

ReDim iRet(UBound(vTmp))
For i = 0 To UBound(vTmp)
iRet(i) = vTmp(i)
Next

SplitToInt = iRet
End Function
'=================
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
Zoury
2005-06-02 18:19:16 UTC
Permalink
Hi Ken !

Did you know you can use a String array to receive the Split() result
instead of a Variant ? ;O)
Dim sTmp() As String
sTmp = Split(Arg, Delim)
--
Best Regards
Yanick
Ken Halter
2005-06-02 19:18:29 UTC
Permalink
Post by Zoury
Hi Ken !
Did you know you can use a String array to receive the Split() result
instead of a Variant ? ;O)
Dim sTmp() As String
sTmp = Split(Arg, Delim)
--
Best Regards
Yanick
That one, I knew <g> How about creating a copy of an entire array with
ThisArrayVar = ThatArrayVar? Kinda' obvious but may come in handy....
'==========
Private Sub Form_Load()
Dim s1() As String
Dim s2() As String
Dim i1() As Integer
Dim i2() As Integer

s1 = Split("1,2,3,4", ",")
s2 = s1

s1(0) = "French" 'just to show that it's a copy and not a reference...
s2(0) = "Frys"

Debug.Print UBound(s2), s1(0), s2(0) 'Shows 3 French
Frys

ReDim i1(3)
i1(0) = 0
i1(1) = 1
i1(2) = 2
i1(3) = 3

i2 = i1
Debug.Print UBound(i2) 'shows 3 (as it should)

End Sub
'==========

Pretty cool (VB rules!)
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
Loading...