Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Split function in vb 5

2 views
Skip to first unread message

John Watson

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
I want to set up a text box that if someone types in

"more than one word"

then the program will split up the 4 words and put them into separate
variables. ie.

word1, word2, word3 etc

I dont have vb 6 so cant take advantage of the Split function. Or can I
create the same function in vb 5?

Any help wil be appreciated

John Watson


Neal Lowrey

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
here is my split routine

Public Sub split(Seperator As String, ByVal target As String, Results() As
String)
Dim iT, iTa As Integer
iT = 1
iTa = 0
Do
iT = InStr(target, Seperator)
If iT <> 0 Then
ReDim Preserve Results(iTa) As String
Results(iTa) = Left$(target, iT - 1)
target = Mid$(target, iT + 1)
Inc iTa
End If
Loop Until iT = 0
If Len(target) <> 0 Then
ReDim Preserve Results(iTa) As String
Results(iTa) = target
End If
End Sub
John Watson wrote in message <36b5f...@newsread3.dircon.co.uk>...

Karl Westberg, MCP

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
Here is a VB5 split function I wrote.
Public Function Split(ByVal TheString As String, Optional ByVal Delimiter As
String = ",")
Const MIN_SIZE = 50 'use some buffering to help speed things up
Dim TheResult() As Variant
Dim Count As Long
Dim DelimiterPos As Long

ReDim TheResult(MIN_SIZE) As Variant
Count = 0
DelimiterPos = InStr(TheString, Delimiter)
If DelimiterPos Then
Do
If Count > MIN_SIZE Then ReDim Preserve TheResult(Count) As
Variant
TheResult(Count) = Left$(TheString, DelimiterPos - 1)
TheString = Mid$(TheString, DelimiterPos + Len(Delimiter))
DelimiterPos = InStr(TheString, Delimiter)
Count = Count + 1
Loop While DelimiterPos > 0
ReDim Preserve TheResult(Count) As Variant
TheResult(Count) = TheString
Else
ReDim TheResult(Count) As Variant
TheResult(Count) = TheString
End If
Split = TheResult
End Function

--
Karl Westberg, MCP


0 new messages