您可以使用 Const 陳述式在 BSL 中建立使用者定義的常數。您可以使用 Const 陳述式,建立名稱有意義的字串或數值常數,並為其指派文字值。
例如:
Const MyString = "This is my string." Const MyAge = 49
註:
字串文字以引號 ("") 括住。引號是區分字串值與數值最明顯的方式。下列範例說明建立常數的用法:
範例 1:
Const MyString = "This is my string." 'Defines a string constant.
範例 2:
Const MyAge = 49 'Defines a numeric constant.
範例 3:
Const Pi = 3.14159, E = 2.71828, Gravity = 9.81 'Defines multiple numeric constants.
範例 4:
Const Greeting = "Hello," Const Name = "Alice" Dim WelcomeMessage WelcomeMessage = Greeting & Name 'Combines string constants. 'WelcomeMessage 'has string value: Hello, Alice