Search for a String Match combo Box
Following up the Card Reader Problem (see its post) I would now like some help with a search function on a combo box list.
I have a combo box (cboMagnetic) connected (by code) to a MS Access Database.
It is bound by the following code:
.Datasource = dsDraft.Tables("PersonalData")
.Displaymember = "PersNumber"
The combo box nicely displays all Personal ID Numbers from the MS Access DB, and the BindingMangerBase.Position is hooked to the combobox.selectedIndex. A Personal ID displayed in the combobox would look like this: 9984839450 (as it appears in the database) All fine until here.
I have a text box called txtMagnetic and its text value is filled by a Magnetic Card Reader. The string in txtMagnetic.text looks like this after swiping a magnetic card: 003432875849984839450134785784
I have put the Magnetic Card reader string into a variable (magnetic) by declaring: magnetic = txtMagnetic.text
Please note that the listed Personal ID Number in the combo box can be found and matched inside variable magnetic.
QUESTION: I would like to do the following:
1. Have VB2005 match a Personal ID Number (from the ID's listed in the combo box) to variable: magnetic. Thus in other words VB2005 should find and match an ID number listed in the combobox) to the string that came from the Magnetic Card Reader and that was put into variable magnetic.
2. The result should change the current number listed in the Combo box and that (changing the selectedvalue of the combobox with another number - the one matched by the search) should move the bindingmanagebase.position automatically (which I think it does because the BindingMangerBase.Position is hooked to the combobox.selectedIndex) to the appropriate record in the database.
I have tried some MSDN solutions with FindString and FindExactString but they all error on me.
I declared a function:
Public Function FindStringExact( _
ByVal magnetic As String, _
ByVal startIndex As Integer _
) As Integer
End Function
And started the search by pressing a button that calls Private Sub Swiped Card:
Private Sub SwipedCard()
magnetic = txtMagnetic.Text
'MessageBox.Show(magnetic)
'this is to see if the card generated a number
Dim instance As ComboBox
Dim startIndex As Integer
Dim returnValue As Integer
returnValue = instance.FindStringExact(magnetic, startIndex)
End Sub
Any help very Appreciated. And thank you in advance for taking the time to read all this.
- Tsadok
|