VBA/Excel/Access/Word/Language Basics/Variable — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 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