WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: SewWrite on May 03, 2020, 11:46:08 AM

Title: Is there a function to test if an array is empty?
Post by: SewWrite on May 03, 2020, 11:46:08 AM
I'm stumbling over what I thought would be easy. I return selected items from a dialog with Report View. I need to be able to have nothing selected but I can't seem to find how to test for it so the rest of my code fails when it bumps into the empty array.(I won't bore you with the list of what I've tried. It's long.) Is there a function I'm missing? If not, how can I test for an empty array?

Thanks for you help!
Title: Re: Is there a function to test if an array is empty?
Post by: td on May 03, 2020, 12:56:27 PM
It depends on what you mean by "empty".   If you mean by "empty" that an array has no rank (no dimensions) then the task is simple. 

Code (winbatch) Select
aEmpty = ArrDimension(0)
if ArrInfo(aEmpty, 1) then strEmpty = 'No'
else strEmpty = 'Yes'
Message('Is the Array "empty"?', strEmpty)


If you are referring to a dimensioned array with uninitialized elements, you would need to check each element with the IsDefined function.
Title: Re: Is there a function to test if an array is empty?
Post by: SewWrite on May 03, 2020, 04:52:33 PM
Thanks... that worked. Duh! Simple once you know the answer. Now onto the next bug. :)