作者WhereMyLove (QQ~~~又被抓了)
看板Visual_Basic
标题[VB6 ]求救,『并未将物件参考设定为物件的执行个体』
时间Sun Jan 13 19:07:24 2008
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
1F:→ m9556:numArray <<你有宣告array的范围吗?多检查几次吧? 01/13 20:00
2F:推 fumizuki:sub中应该是redim preserve array(index) ... 01/15 06:39
3F:推 fumizuki:否则numArray就是此sub中的区域变数 01/15 06:40