Author Topic: Keypadpopup data verification messagebox  (Read 1444 times)

PMT Tech

  • Newbie
  • *
  • Posts: 5
    • View Profile
Keypadpopup data verification messagebox
« on: September 29, 2016, 08:56:48 AM »
I am trying to create a messagebox with yes no buttons that displays the following: "Are you sure # is correct?" where # is the value entered into the keypad. The problem I seem to be having is when the program runs it creates additional message boxes the number of which seems to be equal to the number of times the keypad has been called for that object ( analog value display). I have stepped through the program, and it seems that with or without my additions Lines 555 through 590 on the analogvaluedisplay are called repeatedly again seemingly based on the number of times the keypad has been used since the program has been running.

Any help would be appreciated.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Keypadpopup data verification messagebox
« Reply #1 on: September 29, 2016, 09:28:53 AM »
The place you have your added code, a keypad will pop up every time a key on the keypad is pressed. If you move your line of code down 6 lines below the "Else" it will only pop up on the Enter key:
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 m_ComComponent Is Nothing Then
                DisplayError("ComComponent Property not set")
            Else
            Dim Result As Integer = System.Windows.Forms.MessageBox.Show("Are you sure " & KeypadPopUp.Value & " is correct?", "validate change", MessageBoxButtons.YesNo)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Keypadpopup data verification messagebox
« Reply #2 on: September 29, 2016, 10:51:50 AM »
It still seems to be memorizing all previous attempts.

If disposed of and then re-created it will not memorize any:

Code: [Select]
    Private Sub KeypadPopUp_ButtonClick(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Controls.KeyPadEventArgs)
        If e.Key = "Enter" OrElse e.Key = "Quit" Then
            If e.Key = "Enter" Then
                If m_ComComponent Is Nothing Then
                    DisplayError("ComComponent Property not set")
                Else
                    If KeypadPopUp.Value IsNot Nothing AndAlso (String.Compare(KeypadPopUp.Value, "") <> 0) Then
                        Dim response As DialogResult = MessageBox.Show("Are you sure " & KeypadPopUp.Value & " is correct?", "Validate Change", MessageBoxButtons.YesNo)
                        If response = DialogResult.Yes 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
                        Else
                            Exit Sub
                        End If
                    End If
                End If
            End If
            KeypadPopUp.Visible = False
            KeypadPopUp.Dispose()
            KeypadPopUp = New MfgControl.AdvancedHMI.Controls.Keypad(m_KeypadWidth)
        End If
    End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Keypadpopup data verification messagebox
« Reply #3 on: September 29, 2016, 12:30:54 PM »
I think what is happening is that an event handler gets attached again every time a new keypad pops up. At the very end of the file, move the AddHandler line as shown here:
Code: [Select]
    '***********************************************************
    '* If labeled 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.Keypad(m_KeypadWidth)
                AddHandler KeypadPopUp.ButtonClick, AddressOf KeypadPopUp_ButtonClick
            End If

            KeypadPopUp.Text = m_KeypadText
            KeypadPopUp.ForeColor = m_KeypadFontColor
            KeypadPopUp.Value = ""
            KeypadPopUp.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
            KeypadPopUp.TopMost = True
            KeypadPopUp.Show()
        End If
    End Sub
« Last Edit: September 29, 2016, 05:27:22 PM by Archie »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Keypadpopup data verification messagebox
« Reply #4 on: September 29, 2016, 05:13:51 PM »
That fixes it for my tests.

Here is a possible code which would also introduce a property to turn verification ON/OFF:

Code: [Select]
    Private m_KeypadVerifyNewValue As Boolean
    Public Property KeypadVerifyNewValue As Boolean
        Get
            Return m_KeypadVerifyNewValue
        End Get
        Set(value As Boolean)
            m_KeypadVerifyNewValue = value
        End Set
    End Property
 
    Private Sub KeypadPopUp_ButtonClick(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Controls.KeyPadEventArgs)
        If e.Key = "Enter" OrElse e.Key = "Quit" Then
            If e.Key = "Enter" Then
                If m_ComComponent Is Nothing Then
                    DisplayError("ComComponent Property not set")
                Else
                    If KeypadPopUp.Value IsNot Nothing AndAlso (String.Compare(KeypadPopUp.Value, "") <> 0) Then
                        Dim response As DialogResult
                        If m_KeypadVerifyNewValue Then response = MessageBox.Show("Are you sure " & KeypadPopUp.Value & " is correct?", "Verify New Value", MessageBoxButtons.YesNo)
                        If response = DialogResult.Yes OrElse Not m_KeypadVerifyNewValue 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
                        Else
                            Exit Sub
                        End If
                    End If
                End If
            End If
            KeypadPopUp.Visible = False
        End If
    End Sub
« Last Edit: October 02, 2016, 12:45:10 PM by Godra »