Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub Combo14_LostFocus()
Dim x() As String
x = Split(Text2.Text, " ")
    If x(0) <> Empty Then
        Combo14.Text = Text2.Text
    If UBound(x) Then
        Combo14.Text = x(0)
    Else
    If UBound(x) Then
        Combo14.Text = x(1)
    Else
    If UBound(x) Then
        Combo14.Text = x(2)
    End If
    End If
    End If
    End If
End Sub

Private Sub Text2_LostFocus()
If Text2.Text = Empty Then Exit Sub
Dim STR() As String
STR = Split(Text2.Text, " ")
If STR(0) <> Empty Then
Combo14.Text = STR(0)
End If
End Sub


Is this code suitable for the operation like:
Splitting names from text boxes(firstname-text2,middlename-text3,lastname-text4)to populate list into combo box(combo14) and combo box should show only those records related to the name entered into either of text boxes not other than them.In one way I am going to use text box as a search box.
Same code as text2,I have written for text3 and text 4
While running this code combo box shows all the records(full-names). Not the specific text related full-names.
Please help me regarding this point.
Whether my point is not understood by anybody??????
please try to understand
Posted
Updated 31-Dec-12 23:05pm
v3

1 solution

VB
If x(0) <> Empty Then
    Combo14.Text = Text2.Text
If UBound(x) Then
    Combo14.Text = x(0)
Else
If UBound(x) Then
    Combo14.Text = x(1)
Else
If UBound(x) Then
    Combo14.Text = x(2)
End If

The above sequence does not make much sense. If there is at least one word in your original string then you set the Text item of the combo box to the complete string. You then check if there is more than 1 substring in the array, and if so you try to set it to each three separate items.

Take a look at the documentation[^] to check what you want to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900