mobile databases, mobile forms, and mobile synchronization … where you need to work
Providing Pocket Access, Mobile Database, Windows CE Database, and Windows CE Development Solutions

Tip of the Month (July 2006)

Controlling a Macro by Using an "if" Expression in a SKIP Command Button

When your macro is running, you may want to skip some steps based on some condition. For example, you may have a macro that creates a total and, if an total is more than $100.00, you may want to apply a 10% discount.

You can do this using a SKIP command button as one of the steps of your macro. There are two kinds of SKIP's. The first skips a specific number of steps in your macro. The second (introduced in Visual CE 12.0) allows you to skip to a specific place in your macro.

Skipping a Specific Number of Steps

When skipping a specific number of buttons, the number of buttons to skip would be designated by an "if" expression:

  • Step 1 - ASSIGN: set TOTAL to (ITEM_1 + ITEM_2 + ITEM3)
  • Step 2 - SKIP: if TOTAL > 100.00 then 0 else 1
  • Step 3 - ASSIGN: set TOTAL to (TOTAL * 0.9)
  • ... the rest of the macro

The second step tests the total and, if it is less than $100.00, it skips over one step (the step that applies a 10% discount).

In the example above the "else" part of the "if" was just a very simple expression (in particular, just 1). But the "else" part can be any expression, even another "if" statement.

For example, you may want to apply a 75% discount if the total is more than $1000.00 and apply a 10% discount if the total is is between $100.00 to $1000.00:

  • Step 1 - ASSIGN: set TOTAL to (ITEM_1 + ITEM_2 + ITEM3)
  • Step 2 - SKIP: if TOTAL > 1000.00 then 0 else if TOTAL > 100.00 then 2 else 3
  • Step 3 - ASSIGN: set TOTAL to (TOTAL * 0.75)
  • Step 4 - SKIP: 1
  • Step 5 - ASSIGN: set TOTAL to (TOTAL * 0.9)
  • ... the rest of the macro

Note that by nesting one "if" inside another, you effectively create "if ... else if ... else" expressions.

Skipping to a Specific Place in Your Macro

Starting in Visual CE 12.0, you can label specific places in your macro and, when the macro is running, jump right to that place.

Using this technique, the first macro above can be rewritten as:

  • Step 1 - ASSIGN: set TOTAL to (ITEM_1 + ITEM_2 + ITEM3)
  • Step 2 - SKIP: if TOTAL <= 100.00 then go to no_discount
  • Step 3 - ASSIGN: set TOTAL to (TOTAL * 0.9)
  • Step 4 - MACRO STEP LABEL: "no_discount"
  • ... the rest of the macro

The second step tests the total and, if it is less than $100.00, it skips right to the label.