Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript Tutorial

Status
Not open for further replies.

Caliheat

MIS
Aug 3, 2005
2
US
well guys, im working on getting my MCSA and my MCSE certifications from my microsoft. im also trying to learn VBScript, is a tool it may be useful to become a system admin.
does anyone has a suggestion for a good tutorial, good book, and good materail about it.

thank u for ur time and cooperation.

Andres
 
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.
 
>d) How to use let/set with multiple parameters...
>...
>It is just pure trial and error to figure it out - you won't find this in any book or website.

Just for info sake, in the vbs/js documentation (script56.chm), it does show the use.
script56.chm said:
[Public | Private] Property Let name ([arglist,] value)
[statements]
[Exit Property]
[statements]
End Property
...(excerpt)...
arglist
List of variables representing arguments that are passed to the Property Let procedure when it is called. Commas separate multiple arguments. The name of each argument in a Property Let procedure must be the same as the corresponding argument in a Property Get procedure. In addition, the Property Let procedure will always have one more argument than its corresponding Property Get procedure. That argument is the value being assigned to the property.
But, we never know enough and our memory is short.

Other than that, it is a good and acute highlight of some of the less easy and more intriguing topics. Thanks xwb. Good effort, maybe more than what the op deserves.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top