|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Mixed types in multidimensional arraysHow 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. Public struct Storage
Dim a as Integer Dim b as String End Struct Dim info() as Storage Anil Gupte wrote: Show quoteHide quote > 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. Sorry, it must be:
Public structure Storage Dim a As Integer Dim b As String End Structure Dim Info() as storage Theo Verweij wrote: Show quoteHide quote > 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. 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.... Show quoteHide quote "Theo Verweij" <tverw***@xs4all.nl> wrote in message news:OT6hZY4%23GHA.1784@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. 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/default.asp?url=/library/en-us/cpgenref/html/cpconValueTypeUsageGuidelines.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... -- Show quoteHide quoteHope this helps Jay B. Harlow ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Anil Gupte" <anil-l***@icinema.com> wrote in message news:emv2DI5%23GHA.4800@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" <tverw***@xs4all.nl> wrote in message > news:OT6hZY4%23GHA.1784@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. > > 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, Show quoteHide quote "Jay B. Harlow" <Jay_Harlow_***@tsbradley.net> wrote in message news:8B0709F3-C8DF-42C8-9AA4-DBF8BEF86A4B@microsoft.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/default.asp?url=/library/en-us/cpgenref/html/cpconValueTypeUsageGuidelines.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" <anil-l***@icinema.com> wrote in message > news:emv2DI5%23GHA.4800@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" <tverw***@xs4all.nl> wrote in message >> news:OT6hZY4%23GHA.1784@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. >> >> > "Anil Gupte" <anil-l***@icinema.com> schrieb: Check out the chapter about "jagged arrays" in the documentation.> 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. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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, Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:O4PiiN5%23GHA.4196@TK2MSFTNGP03.phx.gbl... > "Anil Gupte" <anil-l***@icinema.com> schrieb: >> 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/> "Anil Gupte" <anil-l***@icinema.com> schrieb: Jagged arrays are available in VB too ('Dim x()() As String'). However, as >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. 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/> 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 Show quoteHide quote > 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. > Thanx!
BTW, What is Start-to-Finish Visual Basic 2005? Show quoteHide quote "Tim Patrick" <inva***@invalid.com.invalid> wrote in message news:e3b4697610778c8c96f96278a62@newsgroups.comcast.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. >> > > 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 Show quoteHide quote > Thanx! > > BTW, What is Start-to-Finish Visual Basic 2005? > 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. Show quoteHide quote "Anil Gupte" <anil-l***@icinema.com> wrote in message news:%23hu9oN4%23GHA.4740@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 > >
Re: ActiveX raise event - attn Walter Wang
Selecting a single node in 'XML' Graph control webreq.getresponse exceptions More than one method is found with VB but not with C# Application.StartupPath Adding a Web Reference into a Windows Project turn off assertions in VB 2005 How to read XML from a string variable?? Use dll created in dotnet using them from vb6 |
|||||||||||||||||||||||