Link to home
Start Free TrialLog in
Avatar of Chris Jones
Chris JonesFlag for United States of America

asked on

check array to see if its empty

i have a asp page that i need to check an array to see if it has not values in it using vb
Avatar of carazuul
carazuul

Hi blingtec903,

If you're checking if a variable length array has any entries in it you can use:

If array.GetLength(0) > 0 Then

If you're checking each of the values of a fixed length array for values then you can use:

Dim i as integer

For i=0 array.GetLength(0)
      If IsDbNull(array(i)) Or array(i) = Nothing Then

      End If
Next i

Regards,


carazuul

With an array, check for null and then length. this can easily be placed into a function with a Boolean return value. for example ArrayIsNotEmpty().
Dim myArray() As Object = {1, 2, 3}
 
'if array first check for Null
If Not (myArray Is Nothing) Then
    If (myArray.Count() > 0) Then
'Do processing
    End If
End If

Open in new window

With an array, check for null and then length. this can easily be placed into a function with a Boolean return value. for example ArrayIsNotEmpty().

Dim myArray() As Object = {1, 2, 3}

'if array first check for Null
If Not (myArray Is Nothing) Then
    If (myArray.Count() > 0) Then
           'Do processing
    End If
End If
Avatar of Chris Jones

ASKER

ok i have a array of 11 elements and i need to know if it is completly empty

EXAMPLE
GOOD ARRAY
0  --  12
1  --  Nothing
2  --  22
i still will need these values i only need to do a prossess if nothing is checked

BAD ARRAY
0 -- NOthing
1  -- Nothing
2  -- Nothing
the code posted gives an error count is not a member of my array
            'if array first check for Null
            If Not (temparray Is Nothing) Then
                If (temparray.Count() > 0) Then
                    'Do processing
                End If
            End If
 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sughill
sughill

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok this works thnaks
great answer works great fast response