473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

A little help with an array & 'NullReferenceException was unhandled' ??

Hi all. When i run the code below i get a 'NullReferenceException was
unhandled' error. I am using VB 2005 Express.

I'm confused about this because, I have declared my array and i'm
trying to put things in it, so shouldn't it BE NULL until i start to
put things in it? I'm kind of new to this so hoepfully i'm just
overlooking something easy. I know my code is actually talking to the
DB (or dataset rather) because the messageboxes work. if i pull out
the buggy line, it will messagebox every login id in the table. Any
help that anybody can offer is greatly appreciated:
Module DynamicACSAuto
Public ArrLoginIDs() As Integer 'arra. holds phone logins. used
by createTBL()
__________________________________________________ _________________________

Sub GetLoginIDs()
'this procedure makes the program query the empdata table in
the empdb. it is used to put
'the login ID of each agent into an array, which will then be
iterated through to create
'the dynamic TBL reports in the CreateTBL routine
Dim RowCount As Integer 'holds number of records in the dataset
Dim Count As Integer
RowCount = Form1.EmpDBDataSet.Tables("Empdata").Rows.Count
Count = 1

Do Until Count = RowCount

MsgBox(Form1.EmpDBDataSet.Tables("empdata").Rows(C ount).Item("phonelogin"))
'CODE BUGS AT NEXT LINE. ##########################
ArrLoginIDs(Count - 1) =
Form1.EmpDBDataSet.Tables("empdata").Rows
'BUGGY LINE ABOVE ################################
(Count).Item("phonelogin")
Count = Count + 1
Loop
MsgBox(ArrLoginIDs)
MsgBox(Count)

End Sub

Aug 17 '06 #1
5 6584

ducky801 wrote:
Hi all. When i run the code below i get a 'NullReferenceException was
unhandled' error. I am using VB 2005 Express.

I'm confused about this because, I have declared my array and i'm
trying to put things in it, so shouldn't it BE NULL until i start to
put things in it? I'm kind of new to this so hoepfully i'm just
overlooking something easy. I know my code is actually talking to the
DB (or dataset rather) because the messageboxes work. if i pull out
the buggy line, it will messagebox every login id in the table. Any
help that anybody can offer is greatly appreciated:
Module DynamicACSAuto
Public ArrLoginIDs() As Integer 'arra. holds phone logins. used
by createTBL()
__________________________________________________ _________________________

Sub GetLoginIDs()
'this procedure makes the program query the empdata table in
the empdb. it is used to put
'the login ID of each agent into an array, which will then be
iterated through to create
'the dynamic TBL reports in the CreateTBL routine
Dim RowCount As Integer 'holds number of records in the dataset
Dim Count As Integer
RowCount = Form1.EmpDBDataSet.Tables("Empdata").Rows.Count
Count = 1

Do Until Count = RowCount

MsgBox(Form1.EmpDBDataSet.Tables("empdata").Rows(C ount).Item("phonelogin"))
'CODE BUGS AT NEXT LINE. ##########################
ArrLoginIDs(Count - 1) =
Form1.EmpDBDataSet.Tables("empdata").Rows
'BUGGY LINE ABOVE ################################
(Count).Item("phonelogin")
Count = Count + 1
Loop
MsgBox(ArrLoginIDs)
MsgBox(Count)

End Sub
Something got trimmed in the post above. the buggy line reads:
(without wrapping)

ArrLoginIDs(Count - 1) =
Form1.EmpDBDataSet.Tables("empdata").Rows(Count).I tem("phonelogin")

Please help if possible

Aug 17 '06 #2
ducky801,

Before you can use the array you need to redimension it to contain the
appropriate number of elements. Before the Do Until loop:

ReDim ArrLoginIDs(RowCount - 1)

Kerry Moorman
"ducky801" wrote:
>
ducky801 wrote:
Hi all. When i run the code below i get a 'NullReferenceException was
unhandled' error. I am using VB 2005 Express.

I'm confused about this because, I have declared my array and i'm
trying to put things in it, so shouldn't it BE NULL until i start to
put things in it? I'm kind of new to this so hoepfully i'm just
overlooking something easy. I know my code is actually talking to the
DB (or dataset rather) because the messageboxes work. if i pull out
the buggy line, it will messagebox every login id in the table. Any
help that anybody can offer is greatly appreciated:
Module DynamicACSAuto
Public ArrLoginIDs() As Integer 'arra. holds phone logins. used
by createTBL()
__________________________________________________ _________________________

Sub GetLoginIDs()
'this procedure makes the program query the empdata table in
the empdb. it is used to put
'the login ID of each agent into an array, which will then be
iterated through to create
'the dynamic TBL reports in the CreateTBL routine
Dim RowCount As Integer 'holds number of records in the dataset
Dim Count As Integer
RowCount = Form1.EmpDBDataSet.Tables("Empdata").Rows.Count
Count = 1

Do Until Count = RowCount

MsgBox(Form1.EmpDBDataSet.Tables("empdata").Rows(C ount).Item("phonelogin"))
'CODE BUGS AT NEXT LINE. ##########################
ArrLoginIDs(Count - 1) =
Form1.EmpDBDataSet.Tables("empdata").Rows
'BUGGY LINE ABOVE ################################
(Count).Item("phonelogin")
Count = Count + 1
Loop
MsgBox(ArrLoginIDs)
MsgBox(Count)

End Sub

Something got trimmed in the post above. the buggy line reads:
(without wrapping)

ArrLoginIDs(Count - 1) =
Form1.EmpDBDataSet.Tables("empdata").Rows(Count).I tem("phonelogin")

Please help if possible

Aug 17 '06 #3

Kerry Moorman wrote:
ducky801,

Before you can use the array you need to redimension it to contain the
appropriate number of elements. Before the Do Until loop:

ReDim ArrLoginIDs(RowCount - 1)

Kerry Moorman

Worked like a charm! Thanks so much for the help!

AR

Aug 17 '06 #4
ducky801 wrote:
Hi all. When i run the code below i get a 'NullReferenceException was
unhandled' error. I am using VB 2005 Express.

I'm confused about this because, I have declared my array and i'm
trying to put things in it, so shouldn't it BE NULL until i start to
put things in it? I'm kind of new to this so hoepfully i'm just
overlooking something easy. I know my code is actually talking to the
DB (or dataset rather) because the messageboxes work. if i pull out
the buggy line, it will messagebox every login id in the table. Any
help that anybody can offer is greatly appreciated:
Module DynamicACSAuto
Public ArrLoginIDs() As Integer 'arra. holds phone logins. used
by createTBL()
Your confusion arises because arrays are not simple value types, but you
think they are :)

For simple value types such as Integer, when we say:

Dim a As Integer

we are saying 'create space for an Integer, and label this space 'a''.
Forever after, that space will be labeled a, and a will mean that space.

Howeer, for reference types - objects - of which arrays are an example,
when we say:

Dim a() As Integer

we are saying 'a is going to be used to *refer to* an array of
Integers'. We aren't actually creating such an array - just saying that
that is what a is going to be used for.

If we want to actually *create* an array for a to point to, we need to
say so:

a = New Integer(50) {}

This creates a new array of Integers and sets a to refer to it. If we
know what array we want at the time we declare a, we can make the
assignment at the same time:

Dim a() As Integer = New Integer(50) {}

or use the abbreviated syntax

Dim b(50) As Integer

However, I personally don't use the latter syntax, because it makes b
look like a value type. I also prefer to use the newer syntax for array
types, because it emphasizes that the 'array-ness' belongs to the type,
not the variable:

Dim a As Integer()

rather than

Dim a() As Integer
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 18 '06 #5
Larry Lard wrote:
However, I personally don't use the latter syntax, because it makes b
look like a value type. I also prefer to use the newer syntax for array
types, because it emphasizes that the 'array-ness' belongs to the type,
not the variable:

Dim a As Integer()

rather than

Dim a() As Integer
Another reason to use the first syntax above, is because that is the
way it is used when declaring functions and subs:

Public Sub PassIntArray(ints As Integer())
End Sub

Public Function ReturnIntArray() As Integer()
End Function

Aug 18 '06 #6

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

Similar topics

7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
10
by: yop | last post by:
All When I try to get the text from my listbox I am get an error which is listed below. Any ideas? Thanks Object reference not set to an instance of an object.
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
2
by: JIPS | last post by:
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...
0
by: statlerw | last post by:
I have successfully implemented drag and drop in my application to allow the reordering of columns by dragging and dropping them in the same datagridvire (Net 2.0). If i take it relatively...
3
by: Jacob.Bruxer | last post by:
Hi, I want to be able to append text using a For loop to each textbox in an array of textboxes that I've created, called tBoxes(). Basically I want to add a number of spaces to each textbox in...
3
by: raylopez99 | last post by:
Hi all, I'm getting a runtime error for the below program, though it compiles fine. The culprit seems to be the managed array--it doesn't exist. What am I doing wrong? RL //...
3
by: raylopez99 | last post by:
Below is my problem. I've narrowed it down to one thing: my unfamiliarity on how class instances are instantiated in an array. This is because the "un-array" / "non-array" version of the program...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.