MACRO LIBRARY

Lesson 1.5 homework solution

Free public access. No account or subscription required.

Files

Lesson 1.5 homework solution

Code

'Homework 1.5
'Problem: Modify your homework from lesson 1.3 so that all entries are displayed using a loop. _
    Try to accomplish this using a For ... Next loop first, and then a While ... Wend loop or _
    a Do loop.
    
Dim strName(3) As String
Dim intAge(3) As Integer
Dim strRelation(3) As String
Dim intElement As Integer
Dim i 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"
    
    For i = 0 To UBound(strName)
        MsgBox strName(i) & " is " & intAge(i) & " years old and is my " & strRelation(i) & "."
    Next i
    
    i = 0
    While i <= UBound(strName)
        MsgBox strName(i) & " is " & intAge(i) & " years old and is my " & strRelation(i) & "."
        i = i + 1
    Wend
End Sub