iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 3, 2008
Poll: Which Web editor do you use?
About
 
July 3, 2008
Book Review: Head First JavaScript
WebReference.com
 
July 3, 2008
10 Things You Can Do With a Wiki
About
 
July 2, 2008
Web Host Reviews - 10 New Reviews
About
 
July 2, 2008
14 Reasons You Should Join a Social Network
About
 
July 1, 2008
Mark Boulton's Freelance Design Secrets
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /Visual Basic

VBScripts Tutorial II 

  Views:    8391
  Votes:    0
by Ahmad Permessur 4/29/04 Rating: 

Synopsis:

In this tutorial, we will learn how to define arrays in VBScripts
Pages: 
The Article

In my first tutorial on VBScripts, we’ve learned how to declare variables both implicitly and explicitly. Today we will learn how to define arrays. An array is a structure that holds many variables, all of the same data type. The array consists of so many elements, each element of the array capable of storing one piece of data (ie, a variable).

VBScript allows you to create arrays with up to 60 dimensions. A one-dimensional array is like a column of tabular data; a two-dimensional array is like a spreadsheet with rows and columns; and a three-dimensional array is like a 3D grid that takes time and space into account.

You could create a one-dimensional array from a single column of tabular data. If there were 20 data points in the column, you could declare the array as follows:

Dim myArray(19)

Note: Arrays always begin at 0 and end at the number of data points in the array minus 1. Therefore, an array with 20 data points is initialized as Array_Name(19).

You could create a multi-dimensional array from the cells of a spreadsheet. If the spreadsheet has three columns, each with five rows of data points, you could declare the array as follows:

Dim myArray(2,4)

If you want to get the value of a specific cell in the spreadsheet, you could use the following:

myValue = Array_Name(columns -1, rows -1)

In this statement, columns is the column position of the cell, and rows is the row position of the cell, so if you want to know the value of the cell in column 1, row 4, you could use the following:

myValue = myArray(0,3)

Although these sample arrays have fixed sizes, you can also size arrays dynamically. This allows you to use input from users to drive the size of the array. Here's how to declare a dynamic array:

Dim dynamicArray()

Later you can tell VBScript the size of the array by using the ReDim function in one of these two ways:

ReDim dynamicArray(iCount - 1)

ReDim dynamicArray(columnCount - 1, rowCount - 1)

To determine the size of an array at any time, you can use the UBound function, which returns the array's upper boundary. The following sample returns the upper boundary of the array in a message box:

<HTML>
<HEAD>
<TITLE>Example</TITLE>
</HEAD>
<BODY>

<!--
<SCRIPT LANGUAGE="VBScript">

Dim myArray(99)

Dim x

For x = 0 to UBound(myArray)

     myArray(x) = "Initial"

Next

Msgbox "The upper boundary of the array is" & UBound(myArray)
-->
</SCRIPT>

</BODY>
</HTML>


You can test the above VBScripts by copying the above code and pasting it in notepad or any text-editor of your choice and save it as .HTML file to be executed by your browser.

Pages: 



 
  Sponsors