在Form加载事件中调用数组

时间:2014-03-14 17:24:51

标签: vb.net

我有一个带有文本框的表单。如果我输入" 91"它应该给我A级等等。如果我将我的数组放入我的按钮,请点击它。但是,如果我把它放在我的表单加载事件中,它只能工作一次。我每次都要回忆一下吗?

Public Class Form1
Structure Grades
    Public intMinGrade As Integer
    Public strLetterGrade As String
End Structure
Dim graGradingScale(5) As Grades
Dim index As Integer
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click


    'For i As Integer = 0 To graGradingScale.Length - 1
    '    MessageBox.Show(graGradingScale(i).intMinGrade)
    'Next

    Dim FoundBoolean As Boolean = False
    Do Until FoundBoolean Or index > 5

        If TextBox1.Text = graGradingScale(index).intMinGrade.ToString Then

            Label1.Text = graGradingScale(index).strLetterGrade.ToString
            FoundBoolean = True
        Else
            index += 1

        End If
    Loop
End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    graGradingScale(0).intMinGrade = 91
    graGradingScale(0).strLetterGrade = "A"
    graGradingScale(1).intMinGrade = 81
    graGradingScale(1).strLetterGrade = "B"
    graGradingScale(2).intMinGrade = 71
    graGradingScale(2).strLetterGrade = "C"
    graGradingScale(3).intMinGrade = 61
    graGradingScale(3).strLetterGrade = "D"
    graGradingScale(4).intMinGrade = 0
    graGradingScale(4).strLetterGrade = "F"

End Sub

结束班

1 个答案:

答案 0 :(得分:1)

Dim index As Integer

中插入Button1_Click
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim index As Integer = 0
    'code continues

瓦尔特