Author Topic: keypad min max values  (Read 1623 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
keypad min max values
« on: June 03, 2021, 11:47:46 AM »
Hey AHMI, long time without a post but I am doing a new project and I am implementing an AnalogValueDisplay control.  The issue I'm having is the keypad Min/max values are applied to the password as well.  This limits me to the passcode I can enter.  For example, my acceptable values for the control are min=1 and max=6 but I want my passcode to be 1111 which is obviously above 6 and not allowed.  Am I missing a property setting or is this a "bug"?  Thanks.       

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: keypad min max values
« Reply #1 on: June 04, 2021, 06:36:49 PM »

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: keypad min max values
« Reply #2 on: June 12, 2021, 10:10:24 AM »
Thanks Godra for the alternative solution but I was hoping to leverage the pre-built control.  Is there a way to modify the code of the control to separate the passcode from the min/max range?  Thanks.     

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: keypad min max values
« Reply #3 on: June 12, 2021, 06:19:55 PM »
Just remember that, in general, once you modify the code of any control then all controls of that kind, which you might have on your forms, will adopt that modification.

You can try the modifications as below:

Code: [Select]
    Private Sub KeypadPopUp_ButtonClick(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Controls.KeypadEventArgs)
        If e.Key = "Quit" Then
            KeypadPopUp.Visible = False
        ElseIf e.Key = "Enter" Then
            If String.IsNullOrEmpty(m_KeypadPasscode) Or PasscodeValidated Then
                If m_ComComponent Is Nothing Then
                    DisplayError("ComComponent Property not set")
                Else
                    If Not String.IsNullOrEmpty(KeypadPopUp.Value) Then
                        Try
                            If m_KeypadMaxValue <> m_KeypadMinValue Then
                                If KeypadPopUp.Value < m_KeypadMinValue Or KeypadPopUp.Value > m_KeypadMaxValue Then
                                    System.Windows.Forms.MessageBox.Show("Value must be >" & m_KeypadMinValue & " and <" & m_KeypadMaxValue)
                                    Exit Sub
                                End If
                            End If
                        Catch ex As Exception
                            System.Windows.Forms.MessageBox.Show("Failed to validate value. " & ex.Message)
                            Exit Sub
                        End Try

                        Try
                            If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                                m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                            Else
                                m_ComComponent.Write(m_PLCAddressKeypad, CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor)
                            End If
                        Catch ex As Exception
                            System.Windows.Forms.MessageBox.Show("Failed to write value. " & ex.Message)
                        End Try
                    End If

                    KeypadPopUp.Close()
                    KeypadPopUp = Nothing
                End If
            Else
                '* A passcode was entered, so validate
                If Not String.IsNullOrEmpty(KeypadPopUp.Value) AndAlso KeypadPopUp.Value = m_KeypadPasscode Then
                    PasscodeValidated = True
                    PromptNewValue()
                Else
                    System.Windows.Forms.MessageBox.Show("Invalid Passcode!")
                    KeypadPopUp.Close()
                    KeypadPopUp = Nothing
                End If
            End If
        End If
    End Sub

    '***********************************************************
    '* If label is clicked, pop up a keypad for data entry
    '***********************************************************
    Protected Overrides Sub OnClick(e As System.EventArgs)
        MyBase.OnClick(e)

        If m_PLCAddressKeypad IsNot Nothing AndAlso (String.Compare(m_PLCAddressKeypad, "") <> 0) And Enabled Then
            If KeypadPopUp Is Nothing Then
                KeypadPopUp = New MfgControl.AdvancedHMI.Controls.KeypadV2(m_KeypadWidth)
                AddHandler KeypadPopUp.ButtonClick, AddressOf KeypadPopUp_ButtonClick
            End If

            If String.IsNullOrEmpty(m_KeypadPasscode) Then
                PromptNewValue()
            Else
                PromptPasscode()
            End If
        End If
    End Sub

    Private Sub PromptNewValue()
        KeypadPopUp.Text = m_KeypadText
        KeypadPopUp.ForeColor = m_KeypadFontColor
        KeypadPopUp.MinValue = m_KeypadMinValue
        KeypadPopUp.MaxValue = m_KeypadMaxValue
        KeypadPopUp.Value = ""
        KeypadPopUp.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
        KeypadPopUp.TopMost = True
        KeypadPopUp.Show()
    End Sub

    Private PasscodeValidated As Boolean
    Private Sub PromptPasscode()
        PasscodeValidated = False
        KeypadPopUp.Text = "Enter Passcode"
        KeypadPopUp.ForeColor = m_KeypadFontColor
        KeypadPopUp.Value = ""
        KeypadPopUp.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
        KeypadPopUp.TopMost = True
        KeypadPopUp.Show()
    End Sub