VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Implementing Split() function available in VB6 into VB5 applications.

by Prashant Sharma (4 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 10th August 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Implementing Split() function available in VB6 into VB5 applications.

Rate Implementing Split() function available in VB6 into VB5 applications.



'Web-site: http://www.prashantsharma/com
'eMail: [email protected]

'Copy and paste this function in a module
Public Function Split(Expression As String, Optional Delimiter, Optional Limit As Long = -1, Optional Compare As VbCompareMethod = vbBinaryCompare) As Variant
    Dim i As Long, j As Long, Ret() As String, s As String, idx As Long, dl As Integer
    If IsMissing(Delimiter) Then Delimiter = " "
    dl = Len(Delimiter)
    i = 1
    j = InStr(i, Expression, Delimiter, Compare)
    'Loop only if needed
    Do While j > 0
        ReDim Preserve Ret(idx)
        Ret(idx) = Mid$(Expression, i, (j - i))
        If idx = Limit Then Exit Do
        idx = idx + 1
        i = j + dl
        j = InStr(i, Expression, Delimiter, Compare)
    Loop
    If idx <> Limit Then
        ReDim Preserve Ret(idx)
        Ret(idx) = Mid$(Expression, i)
    End If
    Split = Ret
End Function


'The sample usage is given here, copy and paste it in a form...
Private Sub Form_Load()
    Dim a As Variant, b As String, i As Integer
    b = "This is a sample code"
    a = Split(b)
    For i = 0 To UBound(a)
        Debug.Print a(i)
    Next i
End Sub



Download this snippet    Add to My Saved Code

Implementing Split() function available in VB6 into VB5 applications. Comments

No comments have been posted about Implementing Split() function available in VB6 into VB5 applications.. Why not be the first to post a comment about Implementing Split() function available in VB6 into VB5 applications..

Post your comment

Subject:
Message:
0/1000 characters