Zero out Array

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

    #1

    Zero out Array

    Is there a quick way to fill an array with zeros or make all elements
    empty/nothing?


  • 

    #2
    Re: Zero out Array

    it depends.

    specifying the array dimensions in the dim should fill it based on your
    requirements.

    dim intArray(5) as integer ' elements s/b 0
    dim objArray(5) as string ' elements s/b nothing

    but then again, i assume you just haven't fleshed out your question
    completely.

    you can erase arrays, set variables to new arrays, initialize arrays,
    etc....it really depends on what it is you're trying to accomplish.

    "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
    news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..
    | Is there a quick way to fill an array with zeros or make all elements
    | empty/nothing?


    Comment

    • DazedAndConfused

      #3
      Re: Zero out Array

      Your right I didn't give an accurate description of what I am doing.

      The array is dimensioned as Shared Friend.
      The elements are populated with data and processed.
      The array needs to be emptied out before reloading with new data without
      redimensioning.

      I know I can use for loops to reset the array, but I was looking to see if
      there is a better way. I will look to see what erase array offers. Let me
      know if there is a better way.

      Thank You.
      "" <a@b.com> wrote in message news:j43Me.4967 2$vb3.5056@fe07 .lga...[color=blue]
      > it depends.
      >
      > specifying the array dimensions in the dim should fill it based on your
      > requirements.
      >
      > dim intArray(5) as integer ' elements s/b 0
      > dim objArray(5) as string ' elements s/b nothing
      >
      > but then again, i assume you just haven't fleshed out your question
      > completely.
      >
      > you can erase arrays, set variables to new arrays, initialize arrays,
      > etc....it really depends on what it is you're trying to accomplish.
      >
      > "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
      > news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..
      > | Is there a quick way to fill an array with zeros or make all elements
      > | empty/nothing?
      >
      >[/color]


      Comment

      • DazedAndConfused

        #4
        Re: Zero out Array

        ReDim appears to be giving me the result I wanted, but I am unsure if this
        is the proper way because I am not really changing dimension sizes. Should I
        also be erasing the array before I ReDim?
        "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
        news:E4ydnRHbXP vcXZ3eRVn-hQ@comcast.com. ..[color=blue]
        > Your right I didn't give an accurate description of what I am doing.
        >
        > The array is dimensioned as Shared Friend.
        > The elements are populated with data and processed.
        > The array needs to be emptied out before reloading with new data without
        > redimensioning.
        >
        > I know I can use for loops to reset the array, but I was looking to see if
        > there is a better way. I will look to see what erase array offers. Let me
        > know if there is a better way.
        >
        > Thank You.
        > "" <a@b.com> wrote in message news:j43Me.4967 2$vb3.5056@fe07 .lga...[color=green]
        >> it depends.
        >>
        >> specifying the array dimensions in the dim should fill it based on your
        >> requirements.
        >>
        >> dim intArray(5) as integer ' elements s/b 0
        >> dim objArray(5) as string ' elements s/b nothing
        >>
        >> but then again, i assume you just haven't fleshed out your question
        >> completely.
        >>
        >> you can erase arrays, set variables to new arrays, initialize arrays,
        >> etc....it really depends on what it is you're trying to accomplish.
        >>
        >> "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
        >> news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..
        >> | Is there a quick way to fill an array with zeros or make all elements
        >> | empty/nothing?
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Hal Rosser

          #5
          Re: Zero out Array

          Redim the array without using the 'Preserve' keyword. Numeric types will be
          set to zero.



          "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
          news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..[color=blue]
          > Is there a quick way to fill an array with zeros or make all elements
          > empty/nothing?
          >
          >[/color]


          Comment

          • DazedAndConfused

            #6
            Re: Zero out Array

            Thank you. I get sooo confused with VS Help. ReDim is working great. Help
            says "ReDim creates another new array" and I am afraid I am creating
            multiple arrays when I only need 1. Just trying not to write crappy code!

            "Hal Rosser" <hmrosser@bells outh.net> wrote in message
            news:0G3Me.1180 9$Rm3.10859@big news4.bellsouth .net...[color=blue]
            > Redim the array without using the 'Preserve' keyword. Numeric types will
            > be
            > set to zero.
            >
            >
            >
            > "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
            > news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..[color=green]
            >> Is there a quick way to fill an array with zeros or make all elements
            >> empty/nothing?
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Rick Mogstad

              #7
              Re: Zero out Array

              array.Clear(MyA rray,0,MyArray. Length)





              "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
              news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..[color=blue]
              > Is there a quick way to fill an array with zeros or make all elements
              > empty/nothing?
              >[/color]


              Comment

              • Chris

                #8
                Re: Zero out Array

                DazedAndConfuse d wrote:[color=blue]
                > Thank you. I get sooo confused with VS Help. ReDim is working great. Help
                > says "ReDim creates another new array" and I am afraid I am creating
                > multiple arrays when I only need 1. Just trying not to write crappy code!
                >
                > "Hal Rosser" <hmrosser@bells outh.net> wrote in message
                > news:0G3Me.1180 9$Rm3.10859@big news4.bellsouth .net...
                >[color=green]
                >>Redim the array without using the 'Preserve' keyword. Numeric types will
                >>be
                >>set to zero.
                >>
                >>
                >>
                >>"DazedAndConf used" <AceMagoo61@yah oo.com> wrote in message
                >>news:iOWdnfBv wejPJp3eRVn-gQ@comcast.com. ..
                >>[color=darkred]
                >>>Is there a quick way to fill an array with zeros or make all elements
                >>>empty/nothing?
                >>>
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]

                AFAIK, redim will create you another array, but then the first array
                will be cleaned up by the garbage collector when it gets around to it
                and no other object reference the array.

                Chris

                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Zero out Array

                  "DazedAndConfus ed" <AceMagoo61@yah oo.com> schrieb:[color=blue]
                  > Thank you. I get sooo confused with VS Help. ReDim is working great. Help
                  > says "ReDim creates another new array" and I am afraid I am creating
                  > multiple arrays when I only need 1.[/color]

                  Yes, 'ReDim' will create a new array. However, the old array will be
                  transparently removed from memory by the garbabe collector automatically.
                  Alternatively you could loop through the array and reset all the items in
                  the array (three lines of code...).

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

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Zero out Array

                    "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > schrieb:[color=blue]
                    > array.Clear(MyA rray,0,MyArray. Length)[/color]

                    That's indeed a good solution!

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

                    Comment

                    • DazedAndConfused

                      #11
                      Re: Zero out Array

                      I have a multi-dimensional array, would I need to:

                      array.Clear(MyA rray,0,MyArray. Length)
                      array.Clear(MyA rray,1,MyArray. Length)
                      array.Clear(MyA rray,2,MyArray. Length)
                      array.Clear(MyA rray,3,MyArray. Length)

                      ?

                      "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > wrote in message
                      news:ubYFt2boFH A.3696@TK2MSFTN GP12.phx.gbl...[color=blue]
                      > array.Clear(MyA rray,0,MyArray. Length)
                      >
                      >
                      >
                      >
                      >
                      > "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                      > news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..[color=green]
                      >> Is there a quick way to fill an array with zeros or make all elements
                      >> empty/nothing?
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      • DazedAndConfused

                        #12
                        Re: Zero out Array

                        OK, Length is the total size of the array including all dimensions. So
                        starting at 0 and going to Length would clear all dimensions.

                        Do I have that right?

                        Thank you again.
                        "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                        news:d7OdnYDvf4 dFfJ3eRVn-2w@comcast.com. ..[color=blue]
                        >I have a multi-dimensional array, would I need to:
                        >
                        > array.Clear(MyA rray,0,MyArray. Length)
                        > array.Clear(MyA rray,1,MyArray. Length)
                        > array.Clear(MyA rray,2,MyArray. Length)
                        > array.Clear(MyA rray,3,MyArray. Length)
                        >
                        > ?
                        >
                        > "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > wrote in message
                        > news:ubYFt2boFH A.3696@TK2MSFTN GP12.phx.gbl...[color=green]
                        >> array.Clear(MyA rray,0,MyArray. Length)
                        >>
                        >>
                        >>
                        >>
                        >>
                        >> "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                        >> news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..[color=darkred]
                        >>> Is there a quick way to fill an array with zeros or make all elements
                        >>> empty/nothing?
                        >>>[/color]
                        >>
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        • Rick Mogstad

                          #13
                          Re: Zero out Array

                          Hmm. Probably, you would have to try it out. I dont use multi-dimensional
                          arrays much, so I havent tried it.


                          "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                          news:MuWdnZOnPI Uhfp3eRVn-qg@comcast.com. ..[color=blue]
                          > OK, Length is the total size of the array including all dimensions. So
                          > starting at 0 and going to Length would clear all dimensions.
                          >
                          > Do I have that right?
                          >
                          > Thank you again.
                          > "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                          > news:d7OdnYDvf4 dFfJ3eRVn-2w@comcast.com. ..[color=green]
                          >>I have a multi-dimensional array, would I need to:
                          >>
                          >> array.Clear(MyA rray,0,MyArray. Length)
                          >> array.Clear(MyA rray,1,MyArray. Length)
                          >> array.Clear(MyA rray,2,MyArray. Length)
                          >> array.Clear(MyA rray,3,MyArray. Length)
                          >>
                          >> ?
                          >>
                          >> "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > wrote in message
                          >> news:ubYFt2boFH A.3696@TK2MSFTN GP12.phx.gbl...[color=darkred]
                          >>> array.Clear(MyA rray,0,MyArray. Length)
                          >>>
                          >>>
                          >>>
                          >>>
                          >>>
                          >>> "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                          >>> news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..
                          >>>> Is there a quick way to fill an array with zeros or make all elements
                          >>>> empty/nothing?
                          >>>>
                          >>>
                          >>>[/color]
                          >>
                          >>[/color]
                          >
                          >[/color]


                          Comment

                          • DazedAndConfused

                            #14
                            Re: Zero out Array

                            It seems to be working. Thank you.
                            "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > wrote in message
                            news:e1ONpmeoFH A.1148@TK2MSFTN GP12.phx.gbl...[color=blue]
                            > Hmm. Probably, you would have to try it out. I dont use
                            > multi-dimensional arrays much, so I havent tried it.
                            >
                            >
                            > "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                            > news:MuWdnZOnPI Uhfp3eRVn-qg@comcast.com. ..[color=green]
                            >> OK, Length is the total size of the array including all dimensions. So
                            >> starting at 0 and going to Length would clear all dimensions.
                            >>
                            >> Do I have that right?
                            >>
                            >> Thank you again.
                            >> "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                            >> news:d7OdnYDvf4 dFfJ3eRVn-2w@comcast.com. ..[color=darkred]
                            >>>I have a multi-dimensional array, would I need to:
                            >>>
                            >>> array.Clear(MyA rray,0,MyArray. Length)
                            >>> array.Clear(MyA rray,1,MyArray. Length)
                            >>> array.Clear(MyA rray,2,MyArray. Length)
                            >>> array.Clear(MyA rray,3,MyArray. Length)
                            >>>
                            >>> ?
                            >>>
                            >>> "Rick Mogstad" <Rick.Mogstad@G Mail.NOSPAM.com > wrote in message
                            >>> news:ubYFt2boFH A.3696@TK2MSFTN GP12.phx.gbl...
                            >>>> array.Clear(MyA rray,0,MyArray. Length)
                            >>>>
                            >>>>
                            >>>>
                            >>>>
                            >>>>
                            >>>> "DazedAndConfus ed" <AceMagoo61@yah oo.com> wrote in message
                            >>>> news:iOWdnfBvwe jPJp3eRVn-gQ@comcast.com. ..
                            >>>>> Is there a quick way to fill an array with zeros or make all elements
                            >>>>> empty/nothing?
                            >>>>>
                            >>>>
                            >>>>
                            >>>
                            >>>[/color]
                            >>
                            >>[/color]
                            >
                            >[/color]


                            Comment

                            Working...