VBScript: Array Functions
(Page 1 of 6 )
In our last VBScript tutorial we covered the string functions that VBScript has to offer. While there aren’t quite as many Array functions as there were with the earlier date functions, never fear: I still haven’t covered the formatting, string, conversion, and other functions. So get ready, because (as usual) we still have plenty of ground to cover.
An Array of Arrays
If you have made it his far in the series then you no doubt know all about variables and arrays. But just in case, I will briefly cover them here. Feel free to skip to the section labeled VBScript Array Functions if you are familiar with variables and arrays and do not need a refresher. Or if you enjoy the pain, read on!
Variables
Variables are containers in which you store data. In that sense, they're similar to a box. You can put data in them, you can take data out and put it back in, you can take data out and put new data in, or you can delete the data within them. They are called variables because the data within them varies.
You declare variables in VBScript with the Dim statement. Here, we will declare some variables and give them a value:
<html>
<body>
<script type="text/vbscript">
Dim firstVariable
Dim secondVariable
firstVariable="13"
secondVariable="James"
</script>
</body>
</html>
The above code creates two variables, one namedfirstVariableand the other named secondVariable. We then store data in each one (13 and James respectively). Now let's do something with those variables:
<html>
<body>
<script type="text/vbscript">
Dim firstVariable
Dim secondVariable
firstVariable = 13
secondVariable = "James"
document.write("My IQ is " & firstVariable)
document.write("<br />My name is " & secondVariable)
</script>
</body>
</html>
The above code would print the following to the browser:
My IQ is 13
My name is James
You can also declare variables and use them in this manner:
<html>
<body>
<script type="text/vbscript">
Dim firstVariable, secondVariable
firstVariable = 13
secondVariable = "James"
document.write("My IQ is " & firstVariable)
document.write("<br />My name is " & secondVariable)
</script>
</body>
</html>
You get the same result, but save space by declaring the variables on the same line.
Next: Arrays >>
More Windows Scripting Articles
More By James Payne