| | |
Can anybody please help me with this code?
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
Im a beginner to VB.net and im trying to code for a search button which will compare a string from a textbox to a combo box list?
Here is what Im instructed to do:
[SIZE=1]The Search button will look for the phrases containing the phrase the user has specified in the text box and display all such phrases (each on a separate line) in a message box. Search should first check that the user has entered something in the text box. Give an appropriate message if not. Remember to nest any checks so that only one message displays at a time. If the text box is not empty, use a For/Next loop to check each item in the combo box to see if it has the phrase entered by the user in the text box. (You won’t need a foundBoolean here since the entire combo box must be checked even if you’ve found one.) If the phrase matches, add it to a String that you will later display in a message box with all the matching phrases. Remember you want each phrase on a separate line in the message box. You can use &= to keep adding to the String. When you declare this String you’ll have to set it initially to “�. After the loop is finished, check whether there is anything in the String. If not, inform the user via a message box that there are no phrases containing the user-input phrase and call Clear Labels. If the String isn’t empty, display a message box with all the phrases from the combo box that matched the input phrase. Then call Clear Labels.
Do whatever is necessary to match phrases regardless of case. So, for example, if the user enters kent it will match Kent.
One point about the items from the combo box that you are comparing to the text box has to do with Option Strict On. ComboBox.Items(indexInteger) is not regarded as a String. When you enter the For/Next loop you’ll have to use ToString to convert it before you can compare it to the text box Text property which is a String.
Here is what I have so far:
Dim loopIndexInteger As Integer
Dim maximumInteger As Integer
maximumInteger = listComboBox.Items.Count - 1
Dim listCompareString As String = ""
Dim textCompareString 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()
Next
End If
Please help me finish this code, I have no clue on how to compare the textbox
string to the combobox list and then display it in a messagebox string?
Here is what Im instructed to do:
[SIZE=1]The Search button will look for the phrases containing the phrase the user has specified in the text box and display all such phrases (each on a separate line) in a message box. Search should first check that the user has entered something in the text box. Give an appropriate message if not. Remember to nest any checks so that only one message displays at a time. If the text box is not empty, use a For/Next loop to check each item in the combo box to see if it has the phrase entered by the user in the text box. (You won’t need a foundBoolean here since the entire combo box must be checked even if you’ve found one.) If the phrase matches, add it to a String that you will later display in a message box with all the matching phrases. Remember you want each phrase on a separate line in the message box. You can use &= to keep adding to the String. When you declare this String you’ll have to set it initially to “�. After the loop is finished, check whether there is anything in the String. If not, inform the user via a message box that there are no phrases containing the user-input phrase and call Clear Labels. If the String isn’t empty, display a message box with all the phrases from the combo box that matched the input phrase. Then call Clear Labels.
Do whatever is necessary to match phrases regardless of case. So, for example, if the user enters kent it will match Kent.
One point about the items from the combo box that you are comparing to the text box has to do with Option Strict On. ComboBox.Items(indexInteger) is not regarded as a String. When you enter the For/Next loop you’ll have to use ToString to convert it before you can compare it to the text box Text property which is a String.
Here is what I have so far:
Dim loopIndexInteger As Integer
Dim maximumInteger As Integer
maximumInteger = listComboBox.Items.Count - 1
Dim listCompareString As String = ""
Dim textCompareString 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()
Next
End If
Please help me finish this code, I have no clue on how to compare the textbox
string to the combobox list and then display it in a messagebox string?
•
•
Join Date: Nov 2004
Posts: 1
Reputation:
Solved Threads: 0
Im not a vb/VB.net programmer and I had a hard time understanding your question... where ambiguous, I left comments that need to be coded in, but this might help you along the way.
Dim loopIndexInteger As Integer
Dim listCompareString As String,textCompareString,matchString As String
If inputTextBox.Text = Nothing Then
MessageBox.Show("You must enter something in the text box")
Else
textCompareString = inputTextBox.Text.ToUpper()
For loopIndexInteger = 1 To listComboBox.Items.Count
listCompareString = listComboBox.Items(loopIndexInteger - 1).ToString().ToUpper()
if matches(textCompareString, listCompareString) then
matchString &= listComboBox.Items(loopIndexInteger -1).ToString()
matchString &= vbnewline
end if
Next
'call clear fields
if matchString = Nothing then
MessageBox.Show("None Found")
else
MessageBox.Show(matchString)
end if
End If
function matches(byval string1 As String, byval string2 As String) As Boolean
'your code here
end function
Dim loopIndexInteger As Integer
Dim listCompareString As String,textCompareString,matchString As String
If inputTextBox.Text = Nothing Then
MessageBox.Show("You must enter something in the text box")
Else
textCompareString = inputTextBox.Text.ToUpper()
For loopIndexInteger = 1 To listComboBox.Items.Count
listCompareString = listComboBox.Items(loopIndexInteger - 1).ToString().ToUpper()
if matches(textCompareString, listCompareString) then
matchString &= listComboBox.Items(loopIndexInteger -1).ToString()
matchString &= vbnewline
end if
Next
'call clear fields
if matchString = Nothing then
MessageBox.Show("None Found")
else
MessageBox.Show(matchString)
end if
End If
function matches(byval string1 As String, byval string2 As String) As Boolean
'your code here
end function
![]() |
Similar Threads
- Code Snippet: code to split (and reconnect) an Access database (part 1) (Visual Basic 4 / 5 / 6)
- Code Snippet: Code that stores and retrieves. (C)
- Code Snippet: Efficient code for extracting unique elements from sorted array. (C)
- Code Snippet: Strings: Looking at ASCII Code (C)
- Code Snippet: Morse Code (C)
- Code Snippet: Gray Code Conversion (C)
- Code Snippet: code to validate data in Access withOUT using messageboxes (Visual Basic 4 / 5 / 6)
- Code Snippet: code to split (and reconnect) an Access database (part 2) (Visual Basic 4 / 5 / 6)
- Code Snippet: Sample code for taking user input from Shell (Java)
- Code Snippet: Send HTML code to Internet Explorer from basic (Legacy and Other Languages)
Other Threads in the ASP.NET Forum
- Previous Thread: .net tutorials
- Next Thread: is .net framework behind shadow mode surfing?
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer c# c#gridviewcolumn checkbox class commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist development dgv dropdownlist dropdownmenu dynamic dynamically edit fileuploader fill findcontrol flash flv formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news objects opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers





