In general, an ASP contains HTML code mixed with server-side script. The server-side script programmatically determines what information will be returned to the user .
Example
This example uses the Now and Hour procedures contained in the <% and %> delimiters to determine the current time, and then greet the user with either "Good Morning" or "Good Day," depending on the time:<% if Hour(Now) < 12 then %> Good Morning. <% else %> Good Day. <% end if %>
If it is 8:00 A.M., the HTML returned to the user will be:
Good Morning.
Example
This example uses VBScript to test the value of a variable in an ASP file:<%Dim MyVar MyVar = 3 Select Case MyVar Case 1 %><BOLD>The value is one.</BOLD><% Case 2 %><BOLD>The value is two.</BOLD><% End Select%>
Example
This example displays the current time to the user:
The time here is now <%= Time %>.
If it is 8:34 A.M., the HTML returned to the user is:
The time here is now 8:34 AM.
Example
This example uses server-side script to determine whether it is morning or afternoon:<SCRIPT LANGUAGE=VBScript RUNAT=SERVER> Function ComputeAMPM() If Hour(Now) < 12 Then ComputeAMPM = "morning" Else ComputeAMPM = "afternoon" End If End Function </SCRIPT>
You can display the result directly from the HTML <SCRIPT> section by using the Response.Write method.
Example
This example displays a message based on the time of day:<SCRIPT LANGUAGE=VBScript RUNAT=SERVER> Response.Write "Time for your " & ComputeAMPM() & " classes." </SCRIPT>
If it is 6:00 A.M., the HTML returned to the user will be:
Time for your morning classes.
In the <SCRIPT> section, any code that is not contained in a procedure runs when the Web server processes the .asp file. Code in a procedure will not run until the procedure is explicitly invoked by server-side script.