HandsOn Using Type Declaration Characters in Variable Names

1. If the Visual Basic window is not open, press Alt+F11 to open it. Next, choose Insert | Module to add a new module.

2. Enter the code of the AgeCalc2 procedure in the new module's Code window.

3. To run the procedure, click any line between the Sub and End Sub keywords and press F5 or choose Run | Run Sub/UserForm.

Sub AgeCalc2()

' variable declaration Dim FullName$ Dim DateOfBirth As Date Dim age%

' assign values to variables FullName$ = "John Smith" DateOfBirth = #l/3/1967#

' calculate age age% = Year(Now()) - Year(DateOfBirth)

' print results to the Immediate window Debug.Print FullName$ & " is " & age% & " years old." End Sub

Part I

0 0

Post a comment