VBA/Excel/Access/Word/Language Basics/Variable

Материал из VB Эксперт
Версия от 12:46, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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