Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Working With Arrays in VBScript
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Working With Arrays in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-01-05

    Table of Contents:
  • Working With Arrays in VBScript
  • Creating Arrays
  • Using Values from an Array
  • Methods for working with arrays
  • Dynamic and Multidimensional Arrays

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working With Arrays in VBScript - Creating Arrays


    (Page 2 of 5 )

    Arrays are typically created using the Dim statement.  The Dim statement reserves space in memory for a provided variable reference.  This statement is extended to allow creation of arrays.

    Try to think of an array as a column in a spreadsheet.  An array contains several data elements, much like the individual cells in a spreadsheet.  You could, for instance, have a list of names.

    Dim arrNames(2)

     

    arrNames(0) = "John Doe"

    arrNames(1) = "Jane Smith"

    arrNames(2) = "Dick Tracy"

    Here the Dim statement is used to create an array.  This is denoted by the number in parenthesis that follows the array name.  This number provides the Upper Boundary of the array.

    Data elements are stored in an array in a zero-based fashion.  This means that each element can be referenced in the array by a number starting from zero.  So an array with an upper boundary of 2 can hold three elements: 0, 1, and 2.

    We can assign values to these elements in just this fashion.  Notice how I’ve used the array name followed by the element’s number to assign these values.  Values in an array are read/write.

    Dim arrNumbers(2)

     

    arrNumbers(0) = 5

    arrNumbers(1) = 25

    arrNumbers(2) = 7

    The first example created a String Array, or an array containing string values.  You can just as easily create an Integer Array, or an array containing integers.  Any valid variant value can be assigned to an array element.

    Dim arrNames(2)

     

    arrNames(3) = "Rob Dunham"

    Be aware of your array’s boundaries.  Attempting to assign a value like this will result in a “subscript out of range” error because there is no element 3 in this array.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT