How to Make a Counter In VBScript
A VBScript counter is a numeric variable that tracks the number of iterations in a loop. A counter commonly starts with a value of 0 and increases by 1 at the beginning of each iteration. You can create a counter by declaring a variable in your VBScript code with the "Dim" keyword. You can use the counter in a "for" loop by setting an initial value, a constraint and a factor for the counter to change by each iteration.
Instructions
-
-
1
Open your HTML file in a text editor, such as Windows Notepad.
-
2
Add the following code within the <head> section of your file to create a VBScript function with a counter variable:
<script type="text/vbscript">
function myFunction()
Dim counter
counter=0for counter=0 to 3
alert(counter)
nextend function
</script>The value of the counter increases with each iteration of the loop. The loop will popup 4 boxes, displaying the counter values of 0, 1, 2 and 3.
-
-
3
Add the following code after the <head> section to call the VBScript function when the <body> section of the HTML file loads:
<body onload="myFunction()">
-
4
Save the HTML file. Upload it to your Web server and refresh the page to load the counter.
-
1
Tips & Warnings
Client-side VBScript only works in the Internet Explorer Web browser.