ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
Global.asa OnEnd Events Don't Run
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


How to Empty an Array

I recently got this question from a user working with arrays.

How do I easily assign an array to null? It's a string array, and I've tried: Array = Null, Array = Empty, Array = "" and I always get a Type Mismatch error.

I suppose I could build a custom function to cycle through the array and assign each part to "", but is there a VBScript function that already does this?

Well, while there isn't a built in VBScript array emptying mechanism, if you ReDim the array to the samne size without using the PRESERVE keyword, it achieves the desired result. So, assuming arrTest is your array, this code:

ReDim arrTest(UBound(arrTest))

will get the job done and you don't even have to loop through the array to do it.

Note: That just goes to show what I know... there actually is a VBScript array emptying mechanism! It's the Erase statement. It works with fixed arrays as well (which the ReDim statement doesn’t). So now you've got a choice of how to empty your arrays. Thanks to Zack Jones for giving me the heads up.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers