MACRO LIBRARY

Lesson 1.3 homework solution

Free public access. No account or subscription required.

Files

Lesson 1.3 homework solution

Code

'Homework 1.3
'Problem: Create a macro that displays a message box with the name and age of a family _
    member, as well as their relation to you.  (Or, use your coworkers' names, their position, _
    and their years at the company-whichever you prefer.)  Which family member's information _
    is displayed is determined by which element you specify in a variable called intElement. _
    (intElement corresponds to intCustomerNum in the video lesson.)
    
Dim strName(3) As String
Dim intAge(3) As Integer
Dim strRelation(3) As String
Dim intElement As Integer
    
Sub main()
    intElement = 2
    
    strName(0) = "Peter"
    intAge(0) = "13"
    strRelation(0) = "nephew"
    
    strName(1) = "Susan"
    intAge(1) = "12"
    strRelation(1) = "niece"
    
    strName(2) = "Edmund"
    intAge(2) = "10"
    strRelation(2) = "nephew"
    
    strName(3) = "Lucy"
    intAge(3) = "8"
    strRelation(3) = "niece"
    
    MsgBox strName(intElement) & " is " & intAge(intElement) & " years old and is my " _
        & strRelation(intElement) & "."
End Sub