Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents txtPasses As System.Windows.Forms.TextBox
  Friend WithEvents txtResult As System.Windows.Forms.TextBox
  Friend WithEvents Label2 As System.Windows.Forms.Label
  Friend WithEvents btnStart As System.Windows.Forms.Button
  Friend WithEvents btnExit As System.Windows.Forms.Button
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.txtPasses = New System.Windows.Forms.TextBox()
    Me.txtResult = New System.Windows.Forms.TextBox()
    Me.Label2 = New System.Windows.Forms.Label()
    Me.btnStart = New System.Windows.Forms.Button()
    Me.btnExit = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'Label1
    '
    Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label1.Location = New System.Drawing.Point(8, 16)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(112, 20)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "Number of passes: "
    Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
    '
    'txtPasses
    '
    Me.txtPasses.Location = New System.Drawing.Point(120, 16)
    Me.txtPasses.Name = "txtPasses"
    Me.txtPasses.Size = New System.Drawing.Size(88, 20)
    Me.txtPasses.TabIndex = 1
    Me.txtPasses.Text = ""
    '
    'txtResult
    '
    Me.txtResult.Location = New System.Drawing.Point(120, 48)
    Me.txtResult.Multiline = True
    Me.txtResult.Name = "txtResult"
    Me.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
    Me.txtResult.Size = New System.Drawing.Size(88, 96)
    Me.txtResult.TabIndex = 2
    Me.txtResult.Text = ""
    '
    'Label2
    '
    Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label2.Location = New System.Drawing.Point(8, 48)
    Me.Label2.Name = "Label2"
    Me.Label2.Size = New System.Drawing.Size(112, 20)
    Me.Label2.TabIndex = 3
    Me.Label2.Text = "Result: "
    Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
    '
    'btnStart
    '
    Me.btnStart.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnStart.Location = New System.Drawing.Point(8, 160)
    Me.btnStart.Name = "btnStart"
    Me.btnStart.Size = New System.Drawing.Size(80, 24)
    Me.btnStart.TabIndex = 4
    Me.btnStart.Text = "&Start"
    '
    'btnExit
    '
    Me.btnExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnExit.Location = New System.Drawing.Point(128, 160)
    Me.btnExit.Name = "btnExit"
    Me.btnExit.Size = New System.Drawing.Size(80, 24)
    Me.btnExit.TabIndex = 5
    Me.btnExit.Text = "E&xit"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(216, 189)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnExit, Me.btnStart, Me.Label2, Me.txtResult, Me.txtPasses, Me.Label1})
    Me.Name = "Form1"
    Me.Text = "Simple Loop Program"
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    Dim i As Integer, Sum As Integer, Terminate As Integer
    Dim NewLine As String

    txtResult.Text = ""
    NewLine = Chr(13) & Chr(10)
    Terminate = CInt(txtPasses.Text) ' Target iterations
    Sum = 0     ' Clear out the running total

    For i = 1 To Terminate
      Sum += i
      txtResult.Text += CStr(Sum) & "  (i = " & CStr(i) & ")" & NewLine
    Next i

  End Sub

  Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Dispose()
  End Sub
End Class
