在VB中,可以使用以下方式聲明變量:
Dim
:Dim variableName As DataType
例如:Dim age As Integer
Static
:Static variableName As DataType
例如:Static counter As Integer
Public
:Public variableName As DataType
例如:Public name As String
Private
:Private variableName As DataType
例如:Private balance As Double
Friend
:Friend variableName As DataType
例如:Friend count As Integer
Const
:Const variableName As DataType = value
例如:Const PI As Double = 3.14159
注意:在聲明變量時,需要指定變量的數據類型。常見的數據類型包括整數(Integer)、浮點數(Double、Single)、字符串(String)、布爾值(Boolean)等。