Array question

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

    #1

    Array question

    I have an array defined as Dim cLengths() as long. How
    could I test to see if the array is not empty. When I try

    For I=0 to Ubound(cLengths )
    .......
    Next I

    It gives me an error if it is empty.
  • Chris

    #2
    Re: Array question

    cLengths.GetUpp erBounds()

    Chris

    "HLong" <anonymous@disc ussions.microso ft.com> wrote in message
    news:03f001c556 6c$9d595020$a60 1280a@phx.gbl.. .[color=blue]
    >I have an array defined as Dim cLengths() as long. How
    > could I test to see if the array is not empty. When I try
    >
    > For I=0 to Ubound(cLengths )
    > .......
    > Next I
    >
    > It gives me an error if it is empty.[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Array question

      "HLong" <anonymous@disc ussions.microso ft.com> schrieb:[color=blue]
      >I have an array defined as Dim cLengths() as long. How
      > could I test to see if the array is not empty. When I try
      >
      > For I=0 to Ubound(cLengths )
      > .......
      > Next I
      >
      > It gives me an error if it is empty.[/color]

      \\\
      If IsArray(Lengths ) Then
      ...
      End If
      ///

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

      Comment

      • Cor Ligthert

        #4
        Re: Array question

        HLong,

        I never use that Ubound

        I use forever in an inedexed loop for an array or a collection

        for i as integer = 0 to array.length - 1 or collection.coun t -1
        ............... ......
        Next

        I hope this helps,

        Cor


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Array question


          Cor,

          "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
          > I never use that Ubound
          >
          > I use forever in an inedexed loop for an array or a collection
          >
          > for i as integer = 0 to array.length - 1 or collection.coun t -1
          > ............... .....
          > Next[/color]

          This won't solve the problem. Still, a 'NullReferenceE xception' is thrown
          if the array variable doesn't point to an array object. Consequently you'll
          have to check if an array has been assigned prior to iterating over the
          array's items and determining its length:

          \\\
          If IsArray(Lengths ) Then
          ...
          End If
          ///

          - or -

          \\\
          If Not Lengths Is Nothing Then
          ...
          End If
          ///

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

          Comment

          Working...