- The Class Hierarchy
- Creating a New Class
- Declaration and Instantiation
- Constructors and Destructors
- Garbage Collection
- Inheritance
- Object Operators
- Adding and Overriding Methods
- Calling the Overridden Method
- Overloading
- Casting
- Oddities
- Encapsulation
- Access Scope: Public, Private, Protected
- Setting Properties with Methods
- Default and Optional Parameters
- Declaring Variables Static and Const
- Revisiting the StringParser Module
- Example: Creating a Properties Class
- Data-Oriented Classes and Visual Basic Data Types
- Advanced Techniques
Declaring Variables Static and Const
When declaring variables within a method, they are treated by default like local variables that come in scope when the method starts and go out of scope when the method has completed executing. There are two variants of local variables that are also available.
Const
If you declare a variable within a method using Const instead of Dim, you are declaring a constant. The difference between this kind of constant and the other kind that I have written about is that these are local constants and so are active only for the duration of the method:
Const a = 100
This constant is local to the method, but it can be declared anywhere within the method.
Static
Static variables are new to REALbasic 2005. As such I haven't used them extensively in real-life, but they are an interesting addition. A static variable is like a local variable that's declared in a method except for one thing: It retains its value between invocations of that method.
Static a as Integer