I'm looking for how one tests for the existance of an array. After I clear
it, and then I go to use the array, if it hasn't had anything added to it, I
receive the error
"An unhandled exception of type 'System.NullRef erenceException ' occurred in
Reports.exe
Additional information: Object reference not set to an instance of an
object."
Just to make things clear, below is a simple example of code.
Any help is much appreciated.
thanks,
Jason
------------------------------------------------------------------
Public Class frmMain
Inherits System.Windows. Forms.Form
Dim mstrItems() As String
Dim colChk As New Collection
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
colChk.Add(Chec kBox1)
colChk.Add(Chec kBox2)
colChk.Add(Chec kBox3)
colChk.Add(Chec kBox4)
End Sub
Private Sub CheckBox1_Check edChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles CheckBox1.Click , CheckBox2.Click , CheckBox3.Click ,
CheckBox4.Click
Dim intx As Integer
Dim curChk As CheckBox
TextBox1.Text = ""
Erase mstrItems
For intx = 1 To colChk.Count
curChk = colChk(intx)
If curChk.Checked Then
ReDim Preserve mstrItems(intx - 1)
mstrItems(intx - 1) = curChk.Text
End If
Next
'here is where the error occurs if nothing has been added
'to the array, how do I check if the array has been Redim'd?
For intx = 1 To mstrItems.Lengt h
TextBox1.Text += mstrItems(intx - 1)
Next
End Sub
End Class
it, and then I go to use the array, if it hasn't had anything added to it, I
receive the error
"An unhandled exception of type 'System.NullRef erenceException ' occurred in
Reports.exe
Additional information: Object reference not set to an instance of an
object."
Just to make things clear, below is a simple example of code.
Any help is much appreciated.
thanks,
Jason
------------------------------------------------------------------
Public Class frmMain
Inherits System.Windows. Forms.Form
Dim mstrItems() As String
Dim colChk As New Collection
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
colChk.Add(Chec kBox1)
colChk.Add(Chec kBox2)
colChk.Add(Chec kBox3)
colChk.Add(Chec kBox4)
End Sub
Private Sub CheckBox1_Check edChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles CheckBox1.Click , CheckBox2.Click , CheckBox3.Click ,
CheckBox4.Click
Dim intx As Integer
Dim curChk As CheckBox
TextBox1.Text = ""
Erase mstrItems
For intx = 1 To colChk.Count
curChk = colChk(intx)
If curChk.Checked Then
ReDim Preserve mstrItems(intx - 1)
mstrItems(intx - 1) = curChk.Text
End If
Next
'here is where the error occurs if nothing has been added
'to the array, how do I check if the array has been Redim'd?
For intx = 1 To mstrItems.Lengt h
TextBox1.Text += mstrItems(intx - 1)
Next
End Sub
End Class
Comment