VBScript: Plain and Simple - Writing Our First VBScript
(Page 2 of 4 )
If you have ever read anything about any programming languages they give you that really dumb "Hello World" program. We're not going to do it. The world can go find someone else to say hello to for all we care. So let's write a real program, a man's program, a man's man type of program, one that chews tobacco, smokes beer, and drinks nicotine:
<html>
<body>
<script type="text/vbscript">
document.write("Angelina Jolie leave that nerd Brad Pitt.")
</script>
</body>
</html>
Okay Einstein, let's see if you can guess what the output would be. Give up? Well this is what that little snippet of code would have printed out:
Angelina Jolie leave that nerd Brad Pitt.
In the above code, you will notice several things:
We wrote VBScript inside our HTML (hence me suggesting you go and learn it if you don't already know it).
You must use the <script type="text/vbscript"> in your code. This is what tells your browser what language you are speaking in. Without it, it will think you are speaking Swahili.
The way we write text to the browser is with document.write.
Another thing you may have noticed if you are familiar with other programming languages is that you do not end statements with the semi-colon (;). In VBScript, the end of a statement is when you start a new line. This, of course, can be somewhat problematic as you could guess. Let's say we wanted to say more to Angelina. Well, we couldn't simply just type on forever. We could do this:
<html>
<body>
<script type="text/vbscript">
document.write("Angelina Jolie leave that nerd Brad Pitt.")
document.write(" What does he have that I don't?")
document.write(" Aside from looks, money, and a six-pack of abs.")
document.write(" I have a six pack of Mountain Dew...")
</script>
</body>
</html>
This would print out
Angelina Jolie leave that nerd Brad Pitt. What does he have that I don't? Aside from looks, money, and a six pack of abs. I have a six pack of Mountain Dew...
You could also achieve the same affect using concatenation (or joining) "&" and the multiple line special character (the underscore"_"). Here it is in code.
<html>
<body>
<script type="text/vbscript">
document.write("Angelina Jolie leave that nerd Brad Pitt." &_
" What does he have that I don't? " &_
"Aside from looks, money, and a six-pack of abs. " &_
"I have a six pack of Mountain Dew...")
</script>
</body>
</html>
This code results in the same thing as our above code:
Angelina Jolie leave that nerd Brad Pitt. What does he have that I don't? Aside from looks, money, and a six pack of abs. I have a six pack of Mountain Dew...
Next: Variables...In....Space! >>
More BrainDump Articles
More By James Payne