473,778 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create an array-class ? Please, some help with my code

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
oMyCar(0).Wheel s.NumberOfWheel s
oMyCar(0).Wheel s.ColorOfWheels

oMyCar(1).Brand
oMyCar(1).Wheel s.NumberOfWheel s
oMyCar(1).Wheel s.ColorOfWheels

The object has to be an array list itself with properties like Brand
and sub-objects like Wheels.

I think I should create the class like this:

Public Class MyCar

Inherits CollectionBase

Public Wheels As MyWheels
Private mBrand As String

Public Sub New()

Get_Data()

End Sub
Private Function Get_Data()

' DataReader dr has been populated

If dr.HasRows Then
While dr.Read

' I am not sure how to create the array object from here
Me.Add()
mBrand = dr.Item("Brand" ).ToString()

End While

Wheels = New MyWheels(mBrand )
End If

dr.Close()
End Function

Sub Add(ByVal il As Object)
Me.List.Add(il)
End Sub

Public Property Brand() As String
Get
Return mDescripcion
End Get
Set(ByVal Value As String)
mDescripcion = Value
End Set
End Property
End Class

Feb 2 '07 #1
2 1655


I have objects/object collections ( CollectionBase ) here:

5/24/2006
Custom Objects/Collections and Tiered Development

http://sholliday.spaces.live.com/blog/
You don't want ot have a method like:
Private Function Get_Data()
which mixes objects and database access.

Car should be an object
CarCollection should be an object
Wheel should be an object
WheelCollection should be an object

Car should have Wheels as a property.

Don't mix objects and collections with database access.

Create a Manager or Controller class

CarController
public static(shared) CarCollection GetCars

//here is where you create a new CarCollection, and looop over your
datareader to put new cars into the car collection


............... .....
I have Customer(s) and Order(s) objects, and collections are the url above.



"Big Charles" <ch**********@y ahoo.comwrote in message
news:11******** *************@l 53g2000cwa.goog legroups.com...
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
oMyCar(0).Wheel s.NumberOfWheel s
oMyCar(0).Wheel s.ColorOfWheels

oMyCar(1).Brand
oMyCar(1).Wheel s.NumberOfWheel s
oMyCar(1).Wheel s.ColorOfWheels

The object has to be an array list itself with properties like Brand
and sub-objects like Wheels.

I think I should create the class like this:

Public Class MyCar

Inherits CollectionBase

Public Wheels As MyWheels
Private mBrand As String

Public Sub New()

Get_Data()

End Sub
Private Function Get_Data()

' DataReader dr has been populated

If dr.HasRows Then
While dr.Read

' I am not sure how to create the array object from here
Me.Add()
mBrand = dr.Item("Brand" ).ToString()

End While

Wheels = New MyWheels(mBrand )
End If

dr.Close()
End Function

Sub Add(ByVal il As Object)
Me.List.Add(il)
End Sub

Public Property Brand() As String
Get
Return mDescripcion
End Get
Set(ByVal Value As String)
mDescripcion = Value
End Set
End Property
End Class

Feb 2 '07 #2
On Feb 2, 9:48 pm, "Big Charles" <cherediat...@y ahoo.comwrote:
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
[snip]

I am not sure how the VB syntax is, but the C# syntax is basically
like thi:

public class MYarray
{
public object this[int idx] { return /*something*/; }
}
In addition you'd probably want to implement a couple of the
IEnumerable interfaces in addition to read up on generics to get it
strongly typed on the content...

Roughly like this:

public class MYArray<T: IEnumerable<T>
{
public T this[int idx] { return /*something*/; }
}
I haven't ran the code through a compiler, but I think you get the
point...

..t

--
http://ajaxwidgets.com
Free ASP.NET Ajax Widgets NOW!

Feb 2 '07 #3

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

Similar topics

5
1714
by: Winston | last post by:
Hello, There: I would like to create a huge two-dimentational array in C, like 5000X5000. However, I always got sementation faults when accessing more than 2000X2000. Is there any way to overcome this issue? Thanks in advance!
2
7984
by: Wendell Wilkie | last post by:
I am working with a 3rd party unmanaged dll, and I need to pass an array of char* as an argument. I can used fixed to get a single char* as follows: char buf = new char; fixed (char* p = buf) { ... } But I do not know how many of these to create until runtime. I cannot think of a way to use fixed in a loop to fix multiple pointers. Is there a way?
17
3019
by: yinglcs | last post by:
Hi, In STL, can I create a variable size but non-growable array? In Java, I can do this: int void f (int size) { int array = new int; // do something with array return array;
5
2143
by: Richard Lewis Haggard | last post by:
I am trying to create multi-dimensioned arrays in conventional ASP pages and pass these arrays as arguments to functions that are in a C# interop assembly. ASP complains because it doesn't recognize that the created array is the same as the declared interface argument. The C# function is expecting to receive a 2 dimensioned array and is declared like this: public object InteropFunc( string s1, object arValues ); What should the ASP...
0
1786
by: Steve Chaplin | last post by:
I'm trying to create an object (as a C extension) to support the buffer interface and was getting "TypeError: buffer is read-only" errors. So I had a look at the array object and it has the same problem: $ python array('c', 'abc') 'a' array('c', 'dbc') 'd' TypeError: buffer is read-only
16
2970
by: vbnewbie | last post by:
I need to create a number of arraylists at run time. The number of arraylists to be created is unknown at design time. The name of the first newly created arraylist is the first element of an array, NameArray (a Publicly declared array with an unknown number of elements at design time). The name of the second newly created arraylist is the second element of NameArray, etc Problem 1: How can I retrieve that name from NameArray and...
10
3993
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item in the list A i want to associate an undetermined number of items. The complication for me is the fact that the items to associate in list A are undetermined.
2
2828
by: Boki | last post by:
Hi All, I remember in VB6, we can create any component array just by copy and paste, and the IDE will ask us to use a component array or not. I did the same thing on C#, it will auto create the next picturebox, the name is something like: picturebox2. if they are not array, I will be very difficult to program them ... Best regards,
1
3195
by: Ronald S. Cook | last post by:
How can I create a label array at design time in a .NET Windows forms app? Thanks, Ron
11
4674
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type cli:array<cli::interior_ptr<float>, 2>... So, what do I do?
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.