By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Multiple option search engine

P: 37
My search engine in visual basic 2005 has 4 textbox for users to input values, named textbox1,textbox2,textbox3,textbox4.
I have a string assigned to each of the textbox named accession,classname,description,proteinseq respectively.

Expand|Select|Wrap|Line Numbers
  1. Sub accessioncase()
  2.         Dim accession As String
  3.     accession = textbox1.Text
  4.         Dim accessionfound As Boolean = False
  5.         accession = InputBox("Enter Accession Number.")
  6.         For i As Integer = 0 To (dt.Rows.Count - 1)
  7.             If CStr(dt.Rows(i)("Accessionno").ToString) = accession Then
  8.                 accessionfound = True
  9.                 rowIndex = i
  10.                 UpdateTextBoxes()
  11.             End If
  12.         Next
  13.         If (Not accessionfound) Then
  14.             MsgBox("Cannot find the requested Accession Number", 0, "Not in Table")
  15.         End If
  16.     End Sub
  17.     Sub classcase()
  18.         Dim classname As String
  19.     classname = textbox2.Text
  20.         Dim classnamefound As Boolean = False
  21.         classname = InputBox("Enter Protein Type.")
  22.         For i As Integer = 0 To (dt.Rows.Count - 1)
  23.             If CStr(dt.Rows(i)("Class").ToString) = classname Then
  24.                 classnamefound = True
  25.                 rowIndex = i
  26.                 UpdateTextBoxes()
  27.             End If
  28.         Next
  29.         If (Not classnamefound) Then
  30.             MsgBox("Cannot find the requested Protein Type", 0, "Not in Table")
  31.         End If
  32.     End Sub
  33.  
  34.     Sub descriptioncase()
  35.         Dim description As String
  36.     description=textbox3.Text
  37.         Dim descriptionfound As Boolean = False
  38.         description = InputBox("Enter Protein Type.")
  39.         For i As Integer = 0 To (dt.Rows.Count - 1)
  40.             If CStr(dt.Rows(i)("Description").ToString) = description Then
  41.                 descriptionfound = True
  42.                 rowIndex = i
  43.                 UpdateTextBoxes()
  44.             End If
  45.         Next
  46.         If (Not descriptionfound) Then
  47.             MsgBox("Cannot find the requested description", 0, "Not in Table")
  48.         End If
  49.     End Sub
  50.  
  51.     Sub proteinseqcase()
  52.         Dim proteinseq As String
  53.     proteinseq = textbox4.Text
  54.         Dim proteinseqfound As Boolean = False
  55.         proteinseq = InputBox("Enter Protein Sequence.")
  56.         For i As Integer = 0 To (dt.Rows.Count - 1)
  57.             If CStr(dt.Rows(i)("proteinseq").ToString) = proteinseq Then
  58.                 proteinseqfound = True
  59.                 rowIndex = i
  60.                 UpdateTextBoxes()
  61.             End If
  62.         Next
  63.         If (Not proteinseqfound) Then
  64.             MsgBox("Cannot find the requested proteinseq", 0, "Not in Table")
  65.         End If
  66.     End Sub
The code above only allow users to type in only one Textbox. How can i modify the code so that it is a multiple option search engine where users can type in one or move textboxes so that he/she can narrow his/her search?
Jul 11 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
I'd say the problem is the use of InputBox. This is a very old and simple function which generally shouldn't be used in "real" code. It's sort of a "quick and dirty" way of grabbing a value, handy while you're working with VB but not very professional.

You should create your own form and put your four textboxes on it, plus a "Go" or "OK" or "Search" button to begin the search.
Jul 11 '07 #2

P: 37
ok.. note taken.
But can u give me a rough idea or mayb some general codes on how i can allow users to type in one or more textboxes so that they can narrow down their search.
Jul 11 '07 #3

Expert 5K+
P: 8,434
Ok, I got a bit carried away. Here's what I came up with. You may need to play with the syntax slightly, as I work in VB6. Also, this is completely untested...

Expand|Select|Wrap|Line Numbers
  1. Sub proteinseqcase()
  2.   Dim accession As String
  3.   Dim classname As String
  4.   Dim description As String
  5.   Dim proteinseq As String
  6.  
  7.   Dim FoundAccession As Boolean
  8.   Dim FoundClassname As Boolean
  9.   Dim FoundDescription As Boolean
  10.   Dim FoundProteinseq As Boolean
  11.  
  12.   Dim AnythingFound As Boolean
  13.  
  14.   accession = textbox1.Text
  15.   classname = textbox2.Text
  16.   description = textbox3.Text
  17.   proteinseq = textbox4.Text
  18.  
  19.   For i = 0 To (dt.Rows.Count - 1)
  20.     FoundAccession = False
  21.     FoundClassname = False
  22.     FoundDescription = False
  23.     FoundProteinseq = False
  24.     If CStr(dt.Rows(i)("accession").ToString) = accession Then
  25.       FoundAccession = True
  26.     End If
  27.     If CStr(dt.Rows(i)("classname").ToString) = classname Then
  28.       FoundClassname = True
  29.     End If
  30.     If CStr(dt.Rows(i)("description").ToString) = description Then
  31.       FoundDescription = True
  32.     End If
  33.     If CStr(dt.Rows(i)("proteinseq").ToString) = proteinseq Then
  34.       FoundProteinseq = True
  35.     End If
  36.  
  37.     If FoundAccession Or FoundClassname Or FoundDescription Or FoundProteinseq Then
  38.       ' You now have four flags indicating which fields matched.
  39.       ' Based on these flags, and perhaps on which ones were actually entered
  40.       ' (you'll probably ignore those the user didn't enter) you can decide
  41.       ' what to do. When you do decide you've found something relevant,
  42.       ' I'd suggest you set this flag...
  43.       AnythingFound = True
  44.     End If
  45.  
  46.   Next
  47.  
  48.   If Not AnythingFound Then
  49.     MsgBox "No matches found", 0, "Not in Table"
  50.   End If
  51.  
  52. End Sub
Jul 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.