VBA/Excel/Access/Word/Language Basics/Variable Type
Содержание
Define an integer
Sub intSub()
Dim number As Integer
number = 32
End Sub
Define a string variable
Sub stringSub()
Dim lastName As String
lastName = "Smith"
End Sub
Mix integer and string in MsgBox
Sub msgBox()
"Declare the variables
Dim intNumber1 As Integer
Dim intNumber2 As Integer
Dim intSum As Integer
"Create InputBoxes to enter numbers
intNumber1 = 1
intNumber2 = 2
"Add numbers
intSum = intNumber1 + intNumber
Debug.Print "The numbers entered were " & intNumber1 & " and " & intNumber2
End Sub
Read integer number from InputBox
Sub addNumbers()
"Declare the variables
Dim intNumber1 As Integer
Dim intNumber2 As Integer
Dim intSum As Integer
"Create InputBoxes to enter numbers
intNumber1 = 1
intNumber2 = 2
Debug.Print intNumber1 + intNumber
End Sub
Types of Variables
Variable Type Description
Boolean True or False.
Byte It can only hold a single value between 0 and 255.
Currency It holds a currency value with four decimal places, from -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Date This stores both dates and time. Interestingly, the years range from 100 to 9999.
Double Doubles are for very large numbers. The range runs from -4.940656458411247 * 10^-324 to 4.94065645841247 * 10^-324.
Integer nteger handles the range of numbers -32,768 to 32,767.
Long Long handles the number range -2,147,483,648 to 2,147,483,657.
Object You can store an object as a variable for later use.
Single This is the second decimal point type, the other being Double.
String A String variable can hold up to 2 billion characters.