VBA/Excel/Access/Word/Language Basics/Variable
Версия от 16:33, 26 мая 2010; (обсуждение)
Assigning Values to Variables
Sub CalcCost()
slsPrice = 35
slsTax = 0.085
cost = slsPrice + (slsPrice * slsTax)
strMsg = "The calculator total is " & "$" & cost & "."
MsgBox strMsg
End Sub
declare several variables on the same line, separating each variable name with a comma
Sub declSeveral()
Dim FullName As String, DateOfBirth As Date, age As Integer
End Sub
Using Variables
Sub AgeCalc()
Dim FullName As String
Dim DateOfBirth As Date
Dim age As Integer
FullName = "John Smith"
DateOfBirth = #1/3/1967#
age = Year(Now()) - Year(DateOfBirth)
Debug.Print FullName & " is " & age & " years old."
End Sub