String Concatenation: The
Ampersand &
You can combine strings with
the ampersand character. It acts
as a glue between one or more
strings to create one large
string. See our Strings
Lesson for
a more detailed look at strings
and string concatenation. Below is
an example of the ampersand
concatenating two strings.
ASP Code:
<%
Dim myString
myString = "One String"
myString = myString & "
another string"
Response.Write(myString)
%> |
Display:
|
One String another string |
ASP Comments: The Apostrophe '
The apostrophe is used to
prevent the ASP interpreter from
executing the text that follows.
In ASP there is only the single
line comment. Check out our ASP Comments
Lesson for
more information on comments.
Below is an example of the
apostrophe.
ASP Code:
<%
'This is a comment.
%> |
Spanning Multiple Lines: The
Underscore _
Sometimes you can't fit all
your ASP code on one line because
your string is too long, you are
tabbed over too far or you just
want to break up the statement.
With the use of the underscore you
can tell the ASP interpreter that
you line of code continues to the
next line. This allows you to have
a single ASP statement span
multiple lines.
In the following example we
have such a huge piece of code we
need to span over three lines.
ASP Code:
<%
Response.Write("This is
probably the longest "&_
"string to be typed out on
this page and maybe "&_
"even this whole tutorial on
ASP!!!")
%> |
Display:
|
This is probably the longest
string to be typed out on this
page and maybe even this whole
tutorial on ASP!!! |
Squishing Onto a Line: The
Colon :
Sometimes you want to reduce
the human readability of your code
because you're either mentally
disturbed or insane. The colon
will help you satiate your crazy
desires by letting you put
multiple lines of ASP code onto a
single line. Below is an example
of how to make your code very hard
to read!
ASP Code:
<%
Dim x
Dim y
Dim z
x=3 : y=25 : z=x-y : y=x*z :
z=x*x-z+y : y=5*3*z*2/x
%> |
Calling Methods: The Period .
ASP allows for Object Oriented
Programming and these objects have
methods that can only be called by
first stating the object, then
placing a period and finally
calling the method by its name.
The form for using the period is:
myObject.MethodName()
If you would like to learn more
about ASP objects see our ASP
Object Lesson.
Declaring ASP Code: The
Percentage %
ASP files are often made up of
a combination of HTML, some other
stuff and ASP. The tag that you
use to stake out an area for your
ASP code does not resemble normal
HTML tags. Instead it is almost
like just an opening tag that can
be stretched very, very, very
long. You must use this character
sequence to insert ASP code into
your ASP files.
ASP Code:
<html>
<body>
<%
'My ASP code goes here.
%>
</body>
</html> |
Write Shortcut: The Percentage
Equal %=
The percentage equal special
character sequence is a modified
version of the standard ASP code
marker. This modification allows
for quick access to the
Response.Write() method that is
used to write information to the
web browser.
This shortcut can be used to
quickly print numbers, strings,
variables and anything else you
might throw at it. Below is a few
examples of using this shortcut.
ASP Code:
<%=2%> <br />
<%="Hello"%> <br />
<%=Date()%> |
Display: