473,387 Members | 3,750 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,387 software developers and data experts.

Can't get my array to work

I have Web Service that I am accessing that has as part of it's definition a
couple of objects (employees and employee). Employees has 4 properties -
one being an array of "employee" objects.

********************************************
Public Class Employees
Public AuthGUID As String
Public TransactionID As String
Public NoofEmployees As Integer

Public ArrEmployee() As Employee

End Class

Public Class Employee
Public ExternalGUID As String
Public Action As String
Public EmployeeID As String
Public SupervisorName As String
Public CardNumber As String
End Class
************************************************** **********

I have set in my code:

Dim FTSEmployees As Employees = New Employees
Dim FTSEmployee As Employee = New Employee

I can do:
FTSEmployee.ArrEmployee(0).CardNumber = "1234"

and I can do:
FTSEmployee.EmployeeID = newHire.EmployeeNumber
FTSEmployee.SupervisorName = newHire.Officer
FTSEmployee.CardNumber = "1234 "

But I can't do:
FTSEmployees.ArrEmployee(0) = FTSEmployee

I get the error:
System.NullReferenceException: Object reference not set to an instance of an
object.

Line 130: FTSEmployees.ArrEmployee(0) = FTSEmployee

What is cause this? Obviously FTSEmployee.ArrEmployee(0) is an object as I
can do the above line and FTSEmployee is an employee as I am setting all the
properties before I do this line.

What is the error for?

Thanks,

Tom

Jan 25 '07 #1
2 994
jvb
I can do:
FTSEmployee.ArrEmployee(0).CardNumber = "1234"
You should not be able to so this since ArrEmployee is not a member of
class Employee.
and I can do:
FTSEmployee.EmployeeID = newHire.EmployeeNumber
FTSEmployee.SupervisorName = newHire.Officer
FTSEmployee.CardNumber = "1234 "
You can do this because you are setting the properties of an instance
of the Employee class which you have already created.
But I can't do:
FTSEmployees.ArrEmployee(0) = FTSEmployee
You cannot do this because you have not initialized the ArrEmployee.
You may want to try to implement IList and ICollection, it contains
methods and properties used commonly in collections. If you want to
keep it simple, add an employee to the array using an Add method (in
which you ReDim Preserve the array to the new length) and / or declare
ArrEmployee as an ArrayList variable and use the methods on the
ArrayList class

Hope this helps!

On Jan 25, 11:43 am, "tshad" <t...@home.comwrote:
I have Web Service that I am accessing that has as part of it's definition a
couple of objects (employees and employee). Employees has 4 properties -
one being an array of "employee" objects.

********************************************
Public Class Employees
Public AuthGUID As String
Public TransactionID As String
Public NoofEmployees As Integer

Public ArrEmployee() As Employee

End Class

Public Class Employee
Public ExternalGUID As String
Public Action As String
Public EmployeeID As String
Public SupervisorName As String
Public CardNumber As String
End Class
************************************************** **********

I have set in my code:

Dim FTSEmployees As Employees = New Employees
Dim FTSEmployee As Employee = New Employee

I can do:
FTSEmployee.ArrEmployee(0).CardNumber = "1234"

and I can do:
FTSEmployee.EmployeeID = newHire.EmployeeNumber
FTSEmployee.SupervisorName = newHire.Officer
FTSEmployee.CardNumber = "1234 "

But I can't do:
FTSEmployees.ArrEmployee(0) = FTSEmployee

I get the error:
System.NullReferenceException: Object reference not set to an instance of an
object.

Line 130: FTSEmployees.ArrEmployee(0) = FTSEmployee

What is cause this? Obviously FTSEmployee.ArrEmployee(0) is an object as I
can do the above line and FTSEmployee is an employee as I am setting all the
properties before I do this line.

What is the error for?

Thanks,

Tom
Jan 25 '07 #2
"tshad" <t@home.comschrieb
I have Web Service that I am accessing that has as part of it's
definition a couple of objects (employees and employee). Employees
has 4 properties - one being an array of "employee" objects.

********************************************
Public Class Employees
Public AuthGUID As String
Public TransactionID As String
Public NoofEmployees As Integer

Public ArrEmployee() As Employee

End Class

Public Class Employee
Public ExternalGUID As String
Public Action As String
Public EmployeeID As String
Public SupervisorName As String
Public CardNumber As String
End Class
************************************************** **********

I have set in my code:

Dim FTSEmployees As Employees = New Employees
Dim FTSEmployee As Employee = New Employee

I can do:
FTSEmployee.ArrEmployee(0).CardNumber = "1234"
Doesn't the line above start with FTSEmployees, not FTSEmployee?

I don't think it can work.
and I can do:
FTSEmployee.EmployeeID = newHire.EmployeeNumber
FTSEmployee.SupervisorName = newHire.Officer
FTSEmployee.CardNumber = "1234 "

But I can't do:
FTSEmployees.ArrEmployee(0) = FTSEmployee

I get the error:
System.NullReferenceException: Object reference not set to an
instance of an object.

Line 130: FTSEmployees.ArrEmployee(0) = FTSEmployee

What is cause this?

Obviously FTSEmployee.ArrEmployee(0) is an
object as I can do the above line and FTSEmployee is an employee as
I am setting all the properties before I do this line.

What is the error for?

You didn't create an array to store the employees:

Redim FTSEmployees.ArrEmployee(4)
Armin
Jan 25 '07 #3

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

Similar topics

4
by: LRW | last post by:
I'm not even sure this is possible, and if it is, I'm having a hard time focusing on a function that would make it work. What I have is a dynamically generated form with dozens of rows from a...
4
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
14
by: Randell D. | last post by:
Folks, Here's my problem: I am createing an array in a file using the reslut of some PHP and MySQL processing. An example of my array would be examlpe="example one"; examlpe="example...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
18
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
20
by: subramanian | last post by:
Hello I have a doubt in the following piece of code: int a; printf("a=%p\n", a); printf("&a=%p\n", &a); these printf statements print the same value for both 'a' and '&a". I tried in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.