By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Mixed types in multidimensional arrays

P: n/a

How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that if I
know how to create this array or whatever else method is needed.
--
Anil Gupte
www.keeninc.net
www.icinema.com
Oct 29 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Public struct Storage
Dim a as Integer
Dim b as String
End Struct

Dim info() as Storage

Anil Gupte wrote:
How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that if I
know how to create this array or whatever else method is needed.
Oct 29 '06 #2

P: n/a
Sorry, it must be:

Public structure Storage
Dim a As Integer
Dim b As String
End Structure

Dim Info() as storage

Theo Verweij wrote:
Public struct Storage
Dim a as Integer
Dim b as String
End Struct

Dim info() as Storage

Anil Gupte wrote:
>How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.
Oct 29 '06 #3

P: n/a
In that case, I may as well as create a class, right? I understand
Structures are "passe" in OOP?

Only problem is, creating a class that is an array sounds daunting....

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Theo Verweij" <tv******@xs4all.nlwrote in message
news:OT****************@TK2MSFTNGP04.phx.gbl...
Sorry, it must be:

Public structure Storage
Dim a As Integer
Dim b As String
End Structure

Dim Info() as storage

Theo Verweij wrote:
>Public struct Storage
Dim a as Integer
Dim b as String
End Struct

Dim info() as Storage

Anil Gupte wrote:
>>How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.

Oct 29 '06 #4

P: n/a
"Anil Gupte" <an*******@icinema.comschrieb:
How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that if
I know how to create this array or whatever else method is needed.
Check out the chapter about "jagged arrays" in the documentation.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Oct 29 '06 #5

P: n/a
Anil,
Structures are "passe" in OOP?
No! Why would you think that?

Structures are used when you need to define "Value Types" within .NET

http://msdn.microsoft.com/library/de...Guidelines.asp

Basically when you need a type that:
- acts like primitive types (acts like an integer)
- Have an instance size under 16 bytes
- Are immutable
- Value semantics are desirable.

Although Classes are more commonly used in .NET, Structures still offer all
the major tenets of OO (Encapsulation, Abstraction, Polymorphism)...

Considering there is significantly more to inheritance then the common
Implementation Inheritance found with Classes...
Only problem is, creating a class that is an array sounds daunting....
You wouldn't create a class that is an array, you would create an array of a
specific type. That specific type can be either a reference type (Class) or
a value type (Structure)

In the example you gave, an array of Structures might be easier to use then
an array of Classes...

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Anil Gupte" <an*******@icinema.comwrote in message
news:em****************@TK2MSFTNGP05.phx.gbl...
In that case, I may as well as create a class, right? I understand
Structures are "passe" in OOP?

Only problem is, creating a class that is an array sounds daunting....

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Theo Verweij" <tv******@xs4all.nlwrote in message
news:OT****************@TK2MSFTNGP04.phx.gbl...
>Sorry, it must be:

Public structure Storage
Dim a As Integer
Dim b As String
End Structure

Dim Info() as storage

Theo Verweij wrote:
>>Public struct Storage
Dim a as Integer
Dim b as String
End Struct

Dim info() as Storage

Anil Gupte wrote:
How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.

Oct 29 '06 #6

P: n/a
To provide a custom sorting algorithm, implement the IComparable interface
in the class, and then craft the CompareTo override. If you look up "IComparable
interface, about IComparable interface" in the on-line help, it will provide
an example.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.

Oct 29 '06 #7

P: n/a
Thanx yes,that does help. I have read about Enums, now I will go read up on
structures. I was given the impression by some programmer that real OOP
does not include Structs.

Anyway thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Jay B. Harlow" <Ja************@tsbradley.netwrote in message
news:8B**********************************@microsof t.com...
Anil,
>Structures are "passe" in OOP?
No! Why would you think that?

Structures are used when you need to define "Value Types" within .NET

http://msdn.microsoft.com/library/de...Guidelines.asp

Basically when you need a type that:
- acts like primitive types (acts like an integer)
- Have an instance size under 16 bytes
- Are immutable
- Value semantics are desirable.

Although Classes are more commonly used in .NET, Structures still offer
all the major tenets of OO (Encapsulation, Abstraction, Polymorphism)...

Considering there is significantly more to inheritance then the common
Implementation Inheritance found with Classes...
>Only problem is, creating a class that is an array sounds daunting....
You wouldn't create a class that is an array, you would create an array of
a specific type. That specific type can be either a reference type (Class)
or a value type (Structure)

In the example you gave, an array of Structures might be easier to use
then an array of Classes...

--
Hope this helps
Jay B. Harlow
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Anil Gupte" <an*******@icinema.comwrote in message
news:em****************@TK2MSFTNGP05.phx.gbl...
>In that case, I may as well as create a class, right? I understand
Structures are "passe" in OOP?

Only problem is, creating a class that is an array sounds daunting....

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Theo Verweij" <tv******@xs4all.nlwrote in message
news:OT****************@TK2MSFTNGP04.phx.gbl...
>>Sorry, it must be:

Public structure Storage
Dim a As Integer
Dim b As String
End Structure

Dim Info() as storage

Theo Verweij wrote:
Public struct Storage
Dim a as Integer
Dim b as String
End Struct

Dim info() as Storage

Anil Gupte wrote:
How can I dimension an array like this:
>
dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}
>
I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.


Oct 30 '06 #8

P: n/a
I think jagged arrays are only avaialble in C#, not VB. I looked in the
dynamc help and also in the books for VB that I have, but there is no
mention of it.

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:O4****************@TK2MSFTNGP03.phx.gbl...
"Anil Gupte" <an*******@icinema.comschrieb:
>How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that if
I know how to create this array or whatever else method is needed.

Check out the chapter about "jagged arrays" in the documentation.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Oct 30 '06 #9

P: n/a
Thanx!

BTW, What is Start-to-Finish Visual Basic 2005?

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Tim Patrick" <in*****@invalid.com.invalidwrote in message
news:e3*************************@newsgroups.comcas t.net...
To provide a custom sorting algorithm, implement the IComparable interface
in the class, and then craft the CompareTo override. If you look up
"IComparable interface, about IComparable interface" in the on-line help,
it will provide an example.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
>How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that
if I know how to create this array or whatever else method is needed.


Oct 30 '06 #10

P: n/a
"Anil Gupte" <an*******@icinema.comschrieb:
>I think jagged arrays are only avaialble in C#, not VB. I looked in the
dynamc help and also in the books for VB that I have, but there is no
mention of it.
Jagged arrays are available in VB too ('Dim x()() As String'). However, as
I missed in my previous post, it's better not to use them because you store
values of different types in the elements.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Oct 30 '06 #11

P: n/a
It's a new teach-yourself-Visual-Basic type of book that comes out in about
two weeks. You can find out more at www.timaki.com.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Thanx!

BTW, What is Start-to-Finish Visual Basic 2005?

Oct 30 '06 #12

P: n/a
Anil,

As the other posts said as well...

I tried to do the same thing you did as well...
In the end I used a Class.

I didnt know about Struct, but im pretty happy with the way the class
handled it for me.

M.

"Anil Gupte" <an*******@icinema.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>
How can I dimension an array like this:

dim info(a as integer, b as string) so I can store somthing like
{{"John", 10}{"Dan", 20}{"Jane", 30}}

I want to be able to sort this array too, but I think I can swing that if
I know how to create this array or whatever else method is needed.
--
Anil Gupte
www.keeninc.net
www.icinema.com


Oct 30 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.