The problem with VBScript is that it can be used for all sorts of different things.
- controlling HTML like Javascript
- hypertext applications
- administrative scripting
- active server pages (ASP)
- It is also a programming language so it can be used for generic programming.
Most authors will try to cover everything and concentrate on their own specialist topic. In administrative scripting, for instance, it is just a matter of knowing what the classes and methods are called. I normally find that I have to pick up bits and pieces from all over the place, just to write a script. You will probably need to know FSO, network and WMI. You can experiment with quite a lot of the admin stuff with two PCs linked by a crossover cable.
In HTML and HTAs, you just need to access the buttons etc and you're away. There is a script debugger MSE which comes with Office. Quite useful when you have nothing else.
VBScript also has some half baked classes without inheritence. This feature is very badly documented in all books/websites. It is, however, a lot easier to use than Javascript and it is case independent i.e.
LegEnd is the same as legend
NotIce is the same as notice
At a guess, most of the authors don't have an OO background and don't find any need for classes. I've yet to see a book that tells you all of the following:
a) The instance is called "me" (equivalent of this in Javascript). The MS documentation/website doesn't tell you this either. If, however, you have a VB background, this is common knowledge.
b) Putting a parameter in parenthesis forces a call by value
c) The difference between let and set (very simple actually - let is for basic types, set is for classes). Every single book I've seen describes the syntax but doesn't tell you the difference.
d) How to use let/set with multiple parameters. eg if you declare
Code:
property let vvv (a,b,c,d)
m_a = a
m_b = b
m_c = c
m_d = d
end property
It is used as
obj.vvv(a,b,c) = d
It is just pure trial and error to figure it out - you won't find this in any book or website.
e) const cannot be used in classes. Really strange that nobody tells you this or why this is so. I don't know either.
f)
endif is highlighted as a keyword by most editors but your code will fall over in a heap because it has to be two separate words
end if. This one always catches me out.
g) The constructor is always called Class_Initialize (note the z if you are a Brit who spells initialize as initialise)
h) The destructor is always called Class_Terminate. Class_Initialize and Class_Terminate are listed under events.
i) Assigning a variable to nothing will invoke the destructor
j) If you have a statement like
abc = def
and the interpreter moans about it, try
set abc = def
There is some recommended camel/Hungarian notation that will partly help you around this problem but it takes a while to get used to it if you have never done it before.
If you want to learn to use classes, you're probably on your own. The documentation is skimpy.
If you want to learn VBScript, or at least get used to the syntax, try converting a program from a book. Something like shellsort. That will get you past the basics. You can execute the program from the command line using
cscript xxx.vbs
Next bit is file handling. Syntax is simple: just look up FileSystemObject. It has some decent examples. There are quite a few examples if you download WSH 5.6 from the MS website. Things like how to create a Word Document and put things in it.
If you wrap the script in
<job>
<script language=vbscript>
...
</script>
</job>
and give it a .wsf extension, you can execute it.
If you want to make forms, do whatever you want in html and rename the html file to hta. You now have a hypertext application that can be executed.
Once you think you've mastered VBScript, go through some of the problems posted in this forum. It is as good as a test paper. They range from very simple to damn near impossible. Very often, it is just not knowing what the method is. Also have a look at the problems posed in "Microsoft Active Server Pages (ASP)". Many of them are VBScript problems.
That's my penny's worth - good luck in your exams.