Basic syntax
All ASP code is contained with two special tags: <% and %> These tags designate the start and end of some ASP code. There
can be multiple instances or blocks of ASP code, each denoted by these tags. Since ASP uses Visual Basic Script, similar
commands and syntax are shared between code examples in this course and the VBS course. Below is a comparison between VBScript
on the client side and VBScript used in ASP tags:
| Client-side VBScript |
ASP VBScript |
<SCRIPT LANGUAGE="VBScript">
dim mynumber
dim mystring
mynumber = 5
mystring = "Hello world"
</SCRIPT>
|
<%
dim mynumber
dim mystring
mynumber = 5
mystring = "Hello world"
%>
|
Another important item of basic syntax is comments. Commenting your code is a good idea because it lets you know what you're
trying to do in the code. This helps you fix errors in the future, as well as other people understand your code. Below is the
same script in the table above, but with comments.
<%
' here we are defining our variables with the dim statement.
' We could also use dim mynumber, my string Whatever you use is up to your personal preference
dim mynumber
dim mystring
' now we will assign values to our variables.
Mynumber = 5
' You must use quotation marks around strings
Mystring = "Hello World"
' and now we finish our ASP
%>
Comments are made by starting a line with the apostrophe (') character.