VBS Basics – const constants

Time:2021-11-23

constant: refers to the quantity whose value remains unchanged during program operation. It is used to save fixed values, strings and other constants.

Constant definition: used in VBScriptConstDirective can create string or numeric constants whose names have a certain meaning and assign them literal values.

?
1
2
3
Const NAME = "Ethon"
Const AGE = 29
'generally speaking, constant names are all capitalized

Using custom constants can also reduce workload, such as:

?
1
2
3
4
5
msgbox("Hello World")
msgbox("Hello World")
msgbox("Hello World")
msgbox("Hello World")
msgbox("Hello World")

This program outputs Hello world five times. If you want to change the output to bye bye, you must modify all the programs. Of course, you can modify it manually five times, but what if you want to output 1000 times? Constants can solve this problem for us:

?
1
2
3
4
5
6
const HW="Hello World"
msgbox(HW)
msgbox(HW)
msgbox(HW)
msgbox(HW)
msgbox(HW)

In this way, when you want to modify the output, you just need to modify the value of HW.

Note: you cannot reassign constants

?
1
2
3
4
Const MyString = "This is a string"
MsgBox MyString
MyString = "Modify content now"
MsgBox MyString

Run the above script and report an error.

VBS Basics - const constants

This article is introduced here. Friends in need can refer to it.

Recommended Today

Seven solutions for distributed transactions

1、 What is distributed transaction Distributed transaction means that transaction participants, transaction supporting servers, resource servers and transaction managers are located on different nodes of different distributed systems. A large operation is completed by more than n small operations. These small operations are distributed on different services. For these operations, either all of them are […]