我希望用户在文本框中输入学时,从组合框中选择成绩,以根据输入的学期课程编号生成的行数。 生成行的代码在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