Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Variant array is empty problem

I have written this code and for some reason i cannot make the logic
work correctly.

Dim site()
If IsEmpty(site) Then
test = 1
Else
test =0
End If

It always makes test = 0 when I am trying to get it to trip the logic
trap and create an output of test = 1. Thanks in advance for any help.

-perry

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,886
Default Variant array is empty problem

Hi

Try

Dim Site as Variant, Test as Long
If IsEmpty(site) Then
test = 1
Else
test =0
End If

--
Regards

Roger Govier


wrote in message
ps.com...
I have written this code and for some reason i cannot make the logic
work correctly.

Dim site()
If IsEmpty(site) Then
test = 1
Else
test =0
End If

It always makes test = 0 when I am trying to get it to trip the logic
trap and create an output of test = 1. Thanks in advance for any
help.

-perry



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Variant array is empty problem

Perry,

Try code like following. The IsArrayEmpty function is one of about 25 array
information and manipulation procedures at
http://www.cpearson.com/excel/vbaarrays.htm/

Sub AAA()

Dim V As Variant
'''''''''''''''''''''''''''''''
' do something with V
'''''''''''''''''''''''''''''''
If IsArray(V) = True Then
If IsArrayEmpty(Arr:=V) = True Then
MsgBox "Array is empty and unallocated."
Else
MsgBox "Array contains " & _
Format(UBound(V) - LBound(V) + 1, "#,##0") & " elemnts."
End If
End If

End Sub


Public Function IsArrayEmpty(Arr As Variant) As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''
' IsArrayEmpty
' This function tests whether the array is empty (unallocated). Returns TRUE
or FALSE.
'
' The VBA IsArray function indicates whether a variable is an array, but it
does not
' distinguish between allocated and unallocated arrays. It will return TRUE
for both
' allocated and unallocated arrays. This function tests whether the array
has actually
' been allocated.
'
' This function is really the reverse of IsArrayAllocated.
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''

Dim Var As Variant
Err.Clear
On Error Resume Next
If IsArray(Arr) = False Then
' we weren't passed an array, return True
IsArrayEmpty = True
End If

' Attempt to get the UBound of the array. If the array is
' unallocated, an error will occur.
Var = UBound(Arr, 1)
If (Err.Number < 0) Or (Var < 0) Then
IsArrayEmpty = True
Else
IsArrayEmpty = False
End If

End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

wrote in message
ps.com...
I have written this code and for some reason i cannot make the logic
work correctly.

Dim site()
If IsEmpty(site) Then
test = 1
Else
test =0
End If

It always makes test = 0 when I am trying to get it to trip the logic
trap and create an output of test = 1. Thanks in advance for any help.

-perry



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
ReDim Object array as parameter of Variant array Peter T Excel Programming 4 May 10th 05 02:11 PM
Variant Array Steph[_3_] Excel Programming 1 June 2nd 04 01:29 AM
variant array containing cel adresses convert to actual ranges-array Peter[_21_] Excel Programming 5 December 10th 03 09:50 PM


All times are GMT +1. The time now is 01:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"