Constants
Constants are named storage locations in memory, the value of which does not change during program Execution. They remain the same throughout the program execution. When the user wants to use a value that never changes, a constant can be declared and created. The Const statement is used to create a constant. Constants can be declared in local, form, module or global scope and can be public or private as for variables. Constants can be declared as illustrated below.
Public Const gravityconstant As Single = 9.81
Predefined Visual Basic Constants
The predefined constants can be used anywhere in the code in place of the actual numeric values. This makes the code easier to read and write.
For example consider a statement that will set the window state of a form to be maximized.
Form1.Windowstate = 2
The same task can be performed using a Visual Basic constant
Form1.WindowState = vbMaximized
Data Type Conversion
Visual Basic functions either to convert a string into an integer or vice versa and many more conversion functions. A complete listing of all the conversion functions offered by Visual Basic is elucidated below.
Conversion To | Function |
Boolean | Cbool |
Byte | Cbyte |
Currency | Ccur |
Date | Cdate |
Decimals | Cdec |
Double | CDbl |
Integer | Cint |
Long | CLng |
Single | CSng |
String | CStr |
Variant | Cvar |
Error | CVErr |
A conversion function should always be placed at the right hand side of the calculation statement.
Visual Basic Built-in Functions
Many built-in functions are offered by Visual Basic fall under various categories. These functions are procedures that return a value. The functions fall into the following basic categories that will be discussed in the follwing sections at length.
-
Date and Time Functions
-
Format Function
-
String Functions
No comments:
Post a Comment
Comment will be published after moderation only. Do not advertise here.