PDA

View Full Version : [SOLVED] Solved: Tell Me About VB Script



Cyberdude
04-19-2005, 09:51 AM
What is VB script, how is it different from VBA, and where can I do some reading on the subject?

Zack Barresse
04-19-2005, 10:57 AM
A Google (http://www.google.com/) search (http://www.google.com/search?hl=en&lr=&c2coff=1&q=VB+Script&btnG=Search) will yield many results ...

http://www.suite101.com/welcome.cfm/vb_script

http://www.w3schools.com/vbscript/default.asp

http://www.thelinkzone.com/webmaster/programming/vbscript.html

http://www.needscripts.com/

http://www.tutorialized.com/tutorials/Visual-Basic/VB-Script/1 Good

http://c2.com/cgi/wiki?VbScript Good

http://www.nca-corp.com/Napier/VB%20Script%20Programming.htm

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=59940&lngWId=1



HTH

Killian
04-19-2005, 11:08 AM
A VBscript is basically a text file containing VB code and saved with a .vbs extension (exactly as you would use in VBA). It is compiled and executed with the windows VBScript runtime engine when it is run (just as VBA code is compiled and executed in the host app's).
The VB keywords are all there - an easy way to write one is in the VBE to check your syntax etc, then copy it to notepad, save and change the extension to .vbs)
You can create objects in the same way, like instances of applications, the file system object, etc. They have all kinds of applications - I often use them as un/install scripts for developing/testing when I need to copy a lot of files to different places and make registry edits that I don't want to deal with manually.

Here's the MS link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbswhat.asp
There's quite o loy of developer sites that have VBS info and examples, like this one: http://www.devguru.com/Technologies/vbscript/quickref/vbscript_intro.html
(btw devgru is an excellent reference site - well worth bookmarking!)

Zack Barresse
04-19-2005, 11:10 AM
We have one in our Kbase as well ... http://www.vbaexpress.com/kb/getarticle.php?kb_id=78

mvidas
04-19-2005, 11:18 AM
Hi CD,

I'm increasingly using vbscript a lot more nowadays, and while it is mostly the same as vba/vb there are still some minor differences and limitations. If something I write isn't compatable with vbs, I often check http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp for what I'm trying to do, I consider it my vbs help file :) An example file is mdewis' kb entry at http://www.vbaexpress.com/kb/getarticle.php?kb_id=273 which just uses the FSO to combine text files together. I've made a couple updates to that for faster runtimes and more flexibility, but that KB entry is what opened my eyes to vbs, to both the ease and power of it.
Feel free to post questions here or PM me if you have any specific questions about it, I now use it for most of my work automation, as the vbs files can even be run at specific dates/times.
Matt

Just a quick addition to what I just posted. The most important things to remember in vbscript:
-Don't Dim a variable as anything, won't work (just use "Dim a" instead of "Dim a as ___"
-API calls dont exist
-The 'main' sub doesn't have a "Sub Main() ... End Sub" around it, and it goes at the top. All secondary functions and subs go below it. The only exception to this that I know is if you create a Class in vbs, that goes at the top
-No Format() function :(

Cyberdude
04-19-2005, 01:53 PM
Hey, Guys, those are terrific answers . . . just what I needed. Some great references. Don't know why, but I never think to use Google to find out stuff about Excel.