Home Image-Pro Automation (Macros, Apps, Reports)
Options

Can MULTIPLE CONTROLS trigger the same CODE?

2020-11-02-180830

All --

I have a APP with a large number of CHECKBOXES.

I would like the same routine to be triggered when the

checkBox1.CheckedChanged
is triggered.

The INTERNET says that I should be able to chain these .CheckChanged together and connect multiple events to a single event handler in Visual Basic as shown below with a BUTTON EXAMPLE.
<span>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click  
' Add event-handler code here.  
End Sub  </span>

I attempted this in CODE within the PROJECT WORKBENCH.  The WORKBENCH does not like the list when it is connected by commas

    Private Sub checkBox1_CheckedChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) _
        Handles checkBox1.CheckedChanged, checkBox2.CheckedChanged

        'Debug.print "--- checkBox1_CheckedChanged

        CheckChangedWorker()

    End Sub

or when it is just separated by spaces

    Private Sub checkBox1_CheckedChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) _
        Handles checkBox1.CheckedChanged checkBox2.CheckedChanged

        'Debug.print "--- checkBox1_CheckedChanged

        CheckChangedWorker()

    End Sub

Is there a way to make the WORKBENCH HAPPY and to not have to have a

    _CheckChanged

routine for each of the 24 checkboxes in this section of this APP call the CheckChangedWorker?

Thanks.

-- Matt

Answers

  • Options
    edited November 2020
    Hi Matt,

    It is limitation of interpreted mode of Image-Pro scripting language, it can handle only one sender.
    You can switch to Compiled mode and have full VB.NET compatibility, though you will not be able to debug your macros.
    In compiled mode the following statement works:

        Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click,button2.Click
            MsgBox(String.Format("You clicked {0}",sender.Name))
        End Sub
    

    I've also attached the test project.

    Yuri
  • Options
    2020-11-04-162030

    Yuri --

    Thank you for your guidance on this.

    I value having the DEBUGGER so I'll probably not use the COMPILED MODE.

    I was careful when I named the large group of checkbox controls.  This enabled me to make 24 RESPONSE ROUTINES and one WORKER ROUTINE without not much more effort than would be required to make the HANDLES LIST for the checkboxes.

    Thanks again.

    -- Matt


Sign In or Register to comment.