Mixed types in multidimensional arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Gupte

    #1

    Mixed types in multidimensional arrays


    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
    Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

    www.icinema.com


  • Theo Verweij

    #2
    Re: Mixed types in multidimensiona l arrays

    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.

    Comment

    • Theo Verweij

      #3
      Re: Mixed types in multidimensiona l arrays

      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.

      Comment

      • Anil Gupte

        #4
        Re: Mixed types in multidimensiona l arrays

        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
        Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

        www.icinema.com

        "Theo Verweij" <tverweij@xs4al l.nlwrote in message
        news:OT6hZY4%23 GHA.1784@TK2MSF TNGP04.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.

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Mixed types in multidimensiona l arrays

          "Anil Gupte" <anil-list@icinema.co mschrieb:
          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/>

          Comment

          • Jay B. Harlow

            #6
            Re: Mixed types in multidimensiona l arrays

            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" <anil-list@icinema.co mwrote in message
            news:emv2DI5%23 GHA.4800@TK2MSF TNGP05.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
            Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

            www.icinema.com
            >
            "Theo Verweij" <tverweij@xs4al l.nlwrote in message
            news:OT6hZY4%23 GHA.1784@TK2MSF TNGP04.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.
            >
            >

            Comment

            • Tim Patrick

              #7
              Re: Mixed types in multidimensiona l arrays

              To provide a custom sorting algorithm, implement the IComparable interface
              in the class, and then craft the CompareTo override. If you look up "IComparabl e
              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.
              >

              Comment

              • Anil Gupte

                #8
                Re: Mixed types in multidimensiona l arrays

                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
                Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

                www.icinema.com

                "Jay B. Harlow" <Jay_Harlow_MVP @tsbradley.netw rote in message
                news:8B0709F3-C8DF-42C8-9AA4-DBF8BEF86A4B@mi crosoft.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" <anil-list@icinema.co mwrote in message
                news:emv2DI5%23 GHA.4800@TK2MSF TNGP05.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" <tverweij@xs4al l.nlwrote in message
                >news:OT6hZY4%2 3GHA.1784@TK2MS FTNGP04.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.
                >>
                >>
                >

                Comment

                • Anil Gupte

                  #9
                  Re: Mixed types in multidimensiona l arrays

                  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
                  Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

                  www.icinema.com

                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                  news:O4PiiN5%23 GHA.4196@TK2MSF TNGP03.phx.gbl. ..
                  "Anil Gupte" <anil-list@icinema.co mschrieb:
                  >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/>

                  Comment

                  • Anil Gupte

                    #10
                    Re: Mixed types in multidimensiona l arrays

                    Thanx!

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

                    --
                    Anil Gupte
                    Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

                    www.icinema.com

                    "Tim Patrick" <invalid@invali d.com.invalidwr ote in message
                    news:e3b4697610 778c8c96f96278a 62@newsgroups.c omcast.net...
                    To provide a custom sorting algorithm, implement the IComparable interface
                    in the class, and then craft the CompareTo override. If you look up
                    "IComparabl e 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.
                    >>
                    >
                    >

                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: Mixed types in multidimensiona l arrays

                      "Anil Gupte" <anil-list@icinema.co mschrieb:
                      >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/>

                      Comment

                      • Tim Patrick

                        #12
                        Re: Mixed types in multidimensiona l arrays

                        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?
                        >

                        Comment

                        • Miro

                          #13
                          Re: Mixed types in multidimensiona l arrays

                          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" <anil-list@icinema.co mwrote in message
                          news:%23hu9oN4% 23GHA.4740@TK2M SFTNGP03.phx.gb l...
                          >
                          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
                          Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

                          www.icinema.com
                          >
                          >

                          Comment

                          Working...