Practice Exercise 4
Looping

' Student Name
' CIS 220
' DATE
' Triangle Lab
'
' Each button click arranges a triangle of asterisks
' in a different order and displays them in their
' own label.
'-----------------------------------------------------
Public Class frmTriangleLab
    
'
     ' We use a constant declared at the form level because
     ' the constant will be used in multiple click events to
     ' control how many asterisks are printed. Including it
     ' as a constant makes it much easier to modify the program
    
' if the requirements change at a later date.
    
'
     Const maxStars As Integer = 10

     '-------------------------------------------------
     ' This Click event starts with one asterisk and
     ' adds one asterisk with each new row.
     '-------------------------------------------------
     Private Sub cmdPatternA_Click(ByVal sender As System.Object, _
                                                   ByVal e As System.EventArgs) _
                                                   Handles cmdPatternA.Click
          lblOutputA.Text = ""
        
 Dim row As Integer
          Dim stars As Integer

             For row = 1 To maxStars
               For stars = 0 To row - 1
                    lblOutputA.Text &= "*"
               Next
               lblOutputA.Text &= vbCrLf
         Next
     End Sub

     '-------------------------------------------------
     ' This click event starts 10 asterisk and prints
     ' one line on each new line.
     '-------------------------------------------------
     Private Sub cmdPatternB_Click(ByVal sender As System.Object, _
                                                   ByVal e As System.EventArgs) _
                                                   Handles cmdPatternB.Click
          lblOutputB.Text = ""
         
Dim row As Integer
          Dim stars As Integer

          For row = 1 To maxStars
               For stars = 0 To (maxStars - row)
                    lblOutputB.Text &= "*"
               Next
              
lblOutputB.Text &= vbCrLf
          Next
     End Sub

     '-------------------------------------------------
     ' This click event starts with 10 asterisks and 0
     ' spaces and with each row it prints one less
     ' asterisk and one more leading space.
     '-------------------------------------------------
     Private Sub cmdPatternC_Click(ByVal sender As System.Object, _
                                                    ByVal e As System.EventArgs) _
                                                    Handles cmdPatternC.Click
          lblOutputC.Text = ""
         
Dim row As Integer
          Dim stars As Integer

          For row = 1 To maxStars
               lblOutputC.Text &= Space(row - 1)
               For stars = 0 To maxStars - row
                    lblOutputC.Text &= "*"
               Next
               lblOutputC.Text &= vbCrLf
          Next
     End Sub

     '-------------------------------------------------
     ' This click event starts with 9 spaces and 1
     ' asterisk and with each row it prints one less
     ' space and one more asterisk.
     '-------------------------------------------------
     Private Sub cmdPatternD_Click(ByVal sender As System.Object, _
                                                    ByVal e As System.EventArgs) _
                                                    Handles cmdPatternD.Click
          lblOutputD.Text = ""
         
Dim row As Integer
          Dim stars As Integer

          For row = 1 To maxStars
               lblOutputD.Text &= Space(maxStars - row)
               For stars = 1 To row
                    lblOutputD.Text &= "*"
               Next
               lblOutputD.Text &= vbCrLf
          Next
     End Sub

     '-------------------------------------------------
     ' This click event closes the program.
     '-------------------------------------------------
     Private Sub cmdExit_Click(ByVal sender As System.Object, _
                                            ByVal e As System.EventArgs) _
                                            Handles cmdExit.Click
          Me.Close()
     End Sub
End Class