Looping Controls
VBScript support the For next loop constructs. The following example
consists of two forms. The first form accepts a start and end data
which it passes to the second from which generates an HTML page with
one game line for each day.
ForNextForm.asp
<html>
<head>
<title> For next form</title>
</head>
<body>
<h2>Weekly Client contacts</h2><br>
<form action="ForNextAction.asp" method=post>
<p> Please enter the first day of the week in the form mm/dd/yy
such as 07/01/78</br>
<input type="text" name="start">
<p> Please enter the last day of the week in the same form<br>
<input type=text name="end"><br>
<input type=submit>
<input type=reset>
</body>
</html>
ForNextAction.asp
<html>
<head>
<title>For next Action</title>
</head>
<body>
<h2> Weekly games for Harry Potter</h2>
<% varStart=Request.form("start")
varEnd=Request.form("end")
varStart=cdate(varStart)
varEnd=cdate(varEnd)
varNumberDays=(varEnd-varStart)
For varLineCounter=0 to varNumberdays
response.write "Games:"+varLinCounter+" ___________________"
response.write "<br><br><br>"
next
%>
signed ________________________
Harry Potter
</body>
</html>
How it works:
The program retrieves the start and end dates as strings, converts
them to dates through cdate function, then subtracts the start
from the end to determine the number of game lines to produce.
The then loops using the For Next control structure to print out
the lines.
|