473,692 Members | 2,104 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 1652


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
1706
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
7980
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
3012
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
2134
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
1781
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
2962
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
3981
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
2820
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
3188
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
4650
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
8600
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
8535
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
8954
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...
1
8794
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6458
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
5817
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4555
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.