[VB6 ]求救,『並未將物件參考設定為物件的執行個體』
Public Class Form1
Dim index As Integer = 0
Dim numOfElement As Integer = 0
Dim numArray() As Integer
Dim sum As Integer = 0
Dim average As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If numOfElement = 0 Then
numOfElement = CInt(TextBox1.Text)
TextBox1.Text = ""
Label2.Text = ""
If numOfElement > 0 Then
Dim numArray(numOfElement) As Integer
End If
Else
If index < numOfElement Then
numArray(index) = CInt(TextBox1.Text)
TextBox1.Text = ""
index = index + 1
End If
End If
Label1.Text = "輸入第" & CStr(index + 1) & "個數字"
If index = numOfElement Then
For index As Integer = 0 To numOfElement - 1
sum = sum + numArray(index)
Next
average = sum / numOfElement
Label2.Text = CStr(numOfElement) & "個數字的平均值是" &
CStr(average)
Label1.Text = "輸入數字個數"
numOfElement = 0
index = 0
sum = 0
End If
TextBox1.Focus()
End Sub
End Class
--
可以執行~可是執行到紅色那裡就卡死
出現:第一個可能發生的例外狀況類型 'System.NullReferenceException' 發生於
WindowsApplication1.exe
然後我看了說明
他說要我加new
不過加了編譯後就告訴我陣列不能這樣搞
那....問題在哪裡?
--
▁▃▂▁ ‥ . ◢ 玄月 ▲ 王朝 ◣▌ 威 ◣◣◢◢◢
◥﹒◢ 御林軍團 威武校衛 ▏ ▏ ▌ ▕▌ 武 ◥█◤◥◣
◢ █ 哪裡我的愛 ▏ ▏ ▲◢◥◣▲ ▕▌ 校 ◥威◤▃ ◣
◥ █▍▔▔▔▔▔▔▔▔▔. ▏◢█ ██◣▕▌ 衛 ▕ ;▌▎◤
◢ ◥▊ ▃▂▁ ‧. ▏◥◥◥◢◤◤◤▕▌ ▋ ◣◥ ◤ ◤◢
▆▄▆ FCK-MOON ’ ◥ ◢▲◣ ◤▌ ◢◥◢◢ ◤ ◣
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.130.198.4
→
01/13 20:00, , 1F
01/13 20:00, 1F
推
01/15 06:39, , 2F
01/15 06:39, 2F
推
01/15 06:40, , 3F
01/15 06:40, 3F