In this lesson we will write our fist VBScript code and run the same in Intenet Explorer.
Almost every programming language book starts with a hello world program that output, usually on the screen, the string "Hello World. We will do the same in this lesson.
We write the VBScript code in an HTML file and save the same with .htm or .html extension. For the following Hello World example; open the text editor of your choice, type the following and save the file with .htm or .html extension:
<title>VBScript Hello World!</title>
Now open the above in Internet Explorer. The above code would output the following in Internet Explorer:
The above code works as follows:
- The <script> tags are actually HTML. They tell the browser to expect and process the enclosed text as a script. We specify the language, in this case text/vbscript, using the type attribute.
- document.write("Hello World!") outputs the text "Hello World!". We use the same syntax to write text to a web page in our VBScript code. This, actually, is a method of the document object. Mehods will be discussed in one of the coming lessons.
- Note that we have enclosed the Hello World! text in quotes. This is how we deal with strings / text in our VBScript code. More on string later. Keep reading...
Next >>> Lesson No. 3: VBScript Basics