none
working with textchanged event for textbox in vb.net RRS feed

  • Question

  • Hello,

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

    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"

    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

    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

    Sunday, March 3, 2019 10:43 PM

All replies

  • Hello,

    If you were to implement a swipe operation I'd think the code you write for the swipe operation or the software that interfaces with the hardware (the reader) would have a delegate that is triggered when the person swipes their card and in the delegate that would perform the required validation e.g. check the database to see if the card is valid which in turn grants access or denies access.

    Similar to how most places I've work for (federal, state, private), you swipe and no other action is required by me. I know for instance access has been granted by a led turning green or red for denial or when software open or a message dialog appears indicating invalid credentials.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, March 4, 2019 12:55 AM
    Moderator
  • So karen does this imply that there is no textbox event that could be triggered/initiated to handle such a swipe action or get the contents of the textbox and do a validation.
    Monday, March 4, 2019 10:02 AM
  • So karen does this imply that there is no textbox event that could be triggered/initiated to handle such a swipe action or get the contents of the textbox and do a validation.
    A TextBox control knows nothing about a swipe action and secondly if you read my reply there is zero need for such an event, all work to show and perform actions would be done in a delegate that I mentioned in my first reply.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, March 4, 2019 10:48 AM
    Moderator