User Tools

Site Tools


Local Variables

Local variables are only available in the task where they have been declared. While declaring a variable, its type is set. The following types are available:

  • Integer (32 Bit)
  • Single (16 Bit integer)
  • Double (64 Bit Floating Point)
  • Boolean (True or False)
  • String (e.g. “Hello World”)
  • Variant (any)

It is possible to build arrays from all those types.

A variable is declared by the Dim statement. Variable names must start with a letter and must not contain special characters. Here some examples:

  • Dim A1 As Integer correct
  • Dim Ä1 As Integer incorrect
  • Dim 1A As Integer incorrect
  • Dim A 1 As Integer incorrect, space not allowed
  • Dim A_1 As Integer correct

In the screenshot above, the Dim statement declares a String variable named foo. Then, the variable foo gets the value “Hallo Welt”. The content of foo is displayed by the ShowMessage command with foo as parameter. In this example, a line ShowMessage(“Hallo Welt”) would have the same result.

Variant variables are very special. Because they have no (or any) type, they are very flexible. A variant stores a value in different formats and “knows” which one is needed if there is an access to. In the example below a variant variable named v is declared:

In the For..Next loop, an integer value is assigned to v. As discussed above, the ShowMessage command need a string variable as parameter, but the line ShowMessage(“Count:” + v) is working correct, because v knows that only strings are valid and present its content as string. So v is used as integer and as string in the same subroutine. A more structured solution for the same job is the example below:

At first, an integer variable i is declared. The beginning of the For..Next loop is unchanged, because the For..Next instruction expect an integer variable anyway. The command ShowMessage(“Count:”+ i) will not work, because it is impossible to add an integer to a string. But V-Control Basic knows a function that converts an integer to string, the Str(i) command. The result of str(i) is “10”, if i has the value 10. The string “10” comprising from ASCII code 49 (“1”) and ASCII code 48 (“0”).

An Overview of available basic functions is available in the Basic Language Reference Chapter.

Another often used variable type is boolean. Boolean variables know to states, True or False (1/0).

In this example, the variable b1 is declared as Boolean. The PromptMessage command need a boolean variable to return the result of the PromptMessage dialog. If the result is True, the OK button was pressed, if False, the user clicked the Cancel button. The if..then instruction check b1 and branch to the correct ShowMessage command.

locale_variables.txt · Last modified: 2013/07/31 15:56 by admin