Beginners’ Tutorial in Visual Logic

This example shows how to quickly build Visual Logic code. It gives detailed instruction about how to input and edit Visual Logic. The example is a process where the different types of Work Items should travel to different directions. Note that this can also be achieved without the use of Visual Logic, but the example below aims to get you started with Visual Logic through a very simple application.

1. Setting Up

Create a simple simulation like this:

The aim of the example is for Activity 1 to send Work items of Type 1 to the first destination which is Queue for Activity 2, and items of Type 2 to the second destination, that is Queue for Activity 3.

Their type is defined by a Label. Go to the Data & Rules Tab and enter the Labels dialog. Create a Label called “lbl_Type”, assign it to Object Start Point 1, and add a “Set To:” Action, so the Label is set to a Rounded Uniform distribution with parameters 1 and 2. More detailed instructions on setting up this Label are found in the Labels Tutorial. After that, create also a Label called “Route to take”, without assigning to Objects or setting it to any Actions.

To make sure that Work Items will be directed based on the value of “Route to take”, go to the Routing Out dialog of Activity 1, select “Label” and select Route to take from the list of all Labels in simulation. In our example, because Queue for Activity 2 is at the top of the list, if Route to take takes a value of 1, the Work Item will be directed to Queue for Activity 2, and if it takes a value of 2, the item will be directed to Queue for Activity 3.

2. Building the code

You are now ready to start building your Visual Logic code. The code will check the Work Item’s type based on lbl_Type value, and will set Route to take, so Routing Out by Label of Activity 1 can be facilitated.

Navigate to Activity 1> Additional Tab> Events and select on End Logic, which is obeyed after each Work item has been processed by the Activity. Now we have a blank window into where we can enter our Visual Logic.

As shown above, you can right-click in the window to start adding Visual Logic using a wizard.

The first step is to check the Work Item’s type. For that, you will need a Conditional IF command. This is a common command in Visual Logic. You can access it by right-clicking on the window and selecting the “If…Else/While etc.” option, or you can find it using the Search box on the window’s left side.

Once selecting the IF command, you will access the Conditional Block Editor.

The Editor will enable you to check the value of lbl_Type against the value of 1, i.e. to check whether the item’s type is type 1. You can either type the Label’s name and the number directly in the dialog or you can insert these from the Formula Editor, accessed by clicking on the ellipsis shown in the picture.

Press OK and you can see that the IF statement now shows up in your Visual Logic Editor.

The next step is to assign a value to the Label “Route to take”, if the above condition is true. You can do that by using the SET command. Once having finished the IF line, click on the subsequent line, and use the Editor to insert the parameters used by the SET command – the variable which will get the new value (in our case the Label “Route to take”) and the value assigned.

Afterwards, you need to set the value of “Route to take” if lbl_Type has a value of 2 (or other values if our lbl_Type takes more than just two values).We normally need to exhaust all conditions in our code. The code should finally look like this:

You will notice that we only used one IF statement and then continued using an ELSE IF statement. There are different occasions for using IF/ELSE/ELSE IF statements in Visual Logic. In this case, also an ELSE statement could also be used, since the only other value lbl_Type can take is 2.

You have now built your first Visual Logic Section, well done!

Please note that you can also free-type into the Visual Logic window, using Logic Writer and Developer modes.

3. Validation

An easy way of ensuring that this piece of Visual Logic works as expected is to check the Current Contents of the succeeding Queues or Activities to make sure that Work Items in Activity 2 are only of type 1 and items in Activity 3 are of type 2. Current Contents are found under the Properties tab of these Objects. Run for your simulation for a little bit, stop it at any point, and inspect Current Contents.

However, there are various ways of debugging Visual Logic so you can verify it is used appropriately in the simulation.

See also