首页 > 解决方案 > 未加权 GPA 计算器代码代码问题

问题描述

我希望用户在 TextBox 中输入学分,从 ComboBox 中选择等级,以获得基于输入的学期课程编号生成的行数。生成行的代码在 Form1_Load 事件中,计算 GPA 的代码在 CHECK GPA 按钮中完成。我遇到的问题是如何保存所有的学分和成绩并计算它。这是代码:

Imports System.Windows.Forms

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Me.Show()

    Dim Answer As String '= InputBox("Enter number of rows:", "Input Row ", "0")
    Dim Row As Integer '= CInt(Answer)
    Dim Height As Integer
    Dim Valid As Boolean = False

    Do While Valid = False
        Try
            Dim Repeat = True
            Do While Repeat = True
                Answer = InputBox("Please Enter Number Of Semester Courses:", "GPA CHECKER", "0")
                Row = CInt(Answer)
                If Row > 0 And Row <= 13 Then
                    Repeat = False
                Else
                    Repeat = True
                End If
            Loop

            Valid = True
        Catch ex As InvalidCastException
            MsgBox("You Can Only Input Numbers!", MsgBoxStyle.Information)
            Valid = False
        End Try
    Loop

    For index As Integer = 1 To Row

        Dim myPanel As New Panel
        Dim myLabel As New Label
        Dim myTextBox As New TextBox
        Dim myComboBox As New ComboBox

        myPanel.Name = "myPanel" + index.ToString
        myPanel.Location = New Point(12, 70 + Height)
        myPanel.Size = New Size(260, 34)

        myLabel.Text = "Course" + index.ToString
        myLabel.Size = New Size(80, 22)
        myLabel.TextAlign = ContentAlignment.MiddleLeft
        myLabel.Location = New Point(45, 12)

        myTextBox.Name = "CreditHours"
        myTextBox.Size = New Size(50, 22)
        myTextBox.Location = New Size(125, 12)

        myComboBox.Name = "Grade"
        myComboBox.Size = New Size(50, 22)
        myComboBox.Location = New Size(210, 12)
        myComboBox.Items.Add("A+")
        myComboBox.Items.Add("A")
        myComboBox.Items.Add("B+")
        myComboBox.Items.Add("B")
        myComboBox.Items.Add("C+")
        myComboBox.Items.Add("C")
        myComboBox.Items.Add("D+")
        myComboBox.Items.Add("D")
        myComboBox.Items.Add("F")

        myPanel.Controls.Add(myLabel)
        myPanel.Controls.Add(myTextBox)
        myPanel.Controls.Add(myComboBox)

        Me.Controls.Add(myPanel)

        Height += 34

        Me.Show()

    Next

End Sub

Private Sub btnCheckGpa_Click(sender As Object, e As EventArgs) Handles btnCheckGpa.Click


    Form2.Show()
    Me.Hide()

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

End Class

标签: vb.net

解决方案


推荐阅读