473,396 Members | 2,057 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,396 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 1215
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.