Objective

The objective of this How-To guide is to demonstrate the functions of the Multi If command. This will be done by comparing two values in an Excel file, and then writing to that same file before saving it. OpenBots Studio enables the user to utilize If statements in order to perform tasks like comparing variables and values, determining which window is active, determining if a certain error has occurred, or even determining if certain GUI (Graphical User Interface) elements exist. Multiple If statements are very useful when certain actions need to occur once multiple criteria are met.

Prerequisites
In order to follow along with this guide, it is recommended that the user create an Excel file that contains at least two rows that themselves contain two numeric values. The file does not need to be complex and a screenshot of the file that was created for this exercise has been attached. Be sure to place the file in the project folder next to the Main .JSON file.
Walkthrough
The following are the steps involved in comparing variables and saving a file using OpenBots Studio. This automation involves click level operations from the Excel and If command lists.
Step 1: First, in order to access an Excel file throughout the entire process, the Excel application must be opened, and instance must be created first. For a more in-depth explanation of the Excel commands used in this guide, please review the Excel How To Guides here (https://openbots.ai/product/openbots-studio/how-to-guide-for-openbots-studio/excel-automation/). The Create Excel command is used to open an Excel file and create a new instance.
  • Select the Create Excel Application Command
  • Enter the Excel Instance name (User’s Choice) (Name used for this guide will be Test.)
  • Select the “Open Workbook” option (To open the prerequisite file.)
  • Enter the file path for the file (Entering {ProjectPath}\ and then the name of the file ensures that the automation always looks for the specified file in the project folder)
  • Select the visibility criteria (Yes)
  • Select whether to close all existing Excel instances (User’s choice) (Yes)
  • Click OK
Step 2: In order two compare the two values within the Excel file that was just opened, the Get Cell command must be used to extract the two values and store them in variables.
  • Select the Get Cell Command
  • Enter the Excel Instance name (Test)
  • Enter the Cell Location of the value that needs to be extracted (Depends on user’s file. For this guide, the value was in cell A2.)
  • Enter the name of the variable that will be created to store the cell value (User Choice) (This guide uses the name {vValue1}.)
  • Click OK
Step 3: The second cell value needs to be extracted as well.
  • Select the Get Cell Command
  • Enter the Excel Instance name (Test)
  • Enter the Cell Location of the value that needs to be extracted (Depends on user’s file. For this guide, the value was in cell B2.)
  • Enter the name of the variable that will be created to store the cell value (User Choice) (This guide uses the name {vValue2}.)
  • Click OK
Step 4: Now that the two cell values have been extracted, they can be compared using the Multi If command. This command, as the name implies, will create multiple If statements that will be added to the code once all of the If statements have been entered.

Note: All of the conditions within a Multi If command must be true in order for the code inside the command to run unless an Else command is added within it.

  • Select the Multi If Command
  • Click the Add New If Statement button (This will open a separate Begin If window.)
  • In the If window that was just opened, select the “Number Compare” Condition Type. In this dropdown, all of the different conditions that can be compared/checked using the If command are listed. The Condition Type chosen will change the values in the “Additional Parameters” section of the window..
  • Enter the variable that contains the first cell value extracted into the “Number1” Parameter Value ({vValue1})
  • Click the Operand dropdown and select an option. (User choice. This guide uses the “is greater than” option)
  • Enter any number into the “Number2” Parameter Value (This guide used the number 5)
  • Click OK. (This will close the If window and add the If statement to the Multi If window.)
  • Note: Variables and values can be compared to each other using this and other Condition Types as well.
    Example: vValue1 is greater than 5
Step 5: Now Value 2 also needs to be compared against a value, thus another If statement needs to be added to the Multi If window.
  • Click the Add New If Statement button (This will open a separate Begin If window)
  • In the If window that was just opened, select the “Number Compare” Condition Type.
  • Enter the variable that contains the second cell value extracted into the “Number1” Parameter Value ({vValue2})
  • Click the Operand dropdown and select an option. (User choice. This guide uses the “is less than or equal to” option)
  • Enter any number into the “Number2” Parameter Value (This guide used the number 5)
  • Click OK. (This will close the Begin If window and add the If statement to the Begin Multi If window.)
  • Click OK on the Begin Multi If window. (This will close the Begin Multi If window, add the If statements created to the automation code, and add an End If command automatically.)
Note: At this point in the process, the automation code should be similar to the screenshot below.
Step 6: Within the If statement, a Write Cell command can be added. This command is added in order to prove that the comparison was performed and, if both conditions are true, to insert the results into the Excel file itself.
  • Select the Write Cell Command
  • Enter the Excel instance name (Test)
  • Enter the message to indicate that the comparison was true. (For this guide, the message that will be used for this guide is “Both conditions were met”.) (User-Choice)
  • Enter the Cell Location. (For this guide, the cell chosen will be A3.)
  • Click OK
Step 7: If one of the conditions is not true, then a set of backup actions are needed. These actions would be placed inside of an Else command that is within the If statements created by the Begin Multi If command
  • Select the Else Command and click OK
Step 8: Underneath the Else command but above the End If command, another Write Cell command can be added in order signify that both conditions were not met. More If statements could be placed within the Else command in order to compare the values more accurately, however that is unnecessary for the purposes of this guide.
  • Select the Write Cell Command
  • Enter the Excel Instance Name
  • Enter the message to indicate that the conditions were not met. (User-Choice)
  • Enter the Cell Location. (For this guide, the cell chosen will be A3.)
  • Click OK
Step 9: Now that the Excel file has been edited, it can be saved and the application closed, marking the end of this process.
  • Select the Close Excel Application Command
  • Enter the Excel Instance name (Test)
  • Set Save Workbook to Yes
  • Click OK
All the commands in this guide can be utilized alongside many of the other commands that will be discussed in later guides. Below is a snapshot containing the commands used to compare variables.

Commands utilized for the above concept (Deleting data in Excel workbook) are as follows:

Excel Commands: Create Excel Application, Get Cell, Write Cell, Close Excel Application

If Commands: Multi If, If, End If, Else

Newsletter Bot

Lets stay in touch!

Join our weekly newsletter and follow us on social media.

Contact Sales
Call Our Experts!