Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no Split function in VBA?

Status
Not open for further replies.

dahoule

Programmer
Sep 27, 2001
4
US
I am trying to split a string into an array based on a particular delimiter. This is becoming a little difficult and it should be easier! (I am still trying to come up with a way to split an IP address into separate octets based on the location of the "dot" [.]!)

Is there a function like Split()? I have found some references to it, but it does not work in Access 97 VBA.

Any help would be appreciated!

Don
 
This code should work:

Dim s As String
Dim iPos As Integer
Dim iLen As Integer
Dim sArr() As String
Dim i As Integer
Dim iPos2 As Integer

s = "123.12.15.16"
iLen = Len(s)

iPos = InStr(1, s, ".", 1)

ReDim sArr(1)
sArr(1) = Left$(s, iPos - 1)
i = 1

Do
i = i + 1
iPos2 = InStr(iPos + 1, s, ".")
If iPos2 = 0 Then
ReDim sArr(i)
sArr(i) = Right$(s, Len(s) - iPos)
Exit Do
End If

If iPos2 > 0 Then
ReDim sArr(i)
sArr(i) = Mid$(s, iPos + 1, (iPos2 - iPos - 1))
MsgBox sArr(i)
iPos = iPos2
End If
Loop

Nick
 
Do as search for "basSplit" in these forums. It is a ver '97 compatible procedure which ~~~~~ accomplishes the SPLIT function. There are a few different versions (and names) contribuited by various individuals.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks! Those were both very helpful suggestions! nickjar2, I am going to go with the code that you sent - thanks a LOT!!!

Don
 
I believe all this code may be unnecessary. Have you checked the HyperlinkPart function? That shows how to address the three parts of a hyperlink separately.

Uncle Jack
 
Uncle Jack,

I don't want to use the IP address in a link or as part of a URL. The IP address will just be used in the database to denote a customer's address on our network.

Thanks though!

Don
 
Ok, you could have fooled me. That's what I thought the HyperlinkPart function did.

Uncle Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top