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.NullReferenceException' 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
colChk.Add(CheckBox1)
colChk.Add(CheckBox2)
colChk.Add(CheckBox3)
colChk.Add(CheckBox4)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) 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.Length
TextBox1.Text += mstrItems(intx - 1)
Next
End Sub
End Class 2 1427
JIPS,
If Not mstrItems Is Nothing Then
For intx = 0 To mstrItems.Length - 1
TextBox1.Text += mstrItems(intx - 1)
Next
End If
Kerry Moorman
"JIPS" wrote: 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.NullReferenceException' 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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
colChk.Add(CheckBox1) colChk.Add(CheckBox2) colChk.Add(CheckBox3) colChk.Add(CheckBox4)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) 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.Length TextBox1.Text += mstrItems(intx - 1)
Next
End Sub End Class
Kerry,
Works great, thanks a lot! I'm just learning, so thank you for taking the
time to answer.
Jason
"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:27**********************************@microsof t.com... JIPS,
If Not mstrItems Is Nothing Then For intx = 0 To mstrItems.Length - 1 TextBox1.Text += mstrItems(intx - 1) Next End If
Kerry Moorman
"JIPS" wrote:
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.NullReferenceException' 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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
colChk.Add(CheckBox1) colChk.Add(CheckBox2) colChk.Add(CheckBox3) colChk.Add(CheckBox4)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) 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.Length TextBox1.Text += mstrItems(intx - 1)
Next
End Sub End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: fr? |
last post by:
Hi,
i have a website , on wich users have to log in
credentials are checked against mysql db
some session vars are set during login for use somewhere else in the
code.
Is there a way to...
|
by: Mike Meng |
last post by:
hi all,
I'm a newbie Python programmer with a C++ brain inside. I have a
lightweight framework in which I design a base class and expect user to
extend. In other part of the framework, I heavily...
|
by: Dan |
last post by:
hello,
I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
...
|
by: Martin |
last post by:
I'd like to be able to get the name of an object instance from within
a call to a method of that same object. Is this at all possible?
The example below works by passing in the name of the object...
|
by: mytfein |
last post by:
Hi Everyone,
Background:
Another department intends to ftp a .txt file from the mainframe, for me
to process.
The objective is to write a vb script that would be scheduled to run
daily to...
| |
by: mark |
last post by:
I put this question on a new thread because, in spirit, it is a new question.
I apologize that I have difficulty formulating the proper question.
My application performs matrix computations on...
|
by: yhlove |
last post by:
Hi
I declared an array as follows:
dim a as integer()
somewhere else in my program I have the following command:
redim preserve a(size)
I want to check the array length like that
if...
|
by: sirjohnofthewest |
last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man.
Hi guys, I frequently visit this site to get answers to my...
|
by: Klaas Vantournhout |
last post by:
Hi all,
I was wondering if it is possible if you can check in a function if one
of the arguments is temporary.
What I mean is the following. A is a class, foo is a function returning
a class...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |