hi,

this is the code that i use to press enter. how do i make that enter to be pressed only once not more than that. PLEASE HELP!!!

Private Sub frmPasscode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
      
        blnPwdFromKeyboard = True
              If Char.IsNumber(e.KeyChar) Then
                      Select Case Microsoft.VisualBasic.Val(e.KeyChar)
                Case 0 : DisplayKey(lbl0)
                Case 1 : DisplayKey(lbl1)
                Case 2 : DisplayKey(lbl2)
                Case 3 : DisplayKey(lbl3)
                Case 4 : DisplayKey(lbl4)
                Case 5 : DisplayKey(lbl5)
                Case 6 : DisplayKey(lbl6)
                Case 7 : DisplayKey(lbl7)
                Case 8 : DisplayKey(lbl8)
                Case 9 : DisplayKey(lbl9)
            End Select
                   ElseIf Asc(e.KeyChar) = 8 Then
            DisplayKey(lblBackSpace)
                  ElseIf e.KeyChar = Chr(13) Then
                       picYes_MouseUp(Nothing, Nothing)
        End If
         End Sub

hi,

is there anyone can solve my problem. i'm having a big problem because when ever press ENTER more than once it keep printing receipt fo how many times i press enter and it keep saving in sql base on enter pressed.

PLEASE HELP ME ON THIS

hi,

i really have big problem to solve this.Can anyone guide me !!!

At module level define:

Public EnterKeyPressed as Boolead = False

Then on the frmPasscode_KeyPress sub, after

ElseIf e.KeyChar = Chr(13) Then

add

If Not EnterKeyPressed Then
    picYes_MouseUp(Nothing, Nothing)
    EnterKeyPressed = True
End If

Hope this helps

blnPwdFromKeyboard = True

You have to initialize this variable out side the function because it cause to assign true in every key press event
and
when ever user press the enter key you have to assign it as false some thing like this

Dim blnpwdfromkeyboard As Boolean = True

    Private Sub frmPasscode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If blnpwdfromkeyboard = True Then
            If Char.IsNumber(e.KeyChar) Then
                Select Case Microsoft.VisualBasic.Val(e.KeyChar)
                    Case 0 : MessageBox.Show("0")
                    Case 1 : MessageBox.Show("1")
                    Case 2 : MessageBox.Show("2")
                    Case 3 : MessageBox.Show("3")
                    Case 4 : MessageBox.Show("4")
                    Case 5 : MessageBox.Show("5")
                    Case 6 : MessageBox.Show("6")
                    Case 7 : MessageBox.Show("7")
                    Case 8 : MessageBox.Show("8")
                    Case 9 : MessageBox.Show("9")
                End Select
            ElseIf Asc(e.KeyChar) = 8 Then
                MessageBox.Show("lblBackSpace")
            ElseIf e.KeyChar = Chr(13) Then
                MessageBox.Show("Enter")
                blnpwdfromkeyboard = False
            End If
        End If
    End Sub

When ever you press enter second time this event will not execute

Best Of Luck

maybe you can use event keyup, if you use key press, it will be loop :D

hi,

i have tried both of the code but none is working...i think i have to modify some other place in the code. Below is my full source of he particular form.the scenario is once key in p/w 123 from KEYBOARD user need to press ENTER (ONLY ONCE). Please advice me accordingly.

Imports System.Data.SqlClient

Public Class frmPasscode
    Dim userPwd As String
    Dim userTxt As String
    Dim iLength As Integer
    Dim blnPwdFromKeyboard As Boolean


    Private Sub frmPasscode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Visible = False
        SetLabelFont(Me)

        userPwd = ""
        lblPwd.Text = ""
        lblOK.Text = GetButtonText("POS.OK")
        lblCancel.Text = GetButtonText("POS.Cancel")
        lblMessage.Text = GetButtonText("POS.PasscodePrompt")


        Me.Visible = True
    End Sub

    Private Sub frmPasscode_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
     
        If xmlLocalPrinter Then
            Dim obj1 As New PrintDoc1
            Dim i As Integer = 0
            prtStrArr(i) = "" : i += 1
            prtStrArr(0) = "Bill Payment" : i += 1
            prtStrArr(1) = "CB" & Format(ViewCreditBalance(), "#,###,###.00") : i += 1
                     prtStrArr(2) = "Amount To Pay : " & SESSION_CURRENCY & " " & Format(frmMakePayment.TotalPayable, "#,###,###.00") : i += 1
         
            obj1.printMyDoc(3)
        End If
    End Sub

    Private Sub DisplayKey(ByVal sender As Object)
        If Not CheckPasswordControl() Then
            userTxt = Mid(sender.name, 4)

            iLength = Len(userPwd)
            If userTxt = "BackSpace" Then
                If iLength > 0 Then
                    userPwd = Mid(userPwd, 1, iLength - 1)
                    lblPwd.Text = Mid(lblPwd.Text, 1, iLength - 1)
                End If
            Else
                If iLength < 20 Then
                    userPwd &= userTxt
                    lblPwd.Text &= "*"
                End If
            End If
        End If
    End Sub


    Private Function CheckPasswordControl() As Boolean
        CheckPasswordControl = False
        If Not blnPwdFromKeyboard Then
            frmPopup.lblErrMsg.Text = GetButtonText("POS.MakePaymentAtCounter")
            frmPopup.YesNo = False
            frmPopup.QorEx = False
            frmPopup.ShowDialog()
            CheckPasswordControl = True
        End If
    End Function

    Private Sub frmPasscode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        blnPwdFromKeyboard = True
        If Char.IsNumber(e.KeyChar) Then
            Select Case Microsoft.VisualBasic.Val(e.KeyChar)
                Case 0 : DisplayKey(lbl0)
                Case 1 : DisplayKey(lbl1)
                Case 2 : DisplayKey(lbl2)
                Case 3 : DisplayKey(lbl3)
                Case 4 : DisplayKey(lbl4)
                Case 5 : DisplayKey(lbl5)
                Case 6 : DisplayKey(lbl6)
                Case 7 : DisplayKey(lbl7)
                Case 8 : DisplayKey(lbl8)
                Case 9 : DisplayKey(lbl9)
            End Select
        ElseIf Asc(e.KeyChar) = 8 Then
            DisplayKey(lblBackSpace)
        ElseIf e.KeyChar = Chr(13) Then
            picYes_MouseUp(Nothing, Nothing)
        End If
    End Sub

    Private Sub picYes_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picYes.MouseDown
        picYes.BackgroundImage = My.Resources.yes_down_small
        End Sub

    Private Sub picYes_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picYes.MouseUp
        picYes.BackgroundImage = My.Resources.yes_up_small
        Try
         
            If Not CheckPasswordControl() Then
                If userPwd <> "123" Then
                    userPwd = ""
                    lblPwd.Text = ""
                    lblMessage.Text = GetButtonText("POS.InvalidPassword")
                    blnPwdFromKeyboard = False
                Else
                    picYes.Enabled = False
                    picNo.Enabled = False

                    frmMakePayment.PayABill()

                End If
            End If
        Catch ex As Exception
            WriteToLogFile(ex.Message)
        End Try
     
    End Sub

    Private Sub picNo_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picNo.MouseDown
        picNo.Image = My.Resources.No_Down
       End Sub

    Private Sub picNo_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picNo.MouseUp
        picNo.Image = My.Resources.No
       
        frmOnlyBackground.Close()
        frmOnlyBackground.Dispose()
        End

    End Sub

    Public Function ViewCreditBalance() As Double
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim icount As Integer
        Dim strSQL As String = ""
        'Dim connStr As String
        Dim dr As SqlDataReader

        myConnection = GetConnectCRLimit("REMOTE")
        myConnection.Open()

            strSQL = "SELECT TOP 1 [GrandTotal],[KioskID] FROM RetailerBalance ORDER BY TransactionDate DESC"


        myCommand = New SqlCommand(strSQL, myConnection)
        dr = myCommand.ExecuteReader

        While dr.Read
            If Not dr.IsDBNull(0) Then
                ViewCreditBalance = dr(0)
            End If
        End While
     
        myConnection.Close()

    End Function
End Class

hi,

i have a big trouble to solve this code. Please guide me base on my code.PLEASE !!!

Please help me !!!!!!!!!!!

In red my suggestions:

Imports System.Data.SqlClient

Public Class frmPasscode
    Dim userPwd As String
    Dim userTxt As String
    Dim iLength As Integer
    Dim blnPwdFromKeyboard As Boolean
    Dim blnEnterPressed as Boolean = False

    Private Sub frmPasscode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Visible = False
        SetLabelFont(Me)

        userPwd = ""
        lblPwd.Text = ""
        lblOK.Text = GetButtonText("POS.OK")
        lblCancel.Text = GetButtonText("POS.Cancel")
        lblMessage.Text = GetButtonText("POS.PasscodePrompt")


        Me.Visible = True
    End Sub

    Private Sub frmPasscode_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
     
        If xmlLocalPrinter Then
            Dim obj1 As New PrintDoc1
            Dim i As Integer = 0
            prtStrArr(i) = "" : i += 1
            prtStrArr(0) = "Bill Payment" : i += 1
            prtStrArr(1) = "CB" & Format(ViewCreditBalance(), "#,###,###.00") : i += 1
                     prtStrArr(2) = "Amount To Pay : " & SESSION_CURRENCY & " " & Format(frmMakePayment.TotalPayable, "#,###,###.00") : i += 1
         
            obj1.printMyDoc(3)
        End If
    End Sub

    Private Sub DisplayKey(ByVal sender As Object)
        If Not CheckPasswordControl() Then
            userTxt = Mid(sender.name, 4)

            iLength = Len(userPwd)
            If userTxt = "BackSpace" Then
                If iLength > 0 Then
                    userPwd = Mid(userPwd, 1, iLength - 1)
                    lblPwd.Text = Mid(lblPwd.Text, 1, iLength - 1)
                End If
            Else
                If iLength < 20 Then
                    userPwd &= userTxt
                    lblPwd.Text &= "*"
                End If
            End If
        End If
    End Sub


    Private Function CheckPasswordControl() As Boolean
        CheckPasswordControl = False
        If Not blnPwdFromKeyboard Then
            frmPopup.lblErrMsg.Text = GetButtonText("POS.MakePaymentAtCounter")
            frmPopup.YesNo = False
            frmPopup.QorEx = False
            frmPopup.ShowDialog()
            CheckPasswordControl = True
        End If
    End Function

    Private Sub frmPasscode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        blnPwdFromKeyboard = True
        If Char.IsNumber(e.KeyChar) Then
            Select Case Microsoft.VisualBasic.Val(e.KeyChar)
                Case 0 : DisplayKey(lbl0)
                Case 1 : DisplayKey(lbl1)
                Case 2 : DisplayKey(lbl2)
                Case 3 : DisplayKey(lbl3)
                Case 4 : DisplayKey(lbl4)
                Case 5 : DisplayKey(lbl5)
                Case 6 : DisplayKey(lbl6)
                Case 7 : DisplayKey(lbl7)
                Case 8 : DisplayKey(lbl8)
                Case 9 : DisplayKey(lbl9)
            End Select
        ElseIf Asc(e.KeyChar) = 8 Then
            DisplayKey(lblBackSpace)
        ElseIf e.KeyChar = Chr(13) Then
            If blnEnterPressed = False Then
                PicYes_MouseUp(Nothing, Nothing)
                blnEnterPressed = True
            End If
        End If
    End Sub

    Private Sub picYes_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picYes.MouseDown
        picYes.BackgroundImage = My.Resources.yes_down_small
        End Sub

    Private Sub picYes_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picYes.MouseUp
        picYes.BackgroundImage = My.Resources.yes_up_small
        Try
         
            If Not CheckPasswordControl() Then
                If userPwd <> "123" Then
                    userPwd = ""
                    lblPwd.Text = ""
                    lblMessage.Text = GetButtonText("POS.InvalidPassword")
                    blnPwdFromKeyboard = False
                    blnEnterPressed=False
                Else
                    picYes.Enabled = False
                    picNo.Enabled = False

                    frmMakePayment.PayABill()

                End If
            End If
        Catch ex As Exception
            WriteToLogFile(ex.Message)
        End Try
     
    End Sub

    Private Sub picNo_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picNo.MouseDown
        picNo.Image = My.Resources.No_Down
       End Sub

    Private Sub picNo_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picNo.MouseUp
        picNo.Image = My.Resources.No
       
        frmOnlyBackground.Close()
        frmOnlyBackground.Dispose()
        End

    End Sub

    Public Function ViewCreditBalance() As Double
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim icount As Integer
        Dim strSQL As String = ""
        'Dim connStr As String
        Dim dr As SqlDataReader

        myConnection = GetConnectCRLimit("REMOTE")
        myConnection.Open()

            strSQL = "SELECT TOP 1 [GrandTotal],[KioskID] FROM RetailerBalance ORDER BY TransactionDate DESC"


        myCommand = New SqlCommand(strSQL, myConnection)
        dr = myCommand.ExecuteReader

        While dr.Read
            If Not dr.IsDBNull(0) Then
                ViewCreditBalance = dr(0)
            End If
        End While
     
        myConnection.Close()

    End Function
End Class

Hope this helps

hi,

Thank you for the reply, I havE tried the code that you post but it seems it doesn't work. after p/w entered and i HIT ENTER from keyboard (twice or more) i still receive receipt fOr how many times i HIT ENTER and it keep saves in sql database as how many time entered i hit. Please i really need help on this. How do i stop enter to be pressed only once. How the code can be modified the code to accept enter to be pressed only ONCE. PLEASE HELP ME!!!!

hi,

I am desperately need a help on this !!! PLEASE HELP ME !!!!

help please !!!!

i am desperately need help. Please help me !!!

What is your current code?

thank you....i have modify the code that you have posted the other day. Now its working perfectly. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.