Another great thing with ASP is you are not limited to simply VB - you can 'hard-code' HTML too. Take a look at this example:
'declare the variables
Dim bTest, sName, sVariable
'set their values...
bTest = True
sName = "Fred"
sVariable = "hello James"
%>
<table border="1">
<tr><td><%
If bTest Then
Response.Write sVariable
Else
Response.Write sName
End If
%></td></tr>
</table>
What this code does is display some text in a HTML table. If the variable bTest is true (which, in this instance is the case), sVariable is placed in between the <td> and </td> tags. Otherwise, sName is outputted there instead. Not sure exactly what is happening? Take a look in your browser. Then, right click and select View Source. What you should see is this:
<table border="1">
<tr><td>hello James</td></tr>
</table>
Another useful feature is that If...Then...Else statements don't only apply to Visual Basic. You can use them to selectively output existing HTML. Let's convert a previous example to using this syntax:
<p>This is some different text</p>
<% Else %>
<p>This is text!</p>
<% End If %>
which does exactly the same thing. You might also find you want to simply output the value of a variable into some hard coded HTML. ASP provides a function for this too. Instead of using the <% and %> tags, use <%=VariableName%>. For example,
<p>Welcome, <%=sName%>
to VB Web!</p>
would insert the value of sName into the HTML, and is the same as
<p>Welcome, <% Response.Write
sName %> to VB Web!</p>
One final thing before we move on... When using the Response.Write statement you might find you want to include a quote (") within the string. You can do this in two ways. Either use the Chr(32) statement:
Response.Write "<p><font
color=" & Chr(34) & "#FF0000" & Chr(34) & ">Welcome!</font></p>"
or simply replace the single quote with a double quote:
Response.Write "<p><font
color=""#FF0000"">Welcome!</font></p>"
I'll leave it up to you to decide which is more elegant!
Comments