Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - VBScript: Array Functions
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

VBScript: Array Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-05-05

    Table of Contents:
  • VBScript: Array Functions
  • Arrays
  • Multi-Dimensional Arrays
  • Array Functions
  • UBound and LBound
  • The Join Function

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    VBScript: Array Functions - UBound and LBound


    (Page 5 of 6 )

    If you need to know the size of an array, then you need the UBound and LBound functions. The LBound returns the smallest index number, which of course will always be 0. The UBound returns the largest index number. Note that while UBound might return the highest index number, there may not be a value in that index. Here they are at work:


    <html>

    <body>

    <script type="text/vbscript">

    dim super(5)

    super(0)="I"

    super(1)="Am"

    super(2)="Iron"

    super(3)="Man"

    document.write(UBound(super))

    document.write("<br />")

    document.write(LBound(super))

    </script>

    </body>

    </html>

    This gives the result:

      5

      0

    Filtering Function

    You can use the Filter function to filter the items in an array. Let's say you have a list of some He-Man heroes and villains and you want to see all of the ones with the word "man" in their name (there are more than you think):


    <html>

    <body>

    <script type="text/vbscript">

    dim grayskull(5),a

    grayskull(0)="He-Man"

    grayskull(1)="Man at Arms"

    grayskull(2)="Skeletor"

    grayskull(3)="Evil Lynn"

    grayskull(4)="Stinkor"

    a=Filter(grayskull,"Man")

    document.write(a(0) & "<br />")

    document.write(a(1) & "<br />")

    document.write(a(2) & "<br />")

    document.write(a(3) & "<br />")

    document.write(a(4))

    </script>

    </body>

    </html>

    This returns the following names:

      He-Man

      Man at Arms

    Now if you are looking for the elements that DO NOT contain "man," you simply add false to the equation, like this:


    <html>

    <body>

    <script type="text/vbscript">

    dim grayskull(5),a

    grayskull(0)="He-Man"

    grayskull(1)="Man at Arms"

    grayskull(2)="Skeletor"

    grayskull(3)="Evil Lynn"

    grayskull(4)="Stinkor"

    a=Filter(grayskull,"Man",false)

    document.write(a(0) & "<br />")

    document.write(a(1) & "<br />")

    document.write(a(2) & "<br />")

    document.write(a(3) & "<br />")

    document.write(a(4))

    </script>

    </body>

    </html>

    This results in:

      Skeletor

      Evil Lynn

      Stinkor

    More Windows Scripting Articles
    More By James Payne


       · Thanks for stopping by to read my article. In this episode we discuss Array and...
     

    WINDOWS SCRIPTING ARTICLES

    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway