MACRO LIBRARY

Lesson 1.9 homework solution

Free public access. No account or subscription required.

Files

Lesson 1.9 homework solution

Code

Module: HW1_91

'Homework 1.9 - complete
'This code is intended to reverse the text displayed in the label. The incomplete code contained _
    three mistakes: _
    -the label is mistyped "lblWords" instead of "lblText" _
    -the For ... Next loop should begin at 1 not 0 _
    -intPosition should equal intLength - 1, not + 1
    
Sub main()
    UserForm1.Show
End Sub

User form: UserForm1

Dim strText As String
Dim strRevText As String
Dim intLength As Integer
Dim intPosition As Integer
Dim i As Integer
    
Private Sub cmdReverse_Click()
    strText = lblText.Caption
    intLength = Len(strText)
    intPosition = intLength
    strRevText = ""
    For i = 1 To intLength
        strRevText = strRevText & Mid(strText, intPosition, 1)
        intPosition = intLength - i
    Next i
    lblText.Caption = strRevText
End Sub