Executing Macro with parameters over buttons

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
M. Hofmann
Posts: 3
Joined: Fri 19. Oct 2018, 11:19

Executing Macro with parameters over buttons

Post by M. Hofmann » Fri 19. Oct 2018, 11:43

Hello,

I try to send CAN message, which content is calculated by VB script. The script works and can be started over a button of the control panel.

Now I try to achieve that all existing commands can be send via buttons. The command generation use a common logic, that I have implemented in a separate function with parameters.

Until now I did not manage to start this control function with parameters by clicking on a button. How can this be done?

Calling the macro with parameters in the command execute field of the button (like "command 0, 1, 3") did not work. My second approach was to write macros for each button and call the control macro with fix parameters. This works, if the control function and call operation is in the same file. But for this I have to copy the control function in every macro, which is a maintenance hell.

Is there a possibility to call a Macro from another file?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Executing Macro with parameters over buttons

Post by PEAK-Support » Fri 19. Oct 2018, 12:31

Maybe you could use a virtual Signal that changed its value depending on the pressed buttom.
This Signal could be used in the same ways as real CAN Signal and so could be read / write from all available ressources with the PCAN-Explorer.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

M. Hofmann
Posts: 3
Joined: Fri 19. Oct 2018, 11:19

Re: Executing Macro with parameters over buttons

Post by M. Hofmann » Fri 19. Oct 2018, 12:38

Is it possible to execute multiple macros with one click on a button? Or do I have to use multiple buttons? One for selecting the command and one for transmitting the message?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Executing Macro with parameters over buttons

Post by PEAK-Support » Fri 19. Oct 2018, 12:46

Is it possible to execute multiple macros with one click on a button? Or do I have to use multiple buttons? One for selecting the command and one for transmitting the message?
No, one event - one macro (the VBS engine is a single thread - blocking environment - not possible to run more than one code at a time). As i wrote, i would use a Virtual Signal as "Parameter" and the Buttom that set these Value and call the script...
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

M. Hofmann
Posts: 3
Joined: Fri 19. Oct 2018, 11:19

Re: Executing Macro with parameters over buttons

Post by M. Hofmann » Fri 19. Oct 2018, 15:58

The suggestion to use virtual signals and multiple buttons for one action is a little bit too cumbersome.

Thats why I have implemented my own include command. This way I can write the common code in a separate file and reuse it in the button action scripts :)

Maybe it help some of you:

Code: Select all

Sub Include(path)
	const ForReading = 1
	const TristateUseDefault = -2 ' use system settings to decide if ascii or unicode

	Set fs = CreateObject("Scripting.FileSystemObject")
	Set srcF = fs.OpenTextFile(path, ForReading, TristateUseDefault)
	code = srcF.ReadAll
	srcF.Close
	
	ExecuteGlobal code
end sub
For including the file common.pem you only need to write

Code: Select all

Include "common.pem"
Cheers

Post Reply