|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Vb.net string question?
Im trying to compare a string from a textbox to string in a combo list box
and display the strings that compare in a messagebox. My problem is that the textbox string will only compare to the text in the combo box that matches exactly. For example, type in college i want that to compare to fashion college in the combo box list and then display. I can only get it to match if I type in fashion college, which isnt what I want to do. Here is my code: Dim loopIndexInteger As Integer Dim maximumInteger As Integer maximumInteger = listComboBox.Items.Count - 1 Dim listCompareString As String Dim textCompareString As String Dim matchString As String = "" If inputTextBox.Text = "" Then MessageBox.Show("You must enter something in the text box") Else For loopIndexInteger = 0 To maximumInteger listCompareString = listComboBox.Items(loopIndexInteger).ToString() listCompareString = listCompareString.ToUpper() textCompareString = inputTextBox.Text.ToUpper() If textCompareString.IndexOf(listCompareString) >= 0 Then matchString &= listCompareString & ControlChars.NewLine End If Next loopIndexInteger If matchString <> "" Then MessageBox.Show(matchString, "Input That Matches", MessageBoxButtons.OKCancel) Call clearButton_Click(sender, e) Else MessageBox.Show("Nothing matched your input") Call clearButton_Click(sender, e) End If Any help would be appreciated? |
|
#2
|
|||
|
|||
|
Hi,
I think the following code will be useful for you to compare the textbox value to listbox value Dim Str, Str1 AsString Dim Com AsBoolean Dim matchString AsString Dim BoolRes AsInteger str = LCase(Trim(txt_Customer_Name.Text)) matchString = "" ForEach Str1 In Listbox1.Items BoolRes = Str.CompareTo(LCase(Str1)) If BoolRes = 0 Then matchString &= Str1 & ControlChars.NewLine EndIf Next If matchString <> "" Then MessageBox.Show(matchString, "Input That Matches", MessageBoxButtons.OKCancel) Else MessageBox.Show("Nothing matched your input") EndIf |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Vb.net string question? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|