Consulting

Results 1 to 6 of 6

Thread: Solved: Tell Me About VB Script

  1. #1

    Solved: Tell Me About VB Script

    What is VB script, how is it different from VBA, and where can I do some reading on the subject?

  2. #2

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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/de...ml/vbswhat.asp
    There's quite o loy of developer sites that have VBS info and examples, like this one: http://www.devguru.com/Technologies/...ipt_intro.html
    (btw devgru is an excellent reference site - well worth bookmarking!)
    K :-)

  4. #4

  5. #5
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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/de...bscripttoc.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

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •