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.
1. CREATE NEW > PROJECT > BASIC PROJECT > OK
2. Set a filename, in this case VariablesAndTypes > OK
3. Replace the existing code with
6. Now define the variable within the PROCEDURE:
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.
Separated by spaces you can define as many variables as you want.
12. Add the following line to your code:
13. Add the following line to your code:
14. Add the following line to your code:
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.
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.