If you define a variable named „myVar“ in a class in the main program and a variable with the same name „myVar“ in one of its methods (parameter or local variable), then the variable in the method has a higher priority, e.g. the classes variable will be hidden.
static declares variables in a method as static. They are already reserved in memory from program start, will be initialized when the controller starts and will not be initialized when the method is first called such as a temporyry variable 3)). Execution speed is higher as a temporyry variable. Remember that you should not execute this method in parallel because they will all access the same variable. This can cause hard to find errors. By default, all variables of a method are declared temporary, e.g. they exist only as long as the method is executed.
Implemented as of Version | 2015.r1 |
---|
InitialValue is a feature with which you can optionally assign an initial value to numerischen- and string variables in the dimensioning (in methods). Here all of the indicated variables, and arrays are filled with the initial value.
dim a,b(7) as byte = 42 dim s as string = "hello"
Strings are dynamic in memory and static in eeprom. When dimensioning a string in eeprom, you must add the string length identifier (number of characters). Read and write of eeprom-Variables is very slow and the number of write accesses is limited by the hardware. Do not permanently write eeprom-Variables!
Example when dimensioning in memory
dim a,b as byte dim c(19) as integer ' Word-Array of 20 elements dim s1 as string dim s2(4) as string ' String-Array of 5 elements
procedure hello(a as byte) dim c(19) as static integer ' static Word-Array of 20 elements dim s1 as string endproc
Example when dimensioning in eeprom
eedim a,b as byte eedim c(19) as integer ' Word-Array of 20 elements eedim s1[20] as string ' String of 20 byte in memory (1 string length, 19 characters) eedim s2[10](4) as string ' String-Array of 5 elements @ 10 byte each (1 string length, 9 characters)