1 Reply Latest reply on Feb 5, 2018 2:25 PM by gregor

    how to script  processbook VBA for the textbox?

    OhJunseo

      I'm beginner in VBA

      The msgbox shows OK or BAD based on the value of 70.

      I want to type in a text box and easily switch to another reference value except 70.

       

      And I want to reduce the construction simply because it is more than 100 units.

      I'd appreciate your help.

       

       

       

      Private Sub Value1_DataUpdate()
      If Value1.GetValue(Time, 1) > 70 Then
      For i = 0 To 0
      MsgBox "Unit1 OK"
      Next
      End If
      End Sub

       

      Private Sub Value2_DataUpdate()
      If Value2.GetValue(Time, 1) < 70 Then
      For i = 0 To 0
      MsgBox "Unit1 BAD"
      Next
      End If
      End Sub

       

      Private Sub Value3_DataUpdate()
      If Value3.GetValue(Time, 1) > 70 Then
      For i = 0 To 0
      MsgBox "Unit2 OK"
      Next
      End If
      End Sub

       

      Private Sub Value4_DataUpdate()
      If Value4.GetValue(Time, 1) < 70 Then
      For i = 0 To 0
      MsgBox "Unit2 BAD"
      Next
      End If
      End Sub

       

      Private Sub Value5_DataUpdate()
      If Value5.GetValue(Time, 1) > 70 Then
      For i = 0 To 0
      MsgBox "Unit3 OK"
      Next
      End If
      End Sub

       

      Private Sub Value6_DataUpdate()
      If Value6.GetValue(Time, 1) < 70 Then
      For i = 0 To 0
      MsgBox "Unit3 BAD"
      Next
      End If
      End Sub

        • Re: how to script  processbook VBA for the textbox?
          gregor

          Hello and welcome Oh!

           

          When you use a TextBox control e.g. Microsoft Forms 2.0 TextBox, its Text property (e.g. textBox1.Text) will have the text (string) entered by a user. Because you are expecting an Integer (or Float) value here, you need to do some kind of input validation and the internet has many different suggestions on how to do this (search e.g. for "VBA cast integer to string" without double quotes).

           

          With a ProcessBook display, there is no collection of PBValue symbols but a collection of symbols. With other words, you iterate through the collection of symbols and check if they are of type PBValue.

           

                  Dim sym As Symbol
                  For Each sym In ThisDisplay.Symbols
                      If (sym.Type = pbSymbolValue) Then
                          If (sym.GetValue(Time, 1) > compVal) Then
                              MsgBox sym.Name & " => Ok"
                          Else
                              MsgBox sym.Name & " <= Bad"
                          End If
                      End If
                  Next