Using Variables

In this chapter we are going to learn how to use the Variables

To create a new variable, you just need to determine the variable name & value. The value will determine the variable type and you can change the value to switch between the types using the same variable name.

Generated Step:

<Variable Name> = <Value>

Tip

The operator ‘=’ is used here as an Assignment operator and the same operator can be used in conditions, but for testing equality of expressions.

Note

The Variable will contains the real value (not a reference). This means that once you change the variable value, the old value will be removed from memory (even if the variable contains a list or object).

The variable type is based on the value, and this value could be

  • String (One Character, Many Characters, Many Lines, Binary Data)

  • Number (Signed Integer, Unsigned Integer, Double, Boolean)

  • List (List of one type, List of many types, Nested Lists)

  • Object

Introduction

We will create a simple program to learn how to use the Variables

We can create this program quickly using the Quick Start component

ib_quickstart_variables.png

Program Steps

After selecting the (Variables) template, we will get the next steps in the Goal Designer

gd_quickstart_variables.png

Creating the Program

To create this program we will use the next components

  • Assignment

  • Print Text

At first we will define a variable called X

The Variable value will be “Hello” which is a String

In the begining the Steps Tree is empty

1.png

Select the (Assignment) component

2.png

Enter the data in the Interaction Page

Left Side: X

Right Side: “Hello”

3.png

A new step will be added to the Steps Tree

4.png

Let’s print the variable using the (Print Text) component

5.png

Enter the data in the Interaction Page

Text: X

Type: Expression

6.png

The Steps Tree is updated!

7.png

Now we will set X to 5

X type will be a Number (The type is based on the value)

8.png

Enter the data in the Interaction Page

Left Side: X

Right Side: 5

9.png

The Steps Tree is updated!

10.png

Let’s print the variable using the (Print Text) component

11.png 12.png 13.png

Set X to 1.2

14.png 15.png 16.png

We will print the X value

17.png 18.png 19.png

X will be a List of four items [1,2,3,4]

20.png 21.png 22.png

Print the X value

23.png 24.png 25.png

X will be a String that contains the Date

26.png 27.png 28.png

Print X value (The Date)

29.png 30.png 31.png

X will be a String contains the Time

32.png 33.png 34.png

Print X value (The Time)

35.png 36.png 37.png

X will be True (Number: 1)

38.png 39.png 40.png

Print X value (Will print 1)

41.png 42.png 43.png

X will be False (Number: 0)

44.png 45.png 46.png

Print X value (Will print 0)

47.png 48.png

Now we have the final Steps Tree in our program

49.png