
'----------------------------------------------------------------
' Hands-On 4-1
'----------------------------------------------------------------


Function JoinText(k, o)
    JoinText = k + " " + o
End Function


'----------------------------------------------------------------
' Hands-On 4-2
' Statement to be entered in the Immediate Window.
'----------------------------------------------------------------

?JoinText("function", " procedure")


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

Sub EnterText()
    Dim strFirst As String, strLast As String, strFull As String
    
    strFirst = InputBox("Enter your first name:")
    strLast = InputBox("Enter your last name:")
    strFull = JoinText(strFirst, strLast)
    
    MsgBox strFull
End Sub


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

Sub HowMuch()
    Dim num1 As Single
    Dim num2 As Single
    Dim result As Single
    
    num1 = 45.33
    num2 = 19.24
    result = MultiplyIt(num1, num2)
    
    MsgBox result
End Sub

Function MultiplyIt(num1, num2) As Integer
    
    MultiplyIt = num1 * num2
    
End Function


Function NumOfDays()
    NumOfDays = 7
End Function
    
Sub DaysInAWeek()
    MsgBox "There are " & NumOfDays & " days in a week."
End Sub



'----------------------------------------------------------------
' Hands-On 4-5
'----------------------------------------------------------------

Sub ThreeNumbers()
    Dim num1 As Integer, num2 As Integer, num3 As Integer

    num1 = 10
    num2 = 20
    num3 = 30

    MsgBox MyAverage(num1, num2, num3)
    MsgBox num1
    MsgBox num2
    MsgBox num3
End Sub

Function MyAverage(ByVal num1, ByVal num2, ByVal num3)
    num1 = num1 + 1
    MyAverage = (num1 + num2 + num3) / 3
End Function



'----------------------------------------------------------------
' Hands-On 4-6
'----------------------------------------------------------------

Function Avg(num1, num2, Optional num3)
    Dim totalNums As Integer

    totalNums = 3
    If IsMissing(num3) Then
        num3 = 0
        totalNums = totalNums - 1
    End If
    Avg = (num1 + num2 + num3) / totalNums
End Function


'----------------------------------------------------------------
' Hands-On 4-7
'----------------------------------------------------------------

' Statements to be entered in the Immediate Window
' Each statement must be entered on one line as shown below

MsgBox "All done. Now open ""Test.doc"" and place an empty CD in the CD-ROM drive. The following procedure will copy this file to the CD."
MsgBox "All done." & Chr(13) & "Now open ""Test.doc"" and place" & Chr(13) & "an empty CD in the CD-ROM drive." & Chr(13) & "The following procedure will copy this file to the CD."


'Procedure code in this Hands-On

Sub MyMessage()
    MsgBox "All done." & Chr(13) _
    & "Now open ""Test.doc"" and place" & Chr(13)  _
    & "an empty CD in the CD-ROM drive." & Chr(13)  _
    & "The following procedure will copy this file to the CD."
End Sub


Sub MyMessage2()
    MsgBox "All done." & Chr(10) & Chr(10) _
    & "Now open ""Test.doc"" and place" & Chr(13) _
    & "an empty CD in the CD-ROM drive." & Chr(13) & Chr(13) _
    & "The following procedure will copy this file to the CD."
End Sub


' Statements to be entered in the Immediate Window
MsgBox "How are you?", vbOKOnly + vbApplicationModal, "Application Modal"
MsgBox "How are you?", vbOKOnly + vbSystemModal, "System Modal"
MsgBox "Do you want to proceed?", 292
MsgBox "Do you want to proceed?", vbYesNo + vbQuestion + vbDefaultButton2


'----------------------------------------------------------------
' Hands-On 4-8
'----------------------------------------------------------------


Sub MsgYesNo()
    Dim question As String
    Dim myButtons As Integer

    question = "Do you want to open a new report?"
    myButtons = vbYesNo + vbQuestion + vbDefaultButton2
    MsgBox question, myButtons
End Sub

Sub MsgYesNo2()
    Dim question As String
    Dim myButtons As Integer
    Dim myTitle As String
    
    question = "Do you want to open a new report?"
    myButtons = vbYesNo + vbQuestion + vbDefaultButton2
    myTitle = "New report"
    MsgBox question, myButtons, myTitle
End Sub



'----------------------------------------------------------------
' Hands-On 4-9
'----------------------------------------------------------------

Sub MsgYesNo3()
    Dim question As String
    Dim myButtons As Integer
    Dim myTitle As String
    Dim myChoice As Integer
    
    question = "Do you want to open a new report?"
    myButtons = vbYesNo + vbQuestion + vbDefaultButton2
    myTitle = "New report"
    myChoice = MsgBox(question, myButtons, myTitle)
    MsgBox myChoice
End Sub


'----------------------------------------------------------------
' Hands-On 4-10
'----------------------------------------------------------------

Sub Informant()
    InputBox prompt:="Enter your place of birth:" & Chr(13) _
    & " (e.g., Boston, Great Falls, etc.) "
End Sub


Sub Informant2()
    Dim myPrompt As String
    Dim town As String
    
    Const myTitle = "Enter data"
    myPrompt = "Enter your place of birth:" & Chr(13) _
    & "(e.g., Boston, Great Falls, etc.)"
    town = InputBox(myPrompt, myTitle)
    
    MsgBox "You were born in " & town & ".", , "Your response"
End Sub



'----------------------------------------------------------------
' Hands-On 4-11
'----------------------------------------------------------------

Sub AddTwoNums()
    Dim myPrompt As String
    Dim value1 As String
    Dim mySum As Single
       
    Const myTitle = "Enter data"
           
    myPrompt = "Enter a number:"
    value1 = InputBox(myPrompt, myTitle, 0)
    mySum = value1 + 2
       
    MsgBox mySum & " (" & value1 & " + 2)"
End Sub


'----------------------------------------------------------------
' Hands-On 4-12
'----------------------------------------------------------------

Sub AboutUser()
    Dim fullName As String
    Dim firstName As String
    Dim lastName As String
    Dim space As Integer
    
    ' get input from user
    fullName = InputBox("Enter first and last name:")
    
    ' get first and last name strings
    space = InStr(fullName, " ")
    firstName = Left(fullName, space - 1)
    lastName = Right(fullName, Len(fullName) - space)
    
    ' display last name, first name
    MsgBox lastName & ", " & firstName
End Sub


Sub AboutUserMaster()
    Dim first As String, last As String, full As String
    
    Call GetUserName(full)
    
    first = GetFirst(full)
    last = GetLast(full)
    
    Call DisplayLastFirst(first, last)
End Sub

Sub GetUserName(fullName As String)
    
    fullName = InputBox("Enter first and last name:")
    
End Sub

Function GetFirst(fullName As String)
    Dim space As Integer
    
    space = InStr(fullName, " ")
    GetFirst = Left(fullName, space - 1)
End Function

Function GetLast(fullName As String)
    Dim space As Integer
    
    space = InStr(fullName, " ")
    GetLast = Right(fullName, Len(fullName) - space)
End Function

Sub DisplayLastFirst(firstName As String, lastName As String)
    
    MsgBox lastName & ", " & firstName
    
End Sub




