473,406 Members | 2,352 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.

Array of Classes

Hi,

I've got an array of a class say dim mydogs(50) of dog

I create an instance of a dog mydogs(0) = new mydogs("milo")

That all works fine. However I want to search the array for a dog named
Fido. When I get to an array element that hasn't been created I get an
error. I understand why this happens, the object hasn't been created, just
declared.

Is there some way to say:

if mydogs(0)."has been created" then
if mydogs(0).name = "Fido" then found = true
end if

If there's a better way to accomplish the task I would be all happy to try it.

Thanks,
Ron

Jul 30 '05 #1
3 1216
Ron,
Is there some way to say:

if mydogs(0)."has been created" then
if mydogs(0).name = "Fido" then found = true
end if


You could simply check to see if the array object at the given index is not
null. This way, you can check to see if the object is indeed created, and
after that you can check its name.

I think the Visual Basic syntax would be something like:

If Not IsNothing(mydogs(0)) Then ...

Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Jul 30 '05 #2
sure... don't use an array. Use an arraylist instead.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Ron McCafferty" <ro***********@community.nospam> wrote in message
news:C6**********************************@microsof t.com...
Hi,

I've got an array of a class say dim mydogs(50) of dog

I create an instance of a dog mydogs(0) = new mydogs("milo")

That all works fine. However I want to search the array for a dog named
Fido. When I get to an array element that hasn't been created I get an
error. I understand why this happens, the object hasn't been created,
just
declared.

Is there some way to say:

if mydogs(0)."has been created" then
if mydogs(0).name = "Fido" then found = true
end if

If there's a better way to accomplish the task I would be all happy to try
it.

Thanks,
Ron

Jul 31 '05 #3
Jani,

Didn't work but thanks for the try.

Ron

"Jani Järvinen [MVP]" wrote:
Ron,
Is there some way to say:

if mydogs(0)."has been created" then
if mydogs(0).name = "Fido" then found = true
end if


You could simply check to see if the array object at the given index is not
null. This way, you can check to see if the object is indeed created, and
after that you can check its name.

I think the Visual Basic syntax would be something like:

If Not IsNothing(mydogs(0)) Then ...

Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

Aug 1 '05 #4

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

Similar topics

3
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
7
by: Ron | last post by:
Hello, I have 4 classes that use 4 DTS packages on 4 different tables. So I have Dim cls1 As New clsDTS1, cls2 As New clsDTS2 Dim cls3 As New clsDTS3, cls4 As New clsDTS4 Each class has a...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
1
by: Someone21 | last post by:
Hi all, I am currently trying to retrieve a string from a textfile, separate that and put it in an array. I stumbled on the problem that *token is a pointer, and not the string. However when i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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.