Ubound()

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

    #1

    Ubound()

    What is the consensus about using the Ubound function? Should it be avoided
    altogether? Is there an arry size where Ubound becomes less efficent?

    Also, is there a better way to increase the size of an array (preserving its
    current values) besides using Redim Preserve?

    Thanks,
    Mark
  • Jim Wooley

    #2
    Re: Ubound()

    > What is the consensus about using the Ubound function? Should it be[color=blue]
    > avoided altogether? Is there an arry size where Ubound becomes less
    > efficent?
    >
    > Also, is there a better way to increase the size of an array
    > (preserving its current values) besides using Redim Preserve?[/color]

    Have you considered the ArrayList? Depending on your needs, it may have advantages.
    It does not require a Redim to change the size of the array for one.

    Jim Wooley



    Comment

    • Tom Shelton

      #3
      Re: Ubound()


      Mark wrote:[color=blue]
      > What is the consensus about using the Ubound function? Should it be avoided
      > altogether? Is there an arry size where Ubound becomes less efficent?
      >[/color]

      I really have no objects to the Ubound function, nor do I know of any
      limits on it's efficeincy.
      [color=blue]
      > Also, is there a better way to increase the size of an array (preserving its
      > current values) besides using Redim Preserve?[/color]

      With a regular array object? Not really. My only advice here is to
      limit the number of calls to Redim... That means don't call Redim for
      every element you add - always allocate in chunks.

      If what you are storing in the array are reference types (classes, not
      structures) then I would suggest using an arraylist rather then a pure
      array. An arraylist will grow dynamically (actually, it will
      essentially do what you have to do manually with a regular array -
      redim the array that is it's backing store when it needs to grow, but
      it does it in chunks so you don't have to worry about it). It will
      most likely give you better performance... If you are using VB.NET
      2005, then I would say to use one of the generic list class. It will
      give you good performance even with value types (structures). If you
      using 2003 or earlier, then I would consider using a typed array if you
      are storing value types and managing the array resize your self - I
      would put it into a class....

      I hope my rambling made sense :)

      --
      Tom Shelton [MVP]

      Comment

      • Mark

        #4
        RE: Ubound()

        Good stuff! Thanks a bunch.

        Mark

        "Mark" wrote:
        [color=blue]
        > What is the consensus about using the Ubound function? Should it be avoided
        > altogether? Is there an arry size where Ubound becomes less efficent?
        >
        > Also, is there a better way to increase the size of an array (preserving its
        > current values) besides using Redim Preserve?
        >
        > Thanks,
        > Mark[/color]

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Ubound()

          "Mark" <Mark@discussio ns.microsoft.co m> schrieb:[color=blue]
          > What is the consensus about using the Ubound function? Should it be
          > avoided
          > altogether? Is there an arry size where Ubound becomes less efficent?[/color]

          In addition to the other replies, note that using 'UBound' can make code
          shorter and prevent bugs from occuring because it really returns the upper
          bound opposed to the array object's 'Length' property, which will return the
          number of items in the array.

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

          Comment

          Working...