Visual Basic中的动态For循环 - 我做错了什么?

时间:2016-12-18 06:08:23

标签: .net vb.net visual-studio

我正在为我的入门级视觉基础课开展最终项目。我正在尝试创建一个调用几个函数的循环,并使用函数动态设置变量'输出。我需要根据intloop当前值动态定义变量。我知道这是错误的做法,但是正确的方法是什么?

        'Counts number of courses total, for credit or not
    If Not txtGradePercentCourse1.Text = "" Then
        intCourseCount += 1
    End If
    If Not txtGradePercentCourse2.Text = "" Then
        intCourseCount += 1
    End If
    If Not txtGradePercentCourse3.Text = "" Then
        intCourseCount += 1
    End If
    If Not txtGradePercentCourse4.Text = "" Then
        intCourseCount += 1
    End If

    'Loops through all courses and calculates letter grade and quality points for each course
    For intloop = 1 To intCourseCount

        dblPercent = CDbl(txtGradePercentCourse1.Text)
            intCredits = CInt(txtCreditsCourse1.Text)
            lblLetterGradeCourse1.Text = PercentToLetterGrade(dblPercent)
            dblQualityPointsCourse4 = CalculateQualityPoints(dblPercent, intCredits)

        dblPercent = CDbl(txtGradePercentCourse2.Text)
            intCredits = CInt(txtCreditsCourse2.Text)
            lblLetterGradeCourse2.Text = PercentToLetterGrade(dblPercent)
            dblQualityPointsCourse2 = CalculateQualityPoints(dblPercent, intCredits)

        dblPercent = CDbl(txtGradePercentCourse3.Text)
            intCredits = CInt(txtCreditsCourse3.Text)
            lblLetterGradeCourse3.Text = PercentToLetterGrade(dblPercent)
            dblQualityPointsCourse3 = CalculateQualityPoints(dblPercent, intCredits)

        dblPercent = CDbl(txtGradePercentCourse4.Text)
            intCredits = CInt(txtCreditsCourse4.Text)
            lblLetterGradeCourse4.Text = PercentToLetterGrade(dblPercent)
        dblQualityPointsCourse4 = CalculateQualityPoints(dblPercent, intCredits)

    Next

0 个答案:

没有答案