定义数组全局变量出现"未将对象引用设置到对象的实例"
定义数组全局变量
代码如下:
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
'窗体代码
....
Dim id() As Integer '因大小不确定而不定义数组大小
Sub list()
Try
Dim cn As New OleDbConnection(".....")
cn.Open()
Dim cmd As New OleDbCommand("select id,name from code", cn)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
Dim int As Integer = reader.FieldCount
Dim i As Integer = 0
Do While reader.Read
Me.ListBox.Items.Add(reader.GetValue(1))
Me.id(i) = CType(reader.GetValue(0), Integer)
i = i + 1
Loop
'其他代码
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
End Class
当调用list()出现"未将对象引用设置到对象的实例"
目前解决办法是定义Dim id() As Integer 为Dim id(10000) As Integer
请给出解决办法