473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for an instance of an array?

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
Nov 21 '05 #1
2 1432
JIPS,

If Not mstrItems Is Nothing Then
For intx = 0 To mstrItems.Lengt h - 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.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

Nov 21 '05 #2
Kerry,

Works great, thanks a lot! I'm just learning, so thank you for taking the
time to answer.

Jason

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:27******** *************** ***********@mic rosoft.com...
JIPS,

If Not mstrItems Is Nothing Then
For intx = 0 To mstrItems.Lengt h - 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.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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
17272
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 prohibit a user to log in twice. A was thinking about setting some flag in the db, but in that case i need some timeout in case a pc can crash for instance so the user does
37
2821
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 use the instance of this base class (or its children class). How can I ensure the instance IS-A base class instance, since Python is a fully dynamic typing language? I searched and found several different ways to do this:
18
2468
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 for ( j =0; j<MAX ; j++) { for ( i =0; i<MAX ; i++)
6
22507
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 instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
8
3363
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 process this .txt file. Goal: I am working on a vba script to:
2
1157
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 data stored in arrays A, B, …G. Populate subs fill a datagrid on instances of form2 with the elements of the arrays (one form2 instance per array) so that the user can see what is in the arrays. The caption of the form2 instances displays what...
7
7084
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 a.length 1 then
4
8269
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 problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
17
2082
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 and bar is a function using A is an argument returning something else class A;
0
8198
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5549
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
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 we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.