473,385 Members | 1,588 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,385 software developers and data experts.

Which type of object for these values?

I need an object/structure such as an array but each item within the array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
.......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett
Nov 21 '05 #1
7 998
Hi,

I would store the info in a class.

Public Class MyData

Dim mp1, mp2, mp3 As Point

Public Sub New()

mp1 = New Point

mp2 = New Point

mp3 = New Point

End Sub

Public Property p1() As Point

Get

Return mp1

End Get

Set(ByVal Value As Point)

mp1 = Value

End Set

End Property

Public Property p2() As Point

Get

Return mp2

End Get

Set(ByVal Value As Point)

mp2 = Value

End Set

End Property

Public Property p3() As Point

Get

Return mp3

End Get

Set(ByVal Value As Point)

mp3 = Value

End Set

End Property

End Class

Ken
-----------------
"Brett" <no@spam.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I need an object/structure such as an array but each item within the array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
.......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett

Nov 21 '05 #2
As I mentioned, the total number of items aren't defined. You've defined
three "Point"s. There may be 1 or 100 or anything in between. I also need
the ability to loop through each item and reference the particular item's
properties.

Would an array with structures for each item work? For example, say I had
three items for one case. An item will always have three properties. The
structure would look like this:

array.item(0).p1 = someval1
array.item(0).p2 = someval2
array.item(0).p3 = someval3

array.item(1).p1 = someval11
array.item(1).p2 = someval21
array.item(1).p3 = someval31

array.item(2).p1 = someval12
array.item(2).p2 = someval22
array.item(2).p3 = someval32

Brett

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uf****************@TK2MSFTNGP10.phx.gbl...
Hi,

I would store the info in a class.

Public Class MyData

Dim mp1, mp2, mp3 As Point

Public Sub New()

mp1 = New Point

mp2 = New Point

mp3 = New Point

End Sub

Public Property p1() As Point

Get

Return mp1

End Get

Set(ByVal Value As Point)

mp1 = Value

End Set

End Property

Public Property p2() As Point

Get

Return mp2

End Get

Set(ByVal Value As Point)

mp2 = Value

End Set

End Property

Public Property p3() As Point

Get

Return mp3

End Get

Set(ByVal Value As Point)

mp3 = Value

End Set

End Property

End Class

Ken
-----------------
"Brett" <no@spam.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I need an object/structure such as an array but each item within the array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett

Nov 21 '05 #3
guy
As ken says put your item data in a class then load them into either an
arraylist or hashtable (check the docs) as appropriate, that way you dont
need to worry about the number of items you are storing
(hashtable gives 'indexed' access)

hth

guy
"Brett" wrote:
I need an object/structure such as an array but each item within the array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
.......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett

Nov 21 '05 #4
Brett,

In my opinion is a structure a structure, not a variable array.

Can you make that point about the variable P1, P2, P3, Px more clear.

Cor
Nov 21 '05 #5
I really have no idea what you are asking/stating.

Brett

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
Brett,

In my opinion is a structure a structure, not a variable array.

Can you make that point about the variable P1, P2, P3, Px more clear.

Cor

Nov 21 '05 #6
Guess it's more that I don't understand how it works. Could you provide an
example of what the array loop with references to each of the three
properties for an item would look like?

Thanks,
Brett

"guy" <gu*@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
As ken says put your item data in a class then load them into either an
arraylist or hashtable (check the docs) as appropriate, that way you dont
need to worry about the number of items you are storing
(hashtable gives 'indexed' access)

hth

guy
"Brett" wrote:
I need an object/structure such as an array but each item within the
array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
.......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett

Nov 21 '05 #7
Brett,
As Ken suggests define a Structure or Class to hold a single item.

' From Ken's post
Public Class MyData
...
End Class

Then define an array to hold a collection of these items.

Dim list(5 - 1) As MyData ' list of 5 MyData objects

' explicitly create each element of array
For i = 0 To list.count - 1 'where count is 5
list(i) = New MyData(...)
Next

' do something to each property of each element
For i = 0 To list.count - 1 'where count is 5
list(i).p1 = something
list(i).p2 = something
list(i).p3 = something
Next

Because we defined MyData as Class, you need to create an instance of the
class in each array element first. If we had defined MyData as a Structure,
each element would be automatically created. Its the primary difference
between Reference types (classes) and Value types (structures).

As the others have suggested, using an ArrayList or Hashtable (or other
collections from System.Collections & System.Collections.Specialized) may be
a better fit for the problem at hand. Normally I create a specialized
collection that inherits from DictionaryBase or CollectionBase so my
collection is strongly typed...

Hope this helps
Jay

"Brett" <no@spam.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I need an object/structure such as an array but each item within the array
is a complex structure. For example, I have 5 items, say:
A thru E. The number of items may change. Each item has certain
properties. Such as:

A.p1
A.p2
A.p3
......
E.p1
E.p2
E.p3

I'll assign values, via a loop, to what ever structure will hold these
complex types. For example:

For i = 0 To structure.count 'where count is 5
structure(i).p1 = something
structure(i).p2 = something
structure(i).p3 = something
Next

What type of structure will I need for the above?

Thanks,
Brett

Nov 21 '05 #8

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

Similar topics

51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
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);
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
6
by: Markus Eßmayr | last post by:
Hello, I'd like to consume a WebService, which returns an array of objects which include several members of type System.String, System.Decimal and System.DateTime. In the WSDL-file, the members...
11
by: tinman | last post by:
Hi... I have the following two excerpts from a method. It basically reads data from a DataReader and loads it in a collection. Excerpt A: ******** With ProjectData
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
4
by: Nathan Sokalski | last post by:
I am writing a piece of code for an ASP.NET function that generates an onKeyPress JavaScript eventhandler that uses the event.keyCode / event.which properties. I have two situations that I would...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...

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.