Hello, World (and more) !

Now let's write the ubiquitous first program, Hello World.

<HTML>
<HEAD>
<TITLE>Hello, World !</TITLE>
</HEAD>
<BODY>
<%
Response.Write "Hello, World!"
%>
</BODY>
</HTML>

As you can see above, we have enclosed a single line of VBScript within the opening and closing tags. It says,

Response.Write "Hello, World!"

This statement displays the string "Hello, World!" on the webpage.

Another way...

Let us try that in a different way that is shorter than this one.

<HTML>
<HEAD>
<TITLE>Hello, World !</TITLE>
</HEAD>
<BODY>
<%= "Hello, World!" %>
</BODY>
</HTML>

Notice the presence of the = sign just after the <%. It has a similar effect to that of the Response.Write statement.

Displaying the Date...

Now let us go one step further, and make a page that tells you the date today!

<HTML>
<HEAD>
<TITLE>Hello, World !</TITLE>
</HEAD>
<BODY>
<%= Date %>
</BODY>
</HTML>

Using the function Date gives you the current date. And the function, Time returns the time. To get both, use the function, Now.

The following code shows how the Now function is used.

<HTML>
<HEAD>
<TITLE>Hello, World !</TITLE>
</HEAD>
<BODY>
<%
Response.Write Now
%>
</BODY>
</HTML>

And the output:

...and more

You can also get the individual elements, Year, Date, Month, Hour, Minute & Second of the time by using the above functions.

<HTML>
<HEAD>
<TITLE>Hello, World !</TITLE>
</HEAD>
<BODY>
<%
Response.Write "Year: " & Year (Now)
Response.Write "Month: " & Month (Now)
Response.Write "MonthName: " & MonthName (Month(Now))
Response.Write "Hour: " & Hour (Now)
Response.Write "Minute: " & Minute (Now)
Response.Write "Second: " & Second (Now)
%>
</BODY>
</HTML>

Notice the mixing of plain text and VBScript code. With this beginning, let us now move on to handling variables, constants, and various constructs.

« Chapter 1 Chapter 3 »