Split string in VB6

This program shows you on how to split strings and assign it to a variable. You can use this example if you want to split the full name into last name, first name, and middle initial.
How it works?
  • Design user interface, add labels, text boxes and button. (see the design below) 
  • Inside the button event add the code snippet. 
  • Run the program 
Code snippet

Private Sub Command1_Click()
    arr = Split(Text1.Text, ",", -1)
    For i = LBound(arr) To UBound(arr)
        arr(i) = arr(i)
    Next
    Text2.Text = arr(0)
    arr = Split(arr(1), " ", -1)
    For i = LBound(arr) To UBound(arr)
        arr(i) = arr(i)
    Next
    If UBound(arr) = 2 Then
        Text3.Text = arr(UBound(arr) - 1)
    ElseIf UBound(arr) = 3 Then
        Text3.Text = arr(UBound(arr) - 2) & " " & arr(UBound(arr) - 1)
    ElseIf UBound(arr) = 4 Then
        Text3.Text = arr(UBound(arr) - 3) & " " & arr(UBound(arr) - 2) & " " & arr(UBound(arr) - 1)
    ElseIf UBound(arr) = 5 Then
        Text3.Text = arr(UBound(arr) - 4) & " " & arr(UBound(arr) - 3) & " " & arr(UBound(arr) - 2) & " " & arr(UBound(arr) - 1)
    End If
    Text4.Text = arr(UBound(arr))
End Sub
Screenshot

Programming Language: Vb6