Creating an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Dufour

    #1

    Creating an array

    I need an array with two columns, values in column 1 are datetime and in
    column 2 they are numeric with up to two decimal places.

    What's the Dim statement to create this?

    Any help is greatly appreciated.

    Bob


  • Scott M.

    #2
    Re: Creating an array

    If you want to have the 2 data types preserved use an ArrayList object or a
    Collection object, rather than a simple single-type array.


    "Robert Dufour" <bdufour@sgiims .comwrote in message
    news:ev2UJanPHH A.2340@TK2MSFTN GP05.phx.gbl...
    >I need an array with two columns, values in column 1 are datetime and in
    >column 2 they are numeric with up to two decimal places.
    >
    What's the Dim statement to create this?
    >
    Any help is greatly appreciated.
    >
    Bob
    >
    >

    Comment

    • Armin Zingler

      #3
      Re: Creating an array

      "Robert Dufour" <bdufour@sgiims .comschrieb
      I need an array with two columns, values in column 1 are datetime
      and in column 2 they are numeric with up to two decimal places.
      >
      What's the Dim statement to create this?
      >
      Any help is greatly appreciated.
      structure Item
      public v1 as date
      public v2 as decimal
      end structure

      '...


      dim items(17) as item

      items(0).v1 = date.now
      items(0).v2 = 17.34

      with items(1)
      .v1 = date.now
      .v2 = 17.34
      end with


      Armin

      Comment

      • Robert Dufour

        #4
        Re: Creating an array

        Thanks
        Bob
        "Armin Zingler" <az.nospam@free net.dewrote in message
        news:uG3syMoPHH A.4372@TK2MSFTN GP04.phx.gbl...
        "Robert Dufour" <bdufour@sgiims .comschrieb
        >I need an array with two columns, values in column 1 are datetime
        >and in column 2 they are numeric with up to two decimal places.
        >>
        >What's the Dim statement to create this?
        >>
        >Any help is greatly appreciated.
        >
        structure Item
        public v1 as date
        public v2 as decimal
        end structure
        >
        '...
        >
        >
        dim items(17) as item
        >
        items(0).v1 = date.now
        items(0).v2 = 17.34
        >
        with items(1)
        .v1 = date.now
        .v2 = 17.34
        end with
        >
        >
        Armin

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Creating an array

          Armin,

          Is a List Of(item) not nicer?

          Cor

          "Armin Zingler" <az.nospam@free net.deschreef in bericht
          news:uG3syMoPHH A.4372@TK2MSFTN GP04.phx.gbl...
          "Robert Dufour" <bdufour@sgiims .comschrieb
          >I need an array with two columns, values in column 1 are datetime
          >and in column 2 they are numeric with up to two decimal places.
          >>
          >What's the Dim statement to create this?
          >>
          >Any help is greatly appreciated.
          >
          structure Item
          public v1 as date
          public v2 as decimal
          end structure
          >
          '...
          >
          >
          dim items(17) as item
          >
          items(0).v1 = date.now
          items(0).v2 = 17.34
          >
          with items(1)
          .v1 = date.now
          .v2 = 17.34
          end with
          >
          >
          Armin

          Comment

          • Armin Zingler

            #6
            Re: Creating an array

            Hi Cor,

            well, he asked for an array, I gave him an array. ;-)

            You're right with VB 2005, but as Item is a structure (it doesn't have to
            be), it's more complicated if you use it with the generic List. You can not
            simply write

            items(0).v1 = ...
            items(0).v2 = ...

            you would have to write

            dim i as item

            i.v1=..
            i.v2=..

            items(0) = i

            Armin


            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb
            Armin,
            >
            Is a List Of(item) not nicer?
            >
            Cor
            >
            "Armin Zingler" <az.nospam@free net.deschreef in bericht
            news:uG3syMoPHH A.4372@TK2MSFTN GP04.phx.gbl...
            "Robert Dufour" <bdufour@sgiims .comschrieb
            I need an array with two columns, values in column 1 are
            datetime and in column 2 they are numeric with up to two decimal
            places.
            >
            What's the Dim statement to create this?
            >
            Any help is greatly appreciated.
            structure Item
            public v1 as date
            public v2 as decimal
            end structure

            '...


            dim items(17) as item

            items(0).v1 = date.now
            items(0).v2 = 17.34

            with items(1)
            .v1 = date.now
            .v2 = 17.34
            end with


            Armin
            >
            >

            Comment

            • _AnonCoward

              #7
              Re: Creating an array


              "Robert Dufour" <bdufour@sgiims .comwrote in message
              news:ev2UJanPHH A.2340@TK2MSFTN GP05.phx.gbl...
              :
              : I need an array with two columns, values in column 1 are datetime
              : and in column 2 they are numeric with up to two decimal places.
              :
              : What's the Dim statement to create this?
              :
              : Any help is greatly appreciated.
              :
              : Bob


              Just for the sake of a little diversity...

              =============== =============== =============
              Option Strict On

              Imports Microsoft.Visua lBasic
              Imports System
              Imports System.Collecti ons.Generic

              Public Module [module]
              public sub main
              Dim dictionary As New Dictionary(Of DateTime, Decimal)
              With dictionary
              .Add(Date.Now, 12.34D)
              .Add(#1/2/2007#, 5678910.11D)
              End With

              Dim kvp As KeyValuePair(Of Date, Decimal)
              For Each kvp In dictionary
              Console.WriteLi ne("Key={0}, Value={1}", _
              kvp.Key, kvp.Value)
              Next
              End sub
              End Module
              =============== =============== =============


              Ralf
              --
              --
              ----------------------------------------------------------
              * ^~^ ^~^ *
              * _ {~ ~} {~ ~} _ *
              * /_``>*< >*<''_\ *
              * (\--_)++) (++(_--/) *
              ----------------------------------------------------------
              There are no advanced students in Aikido - there are only
              competent beginners. There are no advanced techniques -
              only the correct application of basic principles.


              Comment

              • Mythran

                #8
                Re: Creating an array



                "Armin Zingler" <az.nospam@free net.dewrote in message
                news:udKO#vpPHH A.992@TK2MSFTNG P06.phx.gbl...
                Hi Cor,
                >
                well, he asked for an array, I gave him an array. ;-)
                >
                You're right with VB 2005, but as Item is a structure (it doesn't have to
                be), it's more complicated if you use it with the generic List. You can
                not
                simply write
                >
                items(0).v1 = ...
                items(0).v2 = ...
                >
                you would have to write
                >
                dim i as item
                >
                i.v1=..
                i.v2=..
                >
                items(0) = i
                >
                Armin
                >
                >
                "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb
                >Armin,
                >>
                >Is a List Of(item) not nicer?
                >>
                >Cor
                >>
                >"Armin Zingler" <az.nospam@free net.deschreef in bericht
                >news:uG3syMoPH HA.4372@TK2MSFT NGP04.phx.gbl.. .
                "Robert Dufour" <bdufour@sgiims .comschrieb
                I need an array with two columns, values in column 1 are
                datetime and in column 2 they are numeric with up to two decimal
                places.
                >
                What's the Dim statement to create this?
                >
                Any help is greatly appreciated.
                >
                structure Item
                public v1 as date
                public v2 as decimal
                end structure
                >
                '...
                >
                >
                dim items(17) as item
                >
                items(0).v1 = date.now
                items(0).v2 = 17.34
                >
                with items(1)
                .v1 = date.now
                .v2 = 17.34
                end with
                >
                >
                Armin
                >>
                >>
                >
                In which case you can just add a constructor to the structure that took 2
                parameters, the names of the properties to set. Then you could just use:

                items(0) = New Item(someDate, someDecimal)

                :)

                HTH,
                Mythran


                Comment

                • Armin Zingler

                  #9
                  Re: Creating an array

                  "Mythran" <kip_potter@hot mail.comschrieb
                  You're right with VB 2005, but as Item is a structure (it doesn't
                  have to
                  be), it's more complicated if you use it with the generic List.
                  You can
                  not
                  simply write

                  items(0).v1 = ...
                  items(0).v2 = ...

                  you would have to write

                  dim i as item

                  i.v1=..
                  i.v2=..

                  items(0) = i
                  >
                  In which case you can just add a constructor to the structure that
                  took 2
                  parameters, the names of the properties to set. Then you could just
                  use:
                  >
                  items(0) = New Item(someDate, someDecimal)
                  >
                  :)

                  Right, but my example doesn't create a new item.


                  Armin

                  Comment

                  • Mythran

                    #10
                    Re: Creating an array



                    "Armin Zingler" <az.nospam@free net.dewrote in message
                    news:udhxQ9wPHH A.2312@TK2MSFTN GP04.phx.gbl...
                    "Mythran" <kip_potter@hot mail.comschrieb
                    You're right with VB 2005, but as Item is a structure (it doesn't
                    have to
                    be), it's more complicated if you use it with the generic List.
                    You can
                    not
                    simply write
                    >
                    items(0).v1 = ...
                    items(0).v2 = ...
                    >
                    you would have to write
                    >
                    dim i as item
                    >
                    i.v1=..
                    i.v2=..
                    >
                    items(0) = i
                    >
                    >>
                    >In which case you can just add a constructor to the structure that
                    >took 2
                    >parameters, the names of the properties to set. Then you could just
                    >use:
                    >>
                    >items(0) = New Item(someDate, someDecimal)
                    >>
                    >:)
                    >
                    >
                    Right, but my example doesn't create a new item.
                    >
                    >
                    Armin
                    Umm, yeah it did :0

                    Dim i As Item

                    is the same as

                    Dim i As Item = New Item()

                    where Item is a structure....

                    :)

                    Mythran


                    Comment

                    • Armin Zingler

                      #11
                      Re: Creating an array

                      "Mythran" <kip_potter@hot mail.comschrieb
                      >
                      >
                      "Armin Zingler" <az.nospam@free net.dewrote in message
                      news:udhxQ9wPHH A.2312@TK2MSFTN GP04.phx.gbl...
                      "Mythran" <kip_potter@hot mail.comschrieb
                      You're right with VB 2005, but as Item is a structure (it
                      doesn't have to
                      be), it's more complicated if you use it with the generic
                      List. You can
                      not
                      simply write

                      items(0).v1 = ...
                      items(0).v2 = ...

                      you would have to write

                      dim i as item

                      i.v1=..
                      i.v2=..

                      items(0) = i

                      >
                      In which case you can just add a constructor to the structure
                      that took 2
                      parameters, the names of the properties to set. Then you could
                      just use:
                      >
                      items(0) = New Item(someDate, someDecimal)
                      >
                      :)

                      Right, but my example doesn't create a new item.


                      Armin
                      >
                      Umm, yeah it did :0
                      >
                      Dim i As Item
                      >
                      is the same as
                      >
                      Dim i As Item = New Item()
                      >
                      where Item is a structure....
                      >
                      :)
                      [After many revisions...]

                      Yes and no. :-)

                      My List has as many items as before, so I didn't create a new item.

                      I am referring to the logical level. I only wanted to show that you can not
                      simply write

                      items(0).field = ...

                      but you have to a) declare a variable b) set the field values c) put the
                      item in the list. That's why I call it more complicated. That the existence
                      of the additional declaration of variable i also means the implicit creation
                      of a new object can not be prevented, but the code's purpose is still
                      /changing/ an existing item. If I wanted to create a /new/ one I would have
                      to write Items.Add.


                      Talking about instances, we know that it is never possible to really change
                      the item in the List, and we neither get the same object back from the List
                      that we added, nor the object we add is stored in the list. It is always a
                      copy because it is a value type.


                      In other words, if somebody wants to know how to change an item in the List,
                      I would still answer

                      dim i as item

                      i.v1=..
                      i.v2=..

                      items(0) = i

                      On a logical level this is the required change whereas on a "physical" level
                      it's the creation of (at least) one new object. So, we both are right. :-)


                      Armin

                      Comment

                      • Cor Ligthert [MVP]

                        #12
                        Re: Creating an array

                        Mythran,

                        You know Armin from the past. This will probably a long thread.

                        However mostly all threads Armin is involved in are very good to search for
                        later when they are ready.

                        Success,

                        :-)

                        Cor

                        "Mythran" <kip_potter@hot mail.comschreef in bericht
                        news:%23wqWGUxP HHA.3344@TK2MSF TNGP02.phx.gbl. ..
                        >
                        >
                        "Armin Zingler" <az.nospam@free net.dewrote in message
                        news:udhxQ9wPHH A.2312@TK2MSFTN GP04.phx.gbl...
                        >"Mythran" <kip_potter@hot mail.comschrieb
                        >You're right with VB 2005, but as Item is a structure (it doesn't
                        >have to
                        >be), it's more complicated if you use it with the generic List.
                        >You can
                        >not
                        >simply write
                        >>
                        > items(0).v1 = ...
                        > items(0).v2 = ...
                        >>
                        >you would have to write
                        >>
                        > dim i as item
                        >>
                        > i.v1=..
                        > i.v2=..
                        >>
                        > items(0) = i
                        >>
                        >>>
                        >>In which case you can just add a constructor to the structure that
                        >>took 2
                        >>parameters, the names of the properties to set. Then you could just
                        >>use:
                        >>>
                        >>items(0) = New Item(someDate, someDecimal)
                        >>>
                        >>:)
                        >>
                        >>
                        >Right, but my example doesn't create a new item.
                        >>
                        >>
                        >Armin
                        >
                        Umm, yeah it did :0
                        >
                        Dim i As Item
                        >
                        is the same as
                        >
                        Dim i As Item = New Item()
                        >
                        where Item is a structure....
                        >
                        :)
                        >
                        Mythran
                        >
                        >

                        Comment

                        • Armin Zingler

                          #13
                          Re: Creating an array

                          "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb
                          Mythran,
                          >
                          You know Armin from the past. This will probably a long thread.
                          Heeey, I didn't know I'm mainly responsible for long threads. ;-) I'm only
                          (still) not able to say what I want to say briefly. ;-(



                          Armin

                          Comment

                          • Cor Ligthert [MVP]

                            #14
                            Re: Creating an array

                            Armin,

                            After sending this, I got the idea that you would read it as you did. I
                            wanted to say that you mostly investigate very good what you are writing
                            (after a quick start).

                            :-)

                            Cor

                            "Armin Zingler" <az.nospam@free net.deschreef in bericht
                            news:%23XvUsGyP HHA.4424@TK2MSF TNGP06.phx.gbl. ..
                            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb
                            >Mythran,
                            >>
                            >You know Armin from the past. This will probably a long thread.
                            >
                            Heeey, I didn't know I'm mainly responsible for long threads. ;-) I'm only
                            (still) not able to say what I want to say briefly. ;-(
                            >
                            >
                            >
                            Armin

                            Comment

                            Working...