' Gpa2 Example ' Enter grade and credits sequentially. Output GPA. 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 btnEnter As System.Windows.Forms.Button Friend WithEvents txtGrade As System.Windows.Forms.TextBox Friend WithEvents txtGpa As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents GPA As System.Windows.Forms.Label Friend WithEvents Compute As System.Windows.Forms.Button Friend WithEvents btnReset As System.Windows.Forms.Button Friend WithEvents txtCredits As System.Windows.Forms.TextBox Private Sub InitializeComponent() Me.txtGrade = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.btnEnter = New System.Windows.Forms.Button Me.txtGpa = New System.Windows.Forms.TextBox Me.txtCredits = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.GPA = New System.Windows.Forms.Label Me.Compute = New System.Windows.Forms.Button Me.btnReset = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtGrade ' Me.txtGrade.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtGrade.Location = New System.Drawing.Point(120, 16) Me.txtGrade.Name = "txtGrade" Me.txtGrade.Size = New System.Drawing.Size(72, 29) Me.txtGrade.TabIndex = 0 Me.txtGrade.Text = "" ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(40, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(72, 24) Me.Label1.TabIndex = 1 Me.Label1.Text = "Grade" ' 'btnEnter ' Me.btnEnter.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnEnter.Location = New System.Drawing.Point(208, 16) Me.btnEnter.Name = "btnEnter" Me.btnEnter.Size = New System.Drawing.Size(248, 32) Me.btnEnter.TabIndex = 4 Me.btnEnter.Text = "Enter Grade and Credits" ' 'txtGpa ' Me.txtGpa.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtGpa.Location = New System.Drawing.Point(120, 96) Me.txtGpa.Name = "txtGpa" Me.txtGpa.ReadOnly = True Me.txtGpa.Size = New System.Drawing.Size(72, 29) Me.txtGpa.TabIndex = 2 Me.txtGpa.Text = "0" ' 'txtCredits ' Me.txtCredits.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtCredits.Location = New System.Drawing.Point(120, 56) Me.txtCredits.Name = "txtCredits" Me.txtCredits.Size = New System.Drawing.Size(72, 29) Me.txtCredits.TabIndex = 5 Me.txtCredits.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(32, 64) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(72, 24) Me.Label3.TabIndex = 6 Me.Label3.Text = "Credits" ' 'GPA ' Me.GPA.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.GPA.Location = New System.Drawing.Point(56, 104) Me.GPA.Name = "GPA" Me.GPA.Size = New System.Drawing.Size(56, 24) Me.GPA.TabIndex = 7 Me.GPA.Text = "GPA" ' 'Compute ' Me.Compute.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Compute.Location = New System.Drawing.Point(208, 56) Me.Compute.Name = "Compute" Me.Compute.Size = New System.Drawing.Size(248, 32) Me.Compute.TabIndex = 8 Me.Compute.Text = "Compute GPA" ' 'btnReset ' Me.btnReset.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnReset.Location = New System.Drawing.Point(208, 96) Me.btnReset.Name = "btnReset" Me.btnReset.Size = New System.Drawing.Size(248, 32) Me.btnReset.TabIndex = 9 Me.btnReset.Text = "Reset" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(480, 150) Me.Controls.Add(Me.btnReset) Me.Controls.Add(Me.Compute) Me.Controls.Add(Me.GPA) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.txtCredits) Me.Controls.Add(Me.btnEnter) Me.Controls.Add(Me.txtGpa) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtGrade) Me.Name = "Form1" Me.Text = "Over90 Example" Me.ResumeLayout(False) End Sub #End Region Private totalGradePoints, totalCredits As Double Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load btnReset.PerformClick() End Sub Private Sub btnEnter_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnEnter.Click Dim grade As String Dim credits As Integer grade = txtGrade.Text credits = txtCredits.Text Select Case grade Case "A" : totalGradePoints += 4 * credits Case "B" : totalGradePoints += 3 * credits Case "C" : totalGradePoints += 2 * credits Case "D" : totalGradePoints += 1 * credits End Select totalCredits += credits txtGrade.Clear() txtCredits.Clear() txtGrade.Focus() End Sub Private Sub Compute_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Compute.Click Dim gpa As Double If totalCredits > 0 Then gpa = totalGradePoints / totalCredits txtGpa.Text = gpa.ToString("0.00") Else txtGpa.Text = "NaN" ' NaN means not a number. End If End Sub Private Sub btnReset_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnReset.Click totalCredits = 0 totalGradePoints = 0 txtGrade.Clear() txtCredits.Clear() txtGpa.Clear() txtGrade.Focus() End Sub End Class