Home Search

DriveWorks Pro 22
How To: Use The Macro Argument Property (KB12121043)

Send Feedback

How To: Use The Macro Argument Property

This example explains how the Macro Argument property can be used to drive differing values into a single output, as in the images below.

Image when Macro Button 1 (with the caption Type A in the image below) is clicked:

Image when Macro Button 2 (with the captionType B in the image below) is clicked:

Image when Macro Button 3 (with the captionType C in the image below) is clicked:

The Macro Argument property is a property of the Macro Button and the Run Macro and Run Macro in a Loop tasks.

This article requires DriveWorks Pro Administrator.

Overview

For this example we will use three Macro buttons that, when each is clicked, will drive a different image into a picture box (the output).

Each Macro Button will use the same specification macro, only the macro argument property will differ for each button.

The steps involved to achieve this are as follows:

  1. Create a constant to drive the image path into.
  2. Create a specification macro that drives the constant.
  3. Add the controls to the user form.
  4. Test

Before you Begin

Prepare the images to be driven into the picture box control.

Use an image editing application if necessary, but this example uses the images from the Sample Pictures folder in Windows 7.

Ensure the images follow the guidelines below:

  • Each image has the same dimensions (Each of the sample images in Windows 7 are 1024 x 768).
  • Each image is numbered consecutively (1.jpg, 2.jpg, 3.jpg, etc.).
  • The images are stored in a folder relative to the project location, for this exercise use the sub folder Images, so you have the location:

    < Drive>\< ProjectLocation>\Images

Open or create a group and project to start this exercise, at the location < Drive>\< ProjectLocation>

Create a Constant

The constant will store the image path and name and will be driven by a specification macro (next stage).

  1. With the Group and Project open in DriveWorks Administrator select the user form to apply this example to from Stage 3: Data and Rules> Define Constants.
  2. From the command bar click Add to insert a new constant.
  3. Enter a name for the new constant, use DrivenImageName for this example.
  4. Click OK to apply the constant.

Create a Specification Macro

The specification macro will drive a value into the constant created above. The value will be the result of a rule that forms the location (relative to the project) and the name of the image. The name will be taken from the macro argument property of the last macro button to be clicked.

  1. Select Stage 5: Specification Control> Specification Macros.
  2. From the command bar click Add to insert a new specification macro.
  3. Enter a name for the macro, use ChangePicture for this example.
  4. Click OK to create the macro.
  5. In the Edit Tasks dialog drag the Drive Constant Value task from the toolbox into the Tasks column.
  6. With the Drive Constant Value task selected click in the Constant Name behavior property, activate the drop down for this property and select the constant created above (DWConstant DrivenImageName).
  7. Make the Constant Value property dynamic.
    See how to make a static property dynamic
  8. Click the Build button to launch the Rule Builder.
  9. Type the following into the rule editor window:

    "Images\" &

    This is the location of the images relative to where the DriveWorks Project is stored. See Before you Begin section above.
  10. Ensure the cursor remains after the & symbol in the rule editor window. Click the arrow under the Quick text button in the command bar of the rule builder, click Special Variables and select Current Macro Argument.
  11. Ensure the cursor remains after the special variable (just added) in the rule editor window and type the following:

    & ".jpg"

    This is the file extension of the images to be used. If you are using your own images replace jpg with the extension of the images you are using.
    The should now look like this:

    "Images\" & DWCurrentMacroArgument & ".jpg"
  12. Click OK to apply the rule.
  13. Click Finish in the Edit Tasks dialog to apply the changes to the macro.

Add The Controls

The user form will have three macro buttons that are required to drive a different image into a single picture box.

  1. Select the user form to apply this example to from Stage 2: User Interface> Form Design.
    If a new form is required for this example create one and add it to the Form Navigation from Stage 2: User Interface> Form Navigation.
  2. Add a Macro Button to the user form by selecting the More... button from the command bar and choosing Macro Button from the Controls dialog.
  3. Enter a name for the Macro Button, use TypeA for this example and click OK.
  4. Add two more Macro Buttons and enter the names TypeB and TypeC respectively.
  5. Add a Picture Box control to the form by selecting the  icon from the command bar.
  6. Enter a name for the Picture Box control, use DrivenPicture for this example.
  7. Arrange the Form Controls similar to the layout below:
  8. Multi select all of the Macro buttons, select the Macro Name property and click the build button to launch the rule builder.
  9. Click the Macros... button from the command bar of the rule builder, select the ChangePicture macro from the Macros dialog and click OK.
  10. Click OK in the rule builder to apply the same macro to all of the macro buttons that were selected.
  11. Click anywhere on the form to deselect the macro buttons.
  12. Select the first macro button ( TypeA). Select the Macro Argument property and enter 1.


    We can use the value 1 because the image to use when this button is clicked is named 1.

    If your images are named differently enter the name of the image required to be displayed when the Type A macro button is clicked.

    Note if the image name is text, quotes "" are not required.

  13. Repeat step 12 above for the second macro button ( TypeB) using 2 for the macro argument, and the third macro button ( TypeC) using 3 for the macro argument.
  14. Select the Picture Box control ( DrivenPicture), and then select the File Name property. Click the build button to launch the rule builder.
  15. In the rule builder select the Constants tab from the right hand side and double click the constant DrivenImageName.
  16. Click OK to apply this rule to the File Name property and close the rule builder.

Test

Specification Macros cannot be run in the form design test mode. So you will need to start a new specification to see this example in action.

DriveWorks Quick Tips

DriveWorks Quick Tips: Export to Table

Almost every company runs off a database of some sort. Those databases need to be populated with new information as it is received. DriveWorks can build up databases quickly and easily by using the Export to Simple Table document.

DriveWorks Quick Tips are a series of 1 minute videos, available on YouTube, that explain specific functionality. View all Quick Tips

DriveWorks Tech Tips Portal

Macro Button Selection

Works as a color picker. Select an item and assign it a color by using Macro Buttons to drive a value.

View all Tech Tips

DriveWorks Tech Tips Portal is available to DriveWorks Pro customers with an active subscription and support contract.

Tech Tips provide cut down projects that highlight specific functionality for faster and more effective learning.

To access the portal:

  1. Go to https://my.driveworks.co.uk/learn/tech-tips/
  2. Login with your DriveWorks Pro account credentials, if asked
  3. Click the Visit Tech Tips Portal button for access

The portal provides a search facility, start typing the name of the Tech Tip (as indicated above) to display the Tip you require.


Knowledge Base Article Ref:KB12121043

A user form control that, when selected, will run a VBA macro.