Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


howto check if dynamic array is empty

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,53402
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> howto check if dynamic array is empty
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 howto check if dynamic array is empty - 11/9/2007 2:08:00 AM   
  acki4711

 

Posts: 2
Score: 0
Joined: 11/7/2007
Status: offline
Hi all
The following code gives you "index out of range"

dim arr()

if ubound(arr) > 0 then
  wscript.echo ("not empty")
else
  wscript.echo ("empty")
end if

How to check if dynamic array is empty (not dimensioned) ?
TIA
acki
 
 
Post #: 1
 
 RE: howto check if dynamic array is empty - 11/9/2007 2:35:08 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi acki4711,

Dim-ing a variable with () indicates an array of fixed dimensions/size(s). Empty brackets
make no sense; if you want a fixed array, you want some number(s) between them.

Use Dim <VarName> or (better) Dim <VarName> : <VarName> = Array() to declare/define/initialize
an empty dynamic array. The UBound for an empty array will be -1 (not 0 as your code assumes).

Some code to see what I mean:


      

May all your arrays be dynamic!

ehvbs

(in reply to acki4711)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> howto check if dynamic array is empty Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts