VBScript: Plain and Simple - Variables...In....Space!
(Page 3 of 4 )
Variables are containers that you store data in. 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 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.
Before you can use any variables, you must declare them. You do so 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 named firstVariable and 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 BrainDump Articles
More By James Payne