IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB.Net  Print This     

Constants (VB.Net and Delphi Prism Cross Reference Guide)

By Mike Prestwood

VB.Net versus Delphi Prism: A side by side comparison between VB.Net and Delphi Prism.

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Constants

[Other Languages] 

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

VB.Net:   Const kPI Double = 3.1459

In VB.Net, you define constants with the Const keyword.

All constants are part of a class (no global constants) but you can make a constant public and have access to it using ClassName.ConstantName so long as you have added the class to the project. This works even without creating the class as if the public constants were static, but you cannot use the Shared keyword.

Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or string), an enumeration, or a reference to null.

Syntax Example:
Public Class Convert
Inherits System.Object
 
  Public Const kName As String = "Mike"
  Private Const kPI Double = 3.1459
 
  //Declare two or more on same line too:
Const kFeetToMeter = 3.2808, kMeterToFeet = 0.3048
End Class
Delphi Prism:   const kPI: Double=3.1459;

In Prism, you define constants similar to how you define variables but use the Const keyword instead of the Var keyword. Specifying the type is optional. If you don't specify the type, the compiler chooses the most appropriate type for you.

Declare class constants as part of the class definitions. Declare local constants above the begin..end. Although Prism support inline variables, inline constants are not supported.

Syntax Example:
//Specified type:
const
kFeetToMeter: Double = 3.2808;
  kMeterToFeet: Double = .3048; 
  kName: String = "Mike";

//Unspecified type:
const kPIShort = 3.14;












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]