473,326 Members | 2,173 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,326 software developers and data experts.

How to create array class?

Hi,

I have create a class name employee.
Next, i would like to create array for the employee class.
The code as below:
dim eply(5) as employee

when i call eply(0).name="Khrish", an error message prompt out as saying
object reference is null...

Any idea to solve it?
Please advice.
thank you in advance.

Rgrds,
GL
Jan 7 '07 #1
12 1588
try this:

dim eply(5) as employee
eply(0)=new employee
eply(0).name="Khrish"
Daniel wrote:
Hi,

I have create a class name employee.
Next, i would like to create array for the employee class.
The code as below:
dim eply(5) as employee

when i call eply(0).name="Khrish", an error message prompt out as saying
object reference is null...

Any idea to solve it?
Please advice.
thank you in advance.

Rgrds,
GL
Jan 7 '07 #2
On 2007-01-07, Daniel <Da****@discussions.microsoft.comwrote:
Hi,

I have create a class name employee.
Next, i would like to create array for the employee class.
The code as below:
dim eply(5) as employee

when i call eply(0).name="Khrish", an error message prompt out as saying
object reference is null...

Any idea to solve it?
Please advice.
thank you in advance.

Rgrds,
GL
Dim eply() As Employee { _
new Employee(), _
new Employee(), _
new Employee(), _
new Employee(), _
new Employee()}

--
Tom Shelton
Jan 7 '07 #3
Daniel,

For 2005

http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846

I hope this helps,

Cor
Jan 7 '07 #4
Hi all,

thanks for your response.
I managed to solve the "object reference to null..." error message,however,
another issue appears.

I cannot get the list of 5 different records to be updated into the class
arrays, for instance:

inputs:
eply(0).name="Krish"
eply(1).name="James"
eply(2).name="Bond"

outputs:
all display as "Bond" name which is the last record during updating.

In my class, my code as follow:
public shared sname as string

Public Shared Property name() As String
Get
Return sname
End Get
Set(ByVal Value As String)
sname = Value
End Set
End Property

Any advice, please.

thank you in advance.

Rgrds,
GL
"Cor Ligthert [MVP]" wrote:
Daniel,

For 2005

http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846

I hope this helps,

Cor
Jan 7 '07 #5
How are you displaying them?

Robin S.
========================
"Daniel" <Da****@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
Hi all,

thanks for your response.
I managed to solve the "object reference to null..." error
message,however,
another issue appears.

I cannot get the list of 5 different records to be updated into the
class
arrays, for instance:

inputs:
eply(0).name="Krish"
eply(1).name="James"
eply(2).name="Bond"

outputs:
all display as "Bond" name which is the last record during updating.

In my class, my code as follow:
public shared sname as string

Public Shared Property name() As String
Get
Return sname
End Get
Set(ByVal Value As String)
sname = Value
End Set
End Property

Any advice, please.

thank you in advance.

Rgrds,
GL
"Cor Ligthert [MVP]" wrote:
>Daniel,

For 2005

http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846

I hope this helps,

Cor

Jan 7 '07 #6
Tom Shelton showed you how to create an array of 5 with 5 elements and
initialize each element to a seperate instance of an Employee object.

It is clear, however, that you have created one instance of an Employee
object and assigned it to all 5 elements of the array. This will cause the
exact symptons you are observing.
"Daniel" <Da****@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
Hi all,

thanks for your response.
I managed to solve the "object reference to null..." error
message,however,
another issue appears.

I cannot get the list of 5 different records to be updated into the class
arrays, for instance:

inputs:
eply(0).name="Krish"
eply(1).name="James"
eply(2).name="Bond"

outputs:
all display as "Bond" name which is the last record during updating.

In my class, my code as follow:
public shared sname as string

Public Shared Property name() As String
Get
Return sname
End Get
Set(ByVal Value As String)
sname = Value
End Set
End Property

Any advice, please.

thank you in advance.

Rgrds,
GL
"Cor Ligthert [MVP]" wrote:
>Daniel,

For 2005

http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846

I hope this helps,

Cor

Jan 7 '07 #7

"Daniel" <Da****@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
: Hi all,
:
: thanks for your response.
: I managed to solve the "object reference to null..." error
message,however,
: another issue appears.
:
: I cannot get the list of 5 different records to be updated into the
class
: arrays, for instance:
:
: inputs:
: eply(0).name="Krish"
: eply(1).name="James"
: eply(2).name="Bond"
:
: outputs:
: all display as "Bond" name which is the last record during updating.
:
: In my class, my code as follow:
: public shared sname as string
:
: Public Shared Property name() As String
: Get
: Return sname
: End Get
: Set(ByVal Value As String)
: sname = Value
: End Set
: End Property
:
: Any advice, please.
:
: thank you in advance.
:
: Rgrds,
: GL
:
:
: "Cor Ligthert [MVP]" wrote:
:
: Daniel,
: >
: For 2005
: >
: >
http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846
: >
: I hope this helps,
: >
: Cor
: >
: >
: >
Jan 7 '07 #8

"Daniel" <Da****@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
: Hi all,
:
: thanks for your response.
: I managed to solve the "object reference to null..." error
: message,however, another issue appears.
:
: I cannot get the list of 5 different records to be updated into the
: class arrays, for instance:
:
: inputs:
: eply(0).name="Krish"
: eply(1).name="James"
: eply(2).name="Bond"
:
: outputs:
: all display as "Bond" name which is the last record during updating.
:
: In my class, my code as follow:
: public shared sname as string
:
: Public Shared Property name() As String
: Get
: Return sname
: End Get
: Set(ByVal Value As String)
: sname = Value
: End Set
: End Property
:
: Any advice, please.
:
: thank you in advance.
Sorry for the earlier response. I fat fingered and inadvetantly sent
the post. Oops...
Anyway, your name variable (sName) is Shared which means there is only
one copy of it. When each object's name property is being set, they
are all setting the value of the same variable. Try removing the
Shared keyword.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.

Jan 7 '07 #9
Hi all,

thanks for the help.
Finally, _AnonCoward has identified the root cause which i almost forget
:shared syntax.

Thanks for all the help given.

Rgrds,
GL

"_AnonCoward" wrote:
>
"Daniel" <Da****@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
: Hi all,
:
: thanks for your response.
: I managed to solve the "object reference to null..." error
: message,however, another issue appears.
:
: I cannot get the list of 5 different records to be updated into the
: class arrays, for instance:
:
: inputs:
: eply(0).name="Krish"
: eply(1).name="James"
: eply(2).name="Bond"
:
: outputs:
: all display as "Bond" name which is the last record during updating.
:
: In my class, my code as follow:
: public shared sname as string
:
: Public Shared Property name() As String
: Get
: Return sname
: End Get
: Set(ByVal Value As String)
: sname = Value
: End Set
: End Property
:
: Any advice, please.
:
: thank you in advance.
Sorry for the earlier response. I fat fingered and inadvetantly sent
the post. Oops...
Anyway, your name variable (sName) is Shared which means there is only
one copy of it. When each object's name property is being set, they
are all setting the value of the same variable. Try removing the
Shared keyword.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.

Jan 8 '07 #10
Daniel,

I think that you make not only me curious, what has shared/instanced to do
with the by you described problem. It is obvious that your (new made) class
has no indexer, that has nothing to do with instanced or shared?

Cor
Jan 8 '07 #11
On 2007-01-08, Cor Ligthert [MVP] <no************@planet.nlwrote:
Daniel,

I think that you make not only me curious, what has shared/instanced to do
with the by you described problem. It is obvious that your (new made) class
has no indexer, that has nothing to do with instanced or shared?

Cor
Cor,
He had the name property of his class defined as shared - so, setting it in
one instance set it for all....

--
Tom Shelton
Jan 9 '07 #12
Tom,

That he wrote, but how he did that, it can by handy

Something like this?

static x as string = "Tom"
dim y(5) as string = x

Can be very efficient but I don't know it.

Cor

"Tom Shelton" <to*********@comcastXXXXXXX.netschreef in bericht
news:1Z******************************@comcast.com. ..
On 2007-01-08, Cor Ligthert [MVP] <no************@planet.nlwrote:
>Daniel,

I think that you make not only me curious, what has shared/instanced to
do
with the by you described problem. It is obvious that your (new made)
class
has no indexer, that has nothing to do with instanced or shared?

Cor

Cor,
He had the name property of his class defined as shared - so, setting it
in
one instance set it for all....

--
Tom Shelton

Jan 9 '07 #13

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

Similar topics

6
by: billy | last post by:
I've got a set of subclasses that each derive from a common base class. What I'd like to do is create a global array of the class types (or, class names) that a manager class can walk through in...
2
by: Mriganka | last post by:
I want to create a hierarchical tree from the array of strings obtained by extracting a jar file.I want to do this using Javascript. For ex, I am having the entries in the array as...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: John Haigh | last post by:
I have the need to create an array of objects. Now this sound fairly trivial but I can't figure this out. I have one class called PostingObjectService that has a method GetPostings where the...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: Big Charles | last post by:
Hello, I would like to create an array-class to be able to call like: Dim oMyCar as New MyCar ' After initializing oMyCar, the object has to be like: oMyCar(0).Brand...
1
geo039
by: geo039 | last post by:
Okay I have an application, which is to demonstrate the use of a created class. I have a previous and next button which cycles through the array. However I need the user to be able to create a new...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.