|
|
|
|
|
|
New to myExercises:
New to myNotes:
|
Constant types Intrinsic NaN (not a number) Infinity Literal Named Enumerations (Enum) purpose declarations scope
Constants are memory placeholders for data that do not change while your program is running. A meaningful name is given to a constant - this is simply to make your code easier to read. The first day of the week is Monday; Monday is a constant, because it never changes and the word Monday is meaningful because you know it refers to the first day of the week.
Visual Basic offers its own set of constants, referred to as intrinsic constants. Data types, like String, Boolean, Single, etc. are intrinsic constants, as well as vbNewLine, among others. Intrinsic means built-in or native. In addition to this you the programmer can create your own constants, which are known as named constants and literal constants.
A named constant is a memory location in the computer's memory. The data contained in it cannot change while the program is running. Once you create a named constant you use its name rather than its value in your code. Again, this makes your code easier to read and understand. Named constants are declared, just like variables, but with a prefix of con, e.g. Const conMessage As String = "Good job!". When declaring a constant, you must assign it a value.
Literal constants are actual items of data, unlike variables that are memory placeholders for data. Note that you can store a literal constant in a variable and this is done during Design Mode in Visual Basic and not during Runtime. When you declare a variable, e.g. Dim strName As String, you can store a literal constant in the strName variable during declaration, e.g. Dim strName As String = "Mary". When you assign a numerical literal constant, you would not use the quotation marks, or else Visual Basic will regard it a string, e.g. intNumber = 500 and not intNumber = "500".
Enumerations or Enum is a collective name for a set of values, e.g. the days of the week can be considered as constants and a collective name can be given for them, e.g. DaysOfWeek. DaysOfWeek will then be regarded an enumeration.
Literal
Named
Enumeration (Enum) Intrinsic Enumerations
AppWinStyle CallType CompareMethod DateFormat FileAttribute FirstDayOfWeek FirstWeekOfYear MsgBoxResult MsgBoxStyle Tristate VbStrConv
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
All content on this site is free for private use only | Contributions are encouraged | Thank you to Netfirms for the free hosting | If copyright content is published here or links to certain content violates some right/law, contact the Webmaster to have it removed immediately.
Site launched: October 2005 | Updated: July 20, 2006 | Link exchange | Site map | Contact us |