2014-02-16 23 views
0

我正在使用Visual Studio,並遇到一個問題,我似乎無法找到任何解決方案。在與我的程序加載相關的私有子文件中,我必須重新命名兩個不同的數組,以便爲​​這兩個二維數組中的第五個點添加新值。不幸的是,這似乎是我的程序無緣無故地跳過了最後一個數組代碼。例如,該代碼僅REDIM的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 

與此不同代碼REDIM 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 

結束子 我使用一步一步的調試和它簡單地跳過最後一部分,所以我很困惑。哦,對了,這些都是我的變量

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 
+0

您是否嘗試過使用斷點? – davidsbro

+1

調試的重點是您可以檢查您的工作。試一試。 – OneFineDay

+0

是的,我用它,它在第二個redim數組上添加斷點時根本沒有停止過。 – Bubblesphere

回答

0

從MSDN:

與保留調整大小。如果您使用保留,您可以調整只調整數組的最後一個維。對於其他維度,您必須指定現有數組的邊界。 例如,如果數組只有一個維度,則可以調整該維度的大小並仍保留該數組的所有內容,因爲您要更改最後一維。但是,如果您的陣列具有兩個或更多維度,則只有在使用保留時,才能更改最後維度的大小。

瓦爾特

+0

不,這不是真正的問題,因爲我正在調整最後一個維度。 'ReDim保存tbNoteIniGr2(tbNoteIniGr2.GetLength(0) - 1,tbNoteIniGr2.GetLength(1))'這相當於'ReDim保留tbNoteIniGr2(5,5)'我可以上傳我的視覺工作室項目,如果你想 – Bubblesphere

+0

@ user2973533更改在兩個for循環中'tbNoteIniGr1.GetLength(0)和tbNoteIniGr2.GetLength(0)'到'tbNoteIniGr1.GetLength(0) - 1和tbNoteIniGr2.GetLength(0) - 1'。現在它的工作原理 –

+0

是的,這是做的伎倆,謝謝 – Bubblesphere