If I declare a dynamic array, e.g Dim emps(), and then later in my code, depending on certain conditions, the array will be ReDimmed, how can I determine whether the array has been ReDimmed or not?

Re: Dynamic Arrays by Han

Han
Wed Feb 11 08:13:06 CST 2004

Maybe Ubound() if you've not yet considered.

"AF" <anonymous@discussions.microsoft.com> wrote in message
news:DD979EC4-EF27-4819-A331-DE5766E47D94@microsoft.com...
> If I declare a dynamic array, e.g Dim emps(), and then later in my code,
depending on certain conditions, the array will be ReDimmed, how can I
determine whether the array has been ReDimmed or not?



Re: Dynamic Arrays by anonymous

anonymous
Wed Feb 11 08:26:07 CST 2004

Yes, I tried that before, but UBound gives a 'Subscript out of range' error when you pass it a dynamic array that hasn't been ReDimmed.

Re: Dynamic Arrays by Han

Han
Wed Feb 11 08:50:58 CST 2004

Exactly. Then maybe isArray().

"AF" <anonymous@discussions.microsoft.com> wrote in message
news:935E9A9E-0555-48AA-928F-CDA9D74747C3@microsoft.com...
> Yes, I tried that before, but UBound gives a 'Subscript out of range'
error when you pass it a dynamic array that hasn't been ReDimmed.



Re: Dynamic Arrays by anonymous

anonymous
Wed Feb 11 09:16:09 CST 2004

I've tried all of the built-in functions and they don't give me what I need. isArray returns True because the array has been declared. I can deal with this in other ways but I thought maybe there was a quick way that I wasn't seeing. Maybe not
Thanks anyway.

Re: Dynamic Arrays by Han

Han
Wed Feb 11 09:42:01 CST 2004

Umm I cannot imagine the condition both isarray and ubound don't work. If
the array is empty(var1()), isarray will return false. If true(var1(n)),
ubound will return something. If you want to know whether the array is
simply *touched* or not, that can go into very low level, and I don't
believe script can be a tool for that. Anyway lets wait more elegant
solution.

"AF" <anonymous@discussions.microsoft.com> wrote in message
news:975083FA-3CC3-4B29-A62E-A5AFE1FBC124@microsoft.com...
> I've tried all of the built-in functions and they don't give me what I
need. isArray returns True because the array has been declared. I can deal
with this in other ways but I thought maybe there was a quick way that I
wasn't seeing. Maybe not.
> Thanks anyway.



Re: Dynamic Arrays by Joe

Joe
Wed Feb 11 10:47:48 CST 2004

Hi,

"AF" <anonymous@discussions.microsoft.com> wrote in message
news:975083FA-3CC3-4B29-A62E-A5AFE1FBC124@microsoft.com...
| I've tried all of the built-in functions and they don't give me what I
need. isArray returns True because the array has been declared. I can deal
with this in other ways but I thought maybe there was a quick way that I
wasn't seeing. Maybe not.
| Thanks anyway.

There was a thread on this sometime back. The same problem occurs when
creating a variant array through Split("") and similar functions. There are
two issues: an array with a nominal dimension, but no declared elements
(i.e., ubound(...) is -1), and an array with no declared dimensions (i.e.,
ubound error). The only solution from the last thread was a library
function. Here's a simple one that I use to check data passed to my WSC
library methods.

function IsBndArray (uxArray)
' exposed utility method
' global variables: none
' calls: none

isBndArray= false: if NOT isarray(uxArray) then exit function

on error resume next
isBndArray= (ubound(uxArray)>vbTrue)
on error goto 0
end function

Joe Earnest



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 01-19-04



Re: Dynamic Arrays by Michael

Michael
Wed Feb 11 21:24:53 CST 2004

AF wrote:
> If I declare a dynamic array, e.g Dim emps(), and then later in my
> code, depending on certain conditions, the array will be ReDimmed,
> how can I determine whether the array has been ReDimmed or not?


Three ways to define and initialize an empty, redim-able arry that avoid a
runtime error on the ubound(myArray) function...


option explicit

dim myArray() 'dynamic array
redim myArray(-1) 'redim'd immediately as an empty array
'...
'..
'.
wscript.echo ubound(myArray)

dim myArray2 'a variant
myArray2 = Array() 'initialized to an empty array
'...
'..
'.
wscript.echo ubound(myArray2)

redim myArray3(-1) 'redim'd initially as an empty array
'...
'..
'.
wscript.echo ubound(myArray3)



--
Michael Harris
Microsoft.MVP.Scripting

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

TechNet Script Center Sample Scripts
http://www.microsoft.com/technet/scriptcenter/default.asp
Download in HTML Help format (searchable and indexed)
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


Re: Dynamic Arrays by anonymous

anonymous
Thu Feb 12 07:06:06 CST 2004

Thanks!