3 Replies Latest reply on Dec 2, 2013 3:22 PM by fbatista

    Event Handler for objects that are created programmatically

    ken_reiss

      Hello all,

       

      I'm trying to build controls programmatically and also their event handlers, can this be done?

       

      Here is what I have so far for a little test, but I can't get the event handler to work.  This code is contained in a Class Module

      Private WithEvents Dis As Display
      Private WithEvents test As Text

      Private Sub Class_Initialize()
          Set Dis = Application.ActiveDisplay
          Set test = Dis.Symbols.Add(pbSymbolText)
          test.Contents = "My Text Symbol"
          test.LineColor = 0
          test.BackgroundColor = -1
      End Sub

      Private Sub test_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          MsgBox ("hello")
      End Sub

       I've also tried the following with no success:

      Private WithEvents Dis As Display
      Private WithEvents test As Text

      Private Sub Class_Initialize()
          Set Dis = Application.ActiveDisplay
          Set test = Dis.Symbols.Add(pbSymbolText)
          test.SetName "test"
          test.Contents = "My Text Symbol"
          test.LineColor = 0
          test.BackgroundColor = -1
      End Sub

      Private Sub test_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          MsgBox ("hello")
      End Sub

        • Re: Event Handler for objects that are created programmatically
          andreas

          Hi Ken,

           

          if I understand you right you are using VBA. Unfortunately you have chosen one of the symbols that needs to be "enabled" first. So here is what you would like to write:

          Private Sub CommandButton1_Click()
              Dim test As Text
              Set test = Me.Symbols.Add(pbSymbolText)
              test.SetName ("MySymbol")
              test.EnableScript = True
              test.Contents = "Test"
          End Sub

          Private Sub MySymbol_Click(ByVal lvarX As Long, ByVal lvarY As Long)
              MsgBox "Test"
          End Sub

          Regards,

            • Re: Event Handler for objects that are created programmatically
              fbatista

              Sorry for resurrecting this thread... But I am having the same issue. The test.EnableScript has already been set to true. However nothing happens when click on it. My Processbook version is 3.3.1.1160.

               

              From the code above, Andreas is using an event associated with a symbol called "MySymbol". It works. But what if I have hundreds of symbols in my display? It would be impossible a different sub for all my symbols (MySymbol1_Click, mySymbol2_Click, etc...). So I think the "WithEvents" declaration would do the trick, if it worked (as seen on Kenneth's code). After adding test.EnabvleScript=True, Kenneth's code is still not working.

               

              Could anyone shed a light on this?

               

              Best regards,

               

              Fabiano Batista