加载程序时代码会跳过

时间:2014-02-16 02:53:28

标签: arrays vb.net visual-studio-2010

我正在使用Visual Studio,而我遇到的问题似乎无法找到任何解决方案。在与加载我的程序相关联的私有子中,我必须重新设置两个不同的数组,以便为​​这两个2d数组中的第五个点添加一个新值。可悲的是,似乎我的程序没有任何理由跳过最后一个数组代码。例如,此代码仅重新编写tbNoteIniGr2并跳过tbNoteIniGr1:

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Width = 380


    ReDim Preserve tbNoteIniGr2(tbNoteIniGr2.GetLength(0) - 1, tbNoteIniGr2.GetLength(1))
    For i = 0 To tbNoteIniGr2.GetLength(0)
        inNoteExamens1 = CInt(tbNoteIniGr2(i, 1)) + CInt(tbNoteIniGr2(i, 2)) + CInt(tbNoteIniGr2(i, 4))
        If inNoteExamens1 >= 45 Then
            inNoteFinale1 = inNoteExamens1 + CInt(tbNoteIniGr2(i, 3))
        Else
            inNoteFinale1 = inNoteExamens1 + CInt(CInt(tbNoteIniGr2(i, 3)) * inNoteExamens1 / 75)
        End If
        tbNoteIniGr2(i, 5) = inNoteFinale1
    Next

    ReDim Preserve tbNoteIniGr1(tbNoteIniGr1.GetLength(0) - 1, tbNoteIniGr1.GetLength(1))
    For i = 0 To tbNoteIniGr1.GetLength(0)
        inNoteExamens = CInt(tbNoteIniGr1(i, 1)) + CInt(tbNoteIniGr1(i, 2)) + CInt(tbNoteIniGr1(i, 4))
        If inNoteExamens >= 45 Then
            inNoteFinale = inNoteExamens + CInt(tbNoteIniGr1(i, 3))
        Else
            inNoteFinale = inNoteExamens + CInt(CInt(tbNoteIniGr1(i, 3)) * inNoteExamens / 75)
        End If
        tbNoteIniGr1(i, 5) = inNoteFinale
    Next
End Sub

与此代码重写tbNoteIniGr1并跳过tbNoteIniGr2

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Width = 380

ReDim Preserve tbNoteIniGr1(tbNoteIniGr1.GetLength(0) - 1, tbNoteIniGr1.GetLength(1))
For i = 0 To tbNoteIniGr1.GetLength(0)
    inNoteExamens = CInt(tbNoteIniGr1(i, 1)) + CInt(tbNoteIniGr1(i, 2)) + CInt(tbNoteIniGr1(i, 4))
    If inNoteExamens >= 45 Then
        inNoteFinale = inNoteExamens + CInt(tbNoteIniGr1(i, 3))
    Else
        inNoteFinale = inNoteExamens + CInt(CInt(tbNoteIniGr1(i, 3)) * inNoteExamens / 75)
    End If
    tbNoteIniGr1(i, 5) = inNoteFinale
Next

ReDim Preserve tbNoteIniGr2(tbNoteIniGr2.GetLength(0) - 1, tbNoteIniGr2.GetLength(1))
For i = 0 To tbNoteIniGr2.GetLength(0)
    inNoteExamens1 = CInt(tbNoteIniGr2(i, 1)) + CInt(tbNoteIniGr2(i, 2)) + CInt(tbNoteIniGr2(i, 4))
    If inNoteExamens1 >= 45 Then
        inNoteFinale1 = inNoteExamens1 + CInt(tbNoteIniGr2(i, 3))
    Else
        inNoteFinale1 = inNoteExamens1 + CInt(CInt(tbNoteIniGr2(i, 3)) * inNoteExamens1 / 75)
    End If
    tbNoteIniGr2(i, 5) = inNoteFinale1
Next

End Sub 我使用逐步调试,它只是跳过最后一部分,所以我很困惑。哦顺便说一下,这些是我的变量

Dim tbNoteIniGr1(,) As String = {{"Jean Narrace", "16", "8", "13", "10"}, {"Chu Paspire", "20", "20", "23", "24"}, {"Yésuis Parfait", "25", "25", "25", "25"},
                                 {"Moyende Moyenner", "20", "18", "20", "12"}, {"Ia Rienla", "19", "24", "21", "22"}, {"Chue Troisième", "21", "22", "24", "24"},
                                 {"Pépé Lacasse", "21", "21", "21", "11"}, {"Jvatu Couler", "19", "18", "14", "10"}, {"Ungars Sessaye", "0", "0", "0", "25"},
                                 {"Mpassetu Tonlab", "10", "10", "25", "10"}, {"Cava Mieux", "10", "15", "20", "25"}, {"Quéyé Suisbonnw", "24", "24", "24", "24"},
                                 {"Sexy Body", "24", "6", "15", "24"}, {"Yvon Meravoir", "12", "11", "18", "15"}, {"Jeannez Assez", "25", "15", "5", "0"},
                                 {"Téreize Constance", "13", "13", "13", "13"}, {"Déhaut Etdébas", "20", "5", "25", "9"}, {"Jpasse Saligne", "13", "17", "14", "16"},
                                 {"Passez Moidonc", "18", "17", "13", "10"}}
Dim tbNoteIniGr2(,) As String = {{"Lucienne Vienne", "16", "24", "19", "21"}, {"Adolf Kirpoupov", "20", "20", "23", "24"}, {"Miville St-Roche", "20", "18", "20", "12"},
                                 {"Gastonne Rochon", "19", "24", "21", "22"}, {"Luc Delaqueduc", "24", "16", "15", "24"}, {"Raphael Angelie", "21", "18", "15", "20"}}
Dim inNoteExamens, inNoteFinale, inEchec, inNoteExamens1, inNoteFinale1, inNombreEtudiant, inTotal As Integer
Dim stChaine As String

编辑:这是完整的代码

Public Class frmMain
    Dim tbNoteIniGr1(,) As String = {{"Jean Narrace", "16", "8", "13", "10"}, {"Chu Paspire", "20", "20", "23", "24"}, {"Yésuis Parfait", "25", "25", "25", "25"},
                                     {"Moyende Moyenner", "20", "18", "20", "12"}, {"Ia Rienla", "19", "24", "21", "22"}, {"Chue Troisième", "21", "22", "24", "24"},
                                     {"Pépé Lacasse", "21", "21", "21", "11"}, {"Jvatu Couler", "19", "18", "14", "10"}, {"Ungars Sessaye", "0", "0", "0", "25"},
                                     {"Mpassetu Tonlab", "10", "10", "25", "10"}, {"Cava Mieux", "10", "15", "20", "25"}, {"Quéyé Suisbonnw", "24", "24", "24", "24"},
                                     {"Sexy Body", "24", "6", "15", "24"}, {"Yvon Meravoir", "12", "11", "18", "15"}, {"Jeannez Assez", "25", "15", "5", "0"},
                                     {"Téreize Constance", "13", "13", "13", "13"}, {"Déhaut Etdébas", "20", "5", "25", "9"}, {"Jpasse Saligne", "13", "17", "14", "16"},
                                     {"Passez Moidonc", "18", "17", "13", "10"}}
    Dim tbNoteIniGr2(,) As String = {{"Lucienne Vienne", "16", "24", "19", "21"}, {"Adolf Kirpoupov", "20", "20", "23", "24"}, {"Miville St-Roche", "20", "18", "20", "12"},
                                     {"Gastonne Rochon", "19", "24", "21", "22"}, {"Luc Delaqueduc", "24", "16", "15", "24"}, {"Raphael Angelie", "21", "18", "15", "20"}}
    Dim inNoteExamens, inNoteFinale, inEchec, inNoteExamens1, inNoteFinale1, inNombreEtudiant, inTotal As Integer
    Dim stChaine As String

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Width = 380

        ReDim Preserve tbNoteIniGr1(tbNoteIniGr1.GetLength(0) - 1, tbNoteIniGr1.GetLength(1))
        For i = 0 To tbNoteIniGr1.GetLength(0)
            inNoteExamens = CInt(tbNoteIniGr1(i, 1)) + CInt(tbNoteIniGr1(i, 2)) + CInt(tbNoteIniGr1(i, 4))
            If inNoteExamens >= 45 Then
                inNoteFinale = inNoteExamens + CInt(tbNoteIniGr1(i, 3))
            Else
                inNoteFinale = inNoteExamens + CInt(CInt(tbNoteIniGr1(i, 3)) * inNoteExamens / 75)
            End If
            tbNoteIniGr1(i, 5) = inNoteFinale
        Next

        ReDim Preserve tbNoteIniGr2(tbNoteIniGr2.GetLength(0) - 1, tbNoteIniGr2.GetLength(1))
        For i = 0 To tbNoteIniGr2.GetLength(0)
            inNoteExamens1 = CInt(tbNoteIniGr2(i, 1)) + CInt(tbNoteIniGr2(i, 2)) + CInt(tbNoteIniGr2(i, 4))
            If inNoteExamens1 >= 45 Then
                inNoteFinale1 = inNoteExamens1 + CInt(tbNoteIniGr2(i, 3))
            Else
                inNoteFinale1 = inNoteExamens1 + CInt(CInt(tbNoteIniGr2(i, 3)) * inNoteExamens1 / 75)
            End If
            tbNoteIniGr2(i, 5) = inNoteFinale1
        Next
    End Sub

    Private Sub btnNoteGr1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNoteGr1.Click
        rtbText.Location = New Point(98, 13)
        gbxStats.Location = New Point(466.13)

        inEchec = 0
        stChaine = ""
        stChaine = "Notes finales pour le groupe 01" & vbCrLf & "Cours 420-246" & vbCrLf & "Session Hiver 2011" &
            vbCrLf & vbCrLf & "Nom" & Space(20) & "NoteF" & vbCrLf & vbCrLf
        For i = 0 To tbNoteIniGr1.GetLength(0) - 1
            stChaine &= tbNoteIniGr1(i, 0) & Space(25 - tbNoteIniGr1(i, 0).Length) & tbNoteIniGr1(i, 5).PadLeft(3) & vbCrLf
            If tbNoteIniGr1(i, 5) < 60 Then
                inEchec += 1
            End If
        Next
        rtbText.Text = stChaine
        tbxEhcas.Text = CStr(inEchec)
    End Sub

    Private Sub btnNoteGr2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNoteGr2.Click
        rtbText.Location = New Point(98, 13)
        gbxStats.Location = New Point(466.13)

        inEchec = 0
        stChaine = ""
        stChaine = "Notes finales pour le groupe 02" & vbCrLf & "Cours 420-246" & vbCrLf & "Session Hiver 2011" &
            vbCrLf & vbCrLf & "Nom" & Space(20) & "NoteF" & vbCrLf & vbCrLf
        For i = 0 To tbNoteIniGr2.GetLength(0) - 1
            stChaine &= tbNoteIniGr2(i, 0) & Space(25 - tbNoteIniGr2(i, 0).Length) & tbNoteIniGr2(i, 4).PadLeft(3) & vbCrLf
            If tbNoteIniGr2(i, 5) < 60 Then
                inEchec += 1
            End If
        Next
        rtbText.Text = stChaine
        tbxEhcas.Text = CStr(inEchec)
    End Sub

    Private Sub btnStatGr1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStatGr1.Click
        rtbText.Location = New Point(466.13)
        gbxStats.Location = New Point(98, 13)

        inTotal = 0
        inNombreEtudiant = 0
        inEchec = 0

        For i = 0 To tbNoteIniGr1.GetLength(0) - 1
            inNombreEtudiant += 1
            inTotal += CInt(tbNoteIniGr1(i, 5))
            If tbNoteIniGr1(i, 5) < 60 Then
                inEchec += 1
            End If
        Next

        tbxGroupe.Text = "01"
        tbxMoyenne.Text = inTotal / inNombreEtudiant
        tbxNombreEchec.Text = inEchec
        tbxNombreEtudiant.Text = inNombreEtudiant
    End Sub

    Private Sub btnStatGr2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStatGr2.Click
        rtbText.Location = New Point(466.13)
        gbxStats.Location = New Point(98, 13)

        inTotal = 0
        inNombreEtudiant = 0
        inEchec = 0

        For i = 0 To tbNoteIniGr2.GetLength(0) - 1
            inNombreEtudiant += 1
            inTotal += CInt(tbNoteIniGr2(i, 5))
            If tbNoteIniGr2(i, 5) < 60 Then
                inEchec += 1
            End If
        Next

        tbxGroupe.Text = "02"
        tbxMoyenne.Text = inTotal / inNombreEtudiant
        tbxNombreEchec.Text = inEchec
        tbxNombreEtudiant.Text = inNombreEtudiant
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

来自MSDN:

使用Preserve调整大小。如果您使用保留,则可以调整数组的仅限最后一维。对于每个其他维度,您必须指定现有数组的边界。 例如,如果您的数组只有一个维度,则可以调整该维度的大小并保留数组的所有内容,因为您要更改最后一个维度。但是,如果您的数组有两个或更多维度,则可以使用保留更改最后一个维度的大小。

瓦尔特