Bookmark and Share

VBScript Syntax

If you are an expert Visual Basic programmer then you will be pleasantly surprised to know that VBScript has nearly identical syntax to Visual Basic. However, if you are a programmer or only know the basics of HTML then VBScript code may look a little strange to you. This lesson will point out the most important things about VBScript syntax so you can avoid common potholes.

Advertise on Tizag.com

VBScript: No Semicolons!

If you have programmed before, you will be quite accustomed to placing a semicolon at the end of every statement. In VB this is unnecessary because a newline symbolizes the end of the statement. This example will print out 3 separate phrases to the browser. Note: There are 0 semicolons!

VBScript Code:

<script type="text/vbscript">
document.write("No semicolons")
document.write(" were injured in the making")
document.write(" of this tutorial!")
</script>

Display:

No semicolons were injured in the making of this tutorial!

VBScript Accessing Methods

To access methods and properties contained within an object, like the Document object, you use a period "." after the object and before the name of the method.

So far in this tutorial we have been using the write method that is a part of the document object and the syntax for doing this is:

  • document.write(string_here)

VBScript Multiple Line Syntax

As we stated above, the syntax is that placing a newline in your VBScript signifies the end of a statement, much like a semicolon would. However, what happens if your code is so long that absolutely must place your code on multiple lines?

Well, Microsoft has included a special character for these multiple lines of code: the underscore "_". The following example contains an exceptionally long write statement that we will break up string concatenation and the multiple line special character.

VBScript Code:

<script type="text/vbscript">
document.write("This is a very long write " &_
"statement that will need to be placed onto three " &_
"lines to be readable!")
</script>

Display:

This is a very long write statement that will need to be placed onto three lines to be readable!

VBScript Syntax Review

VBScript is a client-side scripting language that is based off of Microsoft's Visual Basic programming language. No semicolons are used at the end of statements, only newlines are used to end a statement.

If you want to access methods of an object then use a period "." and an underscore is used for statements that go multiple lines!

Bookmark and Share




Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials