Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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 - Using Values from an Array


    (Page 3 of 5 )

    Getting the data from an array is as easy as assigning the values to the array.  You’ll just need to use the array reference along with the number of the element for which you wish you read the value.

    WScript.Echo "Hello,", arrNames(2) & "."

    The arrNames(2) reference returns the value of the third element in the arrNames array, which contains the string “Dick Tracy”.  This results in the following output.

    Hello, Dick Tracy.

    Frequently you will want to process each element in an array.  To do this, you’ll want to iterate, or move through the array one element at a time.  This is typically done using a For…Next structure to loop through each element of the array.

    For i = 0 To UBound(arrNames)

       WScript.Echo arrNames(i)

    Next

    In this example, I’ve introduced VBScript’s UBound function.  UBound returns the upper most boundary of an array.  In this case, it is the number 2.  Thus, the For…Next loop will move through each integer value from 0 to 2, assigning that value to the variable i.

    The first time through, the loop will print the value of arrNames(0); the second time arrNames(1); and so on.  This method allows you to specify a starting and ending number so you can return any specific range of elements.

    For Each strName In arrNames

       WScript.Echo strName

    Next

    You can also use VBScript’s For Each structure.  This will simply iterate through each element in the array, in order.

    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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek