Home All Groups Group Topic Archive Search About
Author
2 Jun 2005 5:33 PM
JoeBananas
Is there anyway to force the VB6 Split function to return an Integer
array rather then a String array?

Author
2 Jun 2005 5:46 PM
Ken Halter
"JoeBananas" <Some***@aplace.net> wrote in message
news:mkgu91pao5sr33qs58jes8iptpd7jfskfh@4ax.com...
> 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..
Author
2 Jun 2005 6:19 PM
Zoury
Hi Ken !

Did you know you can use a String array to receive the Split() result
instead of a Variant ? ;O)

Show quoteHide quote
>    Dim sTmp() As String
>    sTmp = Split(Arg, Delim)

--
Best Regards
Yanick
Author
2 Jun 2005 7:18 PM
Ken Halter
"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:uSRgX%235ZFHA.4040@TK2MSFTNGP14.phx.gbl...
> 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..