To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe

DataFlex Courses

Information

Next lesson:
Flow control
Cancel

Learn the Language

Lesson 2: Variables and Types

DataFlex is a strongly typed language. The most common types are:
 

 

Type conversion is automatic. If you have a function that expects a certain type and you call it using a different type, it will automatically try to convert the value at runtime.
In this demonstration we’re going to take a look at how to use and declare variables within a simple program.

Demonstration
1.    CREATE NEW > PROJECT > BASIC PROJECT > OK

2.    Set a filename, in this case VariablesAndTypes > OK


3.    Replace the existing code with

DfAllEnt.pkg


 

4.    Add 

PROCEDURE LEARNVARIABLES


5.    Add

SEND LEARNVARIABLES

6.    Now define the variable within the PROCEDURE:

STRING STEXT

7.    Add:

MOVE “HELLO FROM VARIABLE” to sText

8.    Add:

SEND INFO_BOX STEXT “HELLO”

9.    Click on RUN (F5) – now you should see an info box should appear with the text “Hello from variable”.
10.    This result can also be achieved with different types of variables. Remove part of the code.

11.    Type:

Integer iVal1 iVal2


Separated by spaces you can define as many variables as you want.

12.    Add the following line to your code:

Move 5 to iVal1


13.    Add the following line to your code:

Move (iVal1*7) to iVal2


14.    Add the following line to your code:

Send Info_Box iVal2 “Hello”


 

15.    Click RUN (F5). An info box should now say “35”. The value of iVal1 is now set to 5 and the value of iVal1*7 is the value of iVal2.

16.    If you try to input an invalid value, in a value of a different type, you will get an error.

17.    Example:

Move ‘N123’ to iVal1


 


18.    Click RUN (F5)
19.    An error message will pop-up
20.    Click DEBUG – The program will find the line that contains the error.

 
21.    The line of code pointed out can just be deleted in this case.
22.    Instead of multiplying by 7, we are going to divide iVal1 by 2. You will see that the integer value cannot hold decimals, so it rounds the result down to 2, instead of 2.5. We have to change it into a number type in order to display decimals.


23.    Replace INTEGER with NUMBER in the code.
24.    Click RUN (F5) – The number should be displayed correctly now, with decimals.

 
25.    Let’s look at another example, Date.
26.    Replace “Number iVal1 iVal2” with “Date dToday” etc.
27.    Click RUN (F5) and now you should see the date of today displayed in the info box.