working with textchanged event for textbox in vb.net

  • Thread starter Thread starter madmabs
  • Start date Start date
M

madmabs

Guest
Hello,

bellow is the image of a form i named frmpassword in a project am working on.

1409850.png

its created in a such a way that when the user punches a set of numbers and clicks the "continue" button the click event for the continue button handles the verification of the numbers on a database table and if this set of numbers exist grants the user access and if not denies the user access to continue. This is quite straight forward. So i decided to look at another scenario, what if we have a form for user access but in this case no number buttons as shown below in the form "frmcardswipe"

1409851.png

in this case all the user has to do is swipe a card against a magnetic card reader which reads the card numbers into the textbox and triggers an event that tries to verify the the characters or contents of the textbox against a code stored in a variable called "Codeno" if it exist. This is where i seem to be in a fix, which event will handle or be called to handle this process, some one suggested the "Textchanged" event . So this is what i did for the "TextChanged" in frmcardswipe,



Private Sub TxtPassword_TextChanged(sender As Object, e As EventArgs) Handles TxtPassword.TextChanged

Try

If TxtPassword.Text = codeno Then

FrmSearchClientB4Booking.ShowDialog() ===this is the form that needs to be loaded if the contents of the textbox = codeno


Else

FrmInvalidAcess.ShowDialog() === Error message that needs to appear if the above condition is false

End If

Catch ex As Exception

End Try

Me.Close()

End Sub


Also for frmcardswipe load event i have i have

Private Sub FrmCardswipe_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Try

Me.TxtPassword.Text = ""


Catch ex As Exception

End Try

End Sub


for the error message form FrmInvalidAcess (which has just one button, "OK" button) i have the following code


Private Sub BtnOK_Click(sender As Object, e As EventArgs) Handles BtnOK.Click


FrmCardswipe.TxtPassword.Text = ""

Me.Hide()

Me.Close()

End Sub

for FrmSearchClientB4Booking

1409854.png

i have the following code

Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
Try

FrmCardswipe.Close()

Catch ex As Exception

End Try

Me.Close()


End Sub

now when the code is wrong FrmInvalidAcess is triggered and and when i click its ok button all works fine, Frmcardswipe is closed and the contents in txtPassword in frmswipecard is cleared and when i click on the menu item that calls or load frmswipecard, frmswipecard is loaded with txtpassword cleared.

But when the contents in txtpassword in frmswipecard is correct or checks out with the variable codeno, FrmSearchClientB4Booking gets displayed , but when i close FrmSearchClientB4Booking, it closes, but when i click on the menu item that loads or calls frmswipecard, FrmInvalidAcess is displayed ( which shouldn't be) when i click ok button on FrmInvalidAcess, FrmInvalidAcess closes and when i click on again on the menu item that loads or calls Frmswipecard , frmswipecard is loaded properly with Txtpassword cleared.

So please should i be using the "Textchanged" event in the case of card swipe process for user validation and if so what am doing wrong. why is FrmInvalidAcess being loaded first ahead of frmswipecard when i click the menu item meant to load or display frmswipecard .


warm regards

Continue reading...
 
Back
Top