Declarations
- Dim - Used to define a variable as a certain type
- i = dim i as integer, r as single
- You can use the Option Explicit to make sure that VB forces you to declare every variable you use. DIM is that simplest way to declare a variable
- i = dim i as integer, r as single
- ReDim - Used to change the dimensions of a dynamic array
- redim arrayname(37)
- Don't be afraid of this one. You can use ReDim to create an array whose size grows by 1 every time you want to add a number to it. Then, the UBound tells you how many numbers you've added.
- redim arrayname(37)
- Static - Establishes a procedure variable which keeps its value between calls
- static i as integer
- For example, if you want to keep track of how many times you've been in a procedure, set a counter as STATIC and increment it by one for each visit to the procedure. It will never go away until the program is terminated.
- static i as integer
- Public - Creates a variable which can be accessed outside its own procedure
- public i as integer
- Even if you're the only programmer writing code in your application, use of Private vs Public will help catch errors if you inadvertently try to access an out-of-scope variable
- public i as integer
- Private - Creates a variable that can be read only in its own procedure or module, according to where the declaration took place.
- private i as integer
- Use this as often as possible to avoid unnecessary exposure of your variables to coding mistakes.
- private i as integer
- Sub - Defines a procedure which can execute a block of code
- Sub NewProcedure (var1 as integer, var2 as string)
- Be sure to check out HELP for how to handle Sub arguments. There are more questions and mistakes made concerning the use of arguments than just about anything else I've seen.
- Sub NewProcedure (var1 as integer, var2 as string)
- Function - Declares a procedure which can return a value
- Function NewFunction (var1 as integer, var2 as string) as SINGLE
- This is actually the most versatile of the Sub/Function procedure types. It can do anything a Sub can do as well as returning a value for use in an expression.
- Function NewFunction (var1 as integer, var2 as string) as SINGLE
- Call - Transfers control to a Sub or Function (is optional)
- Call Procedure 1
- Since the use of CALL is optional, forget you ever saw it
- Call Procedure 1
- CallByName - Executes a method of an object or set/returns a property
- CallByName (form1,procedurename,vbMethod)
- The really cool thing about this is that you don't have to hardcode a procedure call. Just use a string variable with the name of the procedure to call.
- CallByName (form1,procedurename,vbMethod)
- Option Explicit - Instructs VB to force an explicit declaration of all variables
- Option Explicit
- You're borderline stupid if you don't use it to catch typing errors. Set up the VB IDE to automatically include this in all projects.
- Option Explicit
- Option Compare - Instructs VB on how to make string comparisons
- Option Compare Binary
- This can add case-insensitivity for those times when you don't want to hard-code it
- Option Compare Binary
- Option Private - Prevents a module's content from being referenced outside a project.
- Option Private Module
- Generally doesn't apply to most VB applications. If you find a good use for it let me know.
- Option Private Module
- Property Get - Declares how to get the value of a property
- Property Get Name()
- You won't use this much until you get into creating classes of your own
- Property Get Name()
- Property Let - Declares how to assign a value to a property
- Property Let Name()
- You won't use this much until you get into creating classes of your own
- Property Let Name()
- Property Set - Declares how to set a variable reference to an object
-
- You won't use this much until you get into creating classes of your own
-
- Set - Assigns an object reference to a variable
- Set X = form1.txtInputFromUser
- Very useful for making code more readable or simply to cut down on how much typing you have to do!
- Set X = form1.txtInputFromUser
- Let - Precedes assignment of a value to a variable
- Let i = 3
- It's optional, no one uses, so forget you ever saw it
- Let i = 3
- Type...End Type - Creates a user defined part type which consists of standard VB data types
- type anytypename
- one as string
- two as integer
- three as boolean
- End Type
- This is a really excellent way to keep several kinds of data under one variable name. Plus, you can PUT or GET a user-defined type with a single line of code.
- type anytypename
- Const - Creates a variable whose value is fixed
- const anyname
- style="font-style: normal 8.5pt" style="font-family: Verdana"U se this to give easy to remember names to values. For example, suppose you use the value 37.2 a lot in your code, then if you put CONST MyAge = 37.2 in your code you'll be able to insert the MyAge where the 37.2 should have gone. Easier to type and easier to read. Also, you can chane the value of the constant by changing only the declaration line of code, rather than searching out every place the value was used!
- const anyname
- Declare - Used to define a procedure that exists in another file
- declare functionname (arg1 as integer, arg2 as string) as integer
-
- ArrayName = Array (10, 20, 30)
- Implements - Specifies a class to be implemented in a module
- Friend - Allows procedure to be callable from modules outside the class
- GetObject - Return a reference to an ActiveX component
- CreateObject - Creates and returns a reference to an ActiveX object
- GetAutoServerSettings - Returns information about the state of an ActiveX component's registration.
- Enum - Declares a type for an enumeration
- Event - Declares a user-defined event
- TypeName - Returns the type of data in a variable
- VarType - Returns the type of data in a variable
- DefType - Sets the default data type of variables
- DefInt A-Z
- IS - A variety of data type or status checking options
- IsArray , IsBindable, IsBroken, IsDate, IsDirty, IsEmp
- declare functionname (arg1 as integer, arg2 as string) as integer
