我如何从不同的私人子公司获得价值

时间:2016-01-05 11:22:41

标签: vb.net

我是VB的新手,我收到了老师的一项任务,即创建一个CGPA计算器。 This is the form. 正如你所看到的,我正试图从“信用小时”中获取值,然后将它们相加并显示在“总时间”上。我该怎么办?这些值来自不同的私有子,因此它们不是全局可用的。有人可以向我解释我如何获得价值观?或者可能有更好/更简单的方法吗?

以下是我的代码

Public Class Form1

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid0.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid0.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid0.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid0.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname0.Text = coursename
    txtch0.Text = credithour
End Sub

Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid1.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid1.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid1.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid1.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname1.Text = coursename
    txtch1.Text = credithour
End Sub

Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles txtcname2.TextChanged

End Sub

Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles txtcname0.TextChanged

End Sub

Private Sub cbocid2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid2.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid2.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid2.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid2.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname2.Text = coursename
    txtch2.Text = credithour
End Sub

Private Sub cbocid3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid3.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid3.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid3.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid3.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname3.Text = coursename
    txtch3.Text = credithour
End Sub

Private Sub cbocid4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid4.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid4.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid4.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid4.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname4.Text = coursename
    txtch4.Text = credithour
End Sub

Private Sub cbocid5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbocid5.SelectedIndexChanged
    Dim coursename As String
    Dim credithour As Integer

    If cbocid5.SelectedIndex = 0 Then
        coursename = "Computer System & Applications"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 1 Then
        coursename = "Discrete Structures"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 2 Then
        coursename = "Program Design"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 3 Then
        coursename = "Mathematical Techniques 1"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 4 Then
        coursename = "Mathematical Techniques 2"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 5 Then
        coursename = "Database Systems"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 6 Then
        coursename = "Contemporary Management & Entrepreneurship"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 7 Then
        coursename = "English"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 8 Then
        coursename = "Business Management"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 9 Then
        coursename = "Computer Architecture"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 10 Then
        coursename = "Operating Systems"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 11 Then
        coursename = "Systems Analysis & Design"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 12 Then
        coursename = "Data Communications & Networking"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 13 Then
        coursename = "Internet & Web Publishing"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 14 Then
        coursename = "Object Oriented Programming"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 15 Then
        coursename = "Programming In Java"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 16 Then
        coursename = "Data Structure & Algorithms"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 17 Then
        coursename = "Computing Project"
        credithour = "4"
    ElseIf cbocid5.SelectedIndex = 18 Then
        coursename = "Effective Communication Skills"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 19 Then
        coursename = "E-Commerce"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 20 Then
        coursename = "Multimedia Applications"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 21 Then
        coursename = "Management Information System"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 22 Then
        coursename = "Programming For Business Applications"
        credithour = "3"
    ElseIf cbocid5.SelectedIndex = 23 Then
        coursename = "Industrial Training"
        credithour = "6"
    End If
    txtcname5.Text = coursename
    txtch5.Text = credithour
End Sub

Sub ClearAll()
    cbocid0.SelectedIndex = 24
    cbocid1.SelectedIndex = 24
    cbocid2.SelectedIndex = 24
    cbocid3.SelectedIndex = 24
    cbocid4.SelectedIndex = 24
    cbocid5.SelectedIndex = 24
End Sub

Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

End Sub

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

End Sub

Private Sub txttotalch_TextChanged(sender As Object, e As EventArgs) Handles txttotalch.TextChanged

End Sub

Private Sub btncal_Click(sender As Object, e As EventArgs) Handles btncal.Click

End Sub

Private Sub txtch0_TextChanged(sender As Object, e As EventArgs) Handles txtch0.TextChanged

End Sub

Private Sub btnclear_Click(sender As Object, e As EventArgs) Handles btnclear.Click
    ClearAll()
End Sub

结束班

2 个答案:

答案 0 :(得分:0)

首先,将变量从子类移到类下面的顶部,使它们成为全局变量。 您只有一个信用小时变量(信用),所以每次从任何组合框编辑一个值时,您只需更改一个值。为您需要的每个信用小时值设置一个变量,并为总计创建一个变量 imap_sort ($mail_conn, SORTARRIVAL, 0, SE_UID, 'FROM ' . $sender)

然后在每个程序结束时只需输入dim totalCH as integer

之类的内容

答案 1 :(得分:0)

我建议您创建一个类级别属性,它是元组的字典。其中键是索引,值是课程名称和学分时间的元组。然后你的所有函数都可以停止复制那么多代码,只需从字典中提取。您需要在构造函数中初始化字典。