PC Review


Reply
Thread Tools Rate Thread

array variable is empty?

 
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      6th Oct 2006
Hi.

Pretend I have an integer array variable that I'm using for somthing,
arIntArray()

There's a loop that goes through and populates the elements of that array,
which are a subset of the columns in the spreadsheet.

If it turns out that there aren't any columns which meet the condition which
populates the array, is there a quick way to determine that the array is
still empty?

Ubound(arIntArray) fails, becuase it's undefined. Is Nothing and Null also
produced errors.

If needed, I can put in a Boolean flag to set if the array gets populated,
but it seems like there is likely another way.

Thanks.
Mark
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      6th Oct 2006
Sub CCC()
Dim arIntArray() As Integer
Dim ub As Long, res As Variant
If Rnd() < 0.5 Then _
ReDim arIntArray(1 To 5)
On Error Resume Next
ub = UBound(arIntArray)
res = Err.Number
On Error GoTo 0
If res <> 0 Then
' not dimmed
MsgBox "Not Dimensioned"
Else
' process the array
MsgBox "Dimensioned"
End If
End Sub

--
Regards,
Tom Ogilvy


"mark" wrote:

> Hi.
>
> Pretend I have an integer array variable that I'm using for somthing,
> arIntArray()
>
> There's a loop that goes through and populates the elements of that array,
> which are a subset of the columns in the spreadsheet.
>
> If it turns out that there aren't any columns which meet the condition which
> populates the array, is there a quick way to determine that the array is
> still empty?
>
> Ubound(arIntArray) fails, becuase it's undefined. Is Nothing and Null also
> produced errors.
>
> If needed, I can put in a Boolean flag to set if the array gets populated,
> but it seems like there is likely another way.
>
> Thanks.
> Mark

 
Reply With Quote
 
John Coleman
Guest
Posts: n/a
 
      6th Oct 2006
I don't know if there is anything built in. You can roll your own with
error trapping:

Function IsEmptyArray(A As Variant) As Boolean
Dim test As Long
On Error GoTo must_be_empty
test = UBound(A)
IsEmptyArray = False
Exit Function
must_be_empty:
IsEmptyArray = True
End Function

Sub test()
Dim A() As Long
Dim B() As Long
ReDim B(1 To 2)
B(1) = 5
MsgBox IsEmptyArray(A)
MsgBox IsEmptyArray(B)
End Sub

Hope that helps

-John Coleman
mark wrote:
> Hi.
>
> Pretend I have an integer array variable that I'm using for somthing,
> arIntArray()
>
> There's a loop that goes through and populates the elements of that array,
> which are a subset of the columns in the spreadsheet.
>
> If it turns out that there aren't any columns which meet the condition which
> populates the array, is there a quick way to determine that the array is
> still empty?
>
> Ubound(arIntArray) fails, becuase it's undefined. Is Nothing and Null also
> produced errors.
>
> If needed, I can put in a Boolean flag to set if the array gets populated,
> but it seems like there is likely another way.
>
> Thanks.
> Mark


 
Reply With Quote
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      6th Oct 2006
thanks, Tom...

so it's basically just seeing if checking the UBound throws an error.

got it.

"Tom Ogilvy" wrote:

> Sub CCC()
> Dim arIntArray() As Integer
> Dim ub As Long, res As Variant
> If Rnd() < 0.5 Then _
> ReDim arIntArray(1 To 5)
> On Error Resume Next
> ub = UBound(arIntArray)
> res = Err.Number
> On Error GoTo 0
> If res <> 0 Then
> ' not dimmed
> MsgBox "Not Dimensioned"
> Else
> ' process the array
> MsgBox "Dimensioned"
> End If
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "mark" wrote:
>
> > Hi.
> >
> > Pretend I have an integer array variable that I'm using for somthing,
> > arIntArray()
> >
> > There's a loop that goes through and populates the elements of that array,
> > which are a subset of the columns in the spreadsheet.
> >
> > If it turns out that there aren't any columns which meet the condition which
> > populates the array, is there a quick way to determine that the array is
> > still empty?
> >
> > Ubound(arIntArray) fails, becuase it's undefined. Is Nothing and Null also
> > produced errors.
> >
> > If needed, I can put in a Boolean flag to set if the array gets populated,
> > but it seems like there is likely another way.
> >
> > Thanks.
> > Mark

 
Reply With Quote
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      7th Oct 2006
> I don't know if there is anything built in. You can roll your own with
> error trapping:



something like that is what I was planning to do after seeing Ton's post,
but now that I look at it again, I see that I don't even need to do that.

The loop I have that populates the array by checking the columns, has two
variables, i and j .. i for the columns, and j for the columns that meet the
condition to be added to the array.

j is incremented in the interior of the loop, and if j never gets
incremented, then the array was never populated.

so it turns out that all I have to do is check whether j is still 0.

Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems Loading Large String Array into Array variable ExcelMonkey Microsoft Excel Programming 6 6th May 2009 11:20 PM
Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable Ronald R. Dodge, Jr. Microsoft Excel Programming 22 15th Dec 2008 09:19 PM
Make all variable in Array = Empty each click of a Button on Userf RyanH Microsoft Excel Programming 5 28th Jul 2008 07:39 PM
Is the array empty? Otto Moehrbach Microsoft Excel Programming 4 13th Jun 2004 03:35 AM
Problem trying to us a range variable as an array variable TBA Microsoft Excel Programming 4 27th Sep 2003 02:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 PM.