在線路`如果aryTemp(1)< aryTemp2(1)然後,將VB.Net的NullReferenceException
指數是 陣列的邊界之外。
出現錯誤。無法弄清楚它爲什麼會超出數組的界限。 基本上試圖比較姓氏排序記錄並將em放回到列表框中。
Private Sub btnAscending_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAscending.Click
'load all students into array
Dim arySort(numberOfRecords) As String
Dim aryTemp(6) As String
Dim aryTemp2(6) As String
For i = 0 To numberOfRecords - 1
arySort(i) = lstListBox.Items(i)
Next
Dim temp As String 'holds temporary record
Dim k As Integer
For i = 0 To arySort.Length - 2
aryTemp = Split(arySort(i), " ")
For k = i + 1 To arySort.Length - 1
aryTemp2 = Split(arySort(k), " ")
If aryTemp(1) < aryTemp2(1) Then
temp = arySort(k)
arySort(k) = arySort(i)
arySort(i) = temp
End If
Next
Next
lstListBox.Items.Clear()
numberOfRecords = 0
isLoaded = False
For i = 0 To arySort.Length - 1
lstListBox.Items.Add(arySort(i))
numberOfRecords += 1
Next
currentRecord = 0
isLoaded = True
End Sub
你的代碼在哪裏拋出更精確? – 2010-11-29 23:45:18
既然你什麼時候可以在沒有`New`關鍵字的情況下在VB.NET中分配一個數組呢?是不是正確的語法Dim aryTemp as New String(6)`,還是我在這裏丟失了什麼? – ja72 2010-11-29 23:55:21