
'----------------------------------------------------------------
' Hands-On 3-1
'----------------------------------------------------------------


Sub AgeCalc()
   ' variable declaration
   Dim strFullName As String
   Dim dateOfBirth As Date 
   Dim intAge As Integer
   
   ' assign values to variables
   strFullName = "John Smith"
   dateOfBirth = #1/3/1967#
   
   ' calculate age
   IntAge = Year(Now()) - Year(dateOfBirth)

   ' print results to the Immediate window
   Debug.Print strFullName & " is " & intAge & " years old."
End Sub


'----------------------------------------------------------------
' Hands-On 3-2
'----------------------------------------------------------------

Sub MyNumber()
    Dim intNum As Integer
    
    intNum = 23.11
    MsgBox intNum
End Sub


'----------------------------------------------------------------
' Hands-On 3-3
'----------------------------------------------------------------

Sub AgeCalc2()
    ' variable declaration
    Dim FullName$
    Dim DateOfBirth As Date
    Dim age%
    
    ' assign values to variables
    FullName$ = "John Smith"
    DateOfBirth = #1/3/1967#
    
    ' calculate age
    age% = Year(Now()) - Year(DateOfBirth)
    
    ' print results to the Immediate window
    Debug.Print FullName$ & " is " & age% & " years old."
End Sub


'----------------------------------------------------------------
' Hands-On 3-4
'----------------------------------------------------------------

Sub CalcCost()
    slsPrice = 35
    slsTax = 0.085
    cost = slsPrice + (slsPrice * slsTax)
  
    strMsg = "The calculator total is $" & cost & "."
    MsgBox strMsg
End Sub


'----------------------------------------------------------------
' Hands-On 3-5
'----------------------------------------------------------------

Sub CalcCost2() ' revised CalcCost procedure
    ' declaration of variables
    Dim slsPrice As Currency
    Dim slsTax As Single
    Dim cost As Currency
    Dim strMsg As String
       
    slsPrice = 35
    slsTax = 0.085
    cost = Format(slsPrice + (slsPrice * slsTax), "0.00")
    strMsg = "The calculator total is $" & cost & "."
       
    MsgBox strMsg
End Sub


'----------------------------------------------------------------
' Hands-On 3-6
'----------------------------------------------------------------

Dim slsTax As Single ' this declaration must appear at the top of the module

Sub ExpenseRep()
    Dim slsPrice As Currency
    Dim cost As Currency
    
    slsPrice = 55.99
    cost = slsPrice + (slsPrice * slsTax)
    
    MsgBox slsTax
    MsgBox cost
End Sub


'----------------------------------------------------------------
' 
' Statements to be entered in the Immediate Window 
' (See book pages 57-58)

'----------------------------------------------------------------

TempVars("gtvUserName").Value = "Julitta Korol"
TempVars("gtvUserFolder").Value = Environ("HOMEPATH")
TempVars("gtvEndDate").Value=Format(now(),"mm/dd/yyyy")
TempVars.Add "gtvCompleted", "true"
?TempVars(1).Value
?TempVars("gtvUserFolder").Value
For each gtv in TempVars : Debug.Print gtv.Name & ":" & gtv.Value : Next
TempVars.Remove "gtvUserFolder"
?TempVars.Count
TempVars.RemoveAll


'----------------------------------------------------------------
' Hands-On 3-7
'----------------------------------------------------------------

Sub CostOfPurchase()
    ' declare variables
    Static allPurchase
    Dim newPurchase As String
    Dim purchCost As Single
    
    newPurchase = InputBox("Enter the cost of a purchase:")
    purchCost = CSng(newPurchase)
    allPurchase = allPurchase + purchCost
    
    ' display results
    MsgBox "The cost of a new purchase is: " & newPurchase
    MsgBox "The running cost is: " & allPurchase
End Sub



'----------------------------------------------------------------
' Hands-On 3-8
'----------------------------------------------------------------


Sub HideControl()
    ' this procedure is run against the open Customers form
    Dim frm As Form
    Dim myControl As Control
    Set frm = Forms!Customers
    Set myControl = frm.CompanyName
    myControl.Visible = False
    'myControl.Visible = True
    
    Set frm = Nothing
    Set myControl = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 3-9
' No code for this Hands-On. 
' Please follow the instructions in the book.
'----------------------------------------------------------------


'----------------------------------------------------------------
' Hands-On 3-10
' Statements to be tried out in the Immediate window.
'----------------------------------------------------------------

age = 28
birthdate = #1/1/1981#
firstName = "John"
?varType(age)
?varType(birthdate)
?varType(firstName)


'----------------------------------------------------------------
' Hands-On 3-11
' No code for this Hands-On. 
' Please follow the instructions in the book.
'----------------------------------------------------------------


'----------------------------------------------------------------
' Hands-On 3-12
' Event procedure code for the Customers form
'----------------------------------------------------------------

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
    If FilterType = acFilterByForm Or _
        FilterType = acFilterAdvanced Then
        MsgBox "You need authorization to filter records."
        Cancel = True
    End If
End Sub


'----------------------------------------------------------------------
' Additional example code in this chapter
' (See book pages 67-68)
'----------------------------------------------------------------------

Public Enum StatusType
    Rejected = 0
    MoreInfo = 1
    Approved = 2
    Completed = 3
End Enum


Sub GetStatusType()

    Dim result As Integer
    
    result = InputBox("Please enter a number from 0 to 3", "Status Type", 0)
    
    If result = StatusType.MoreInfo Then
        MsgBox ("Please provide more details on a separate form.")
    ElseIf result = StatusType.Rejected Then
        MsgBox ("Please apply again next year.")
    ElseIf result >= StatusType.Approved Then
        MsgBox ("Thank you for applying.")
    End If

End Sub




