Books On Vb Scripting



By reading the book and using the sample source code, y ou will be able to master Visual Basic programming effortlessly! (.We have redesigned and updated the book recently to make the content more reader-friendly.) Preview the Book. By reading this book and trying out the accompanied source codes, you can.

VBScript, short for Visual Basic Scripting Edition, is a Microsoft-supplied scripting language similar to Visual Basic and Visual Basic for Applications. It can be used via Windows Script Host (WSH) as a Windows scripting language. Furthermore, it can be used as a client-side scripting language in web pages instead of JavaScript, but such pages will only work with Internet Explorer. Moreover, it can be used for server-side web scripting as part of Active Server Pages (ASP), and in other environments. This book focuses on the language use via WSH.

Scripts to be used with WSH are usually plain text files with .vbs extension. By default, Windows associates the extension with an interpreter of the language, and therefore, entering the script name on the Windows batch command line leads to script execution, albeit without waiting for script completion. Furthermore, scripts can be run from the desktop or the Windows file explorer, usually by double clicking.

VBScript can access objects available via Microsoft COM interface, including those of Microsoft Office. Thus, Microsoft Office can be scripted not only from Visual Basic for Applications (VBA) embedded in office files such as spreadsheets but also from VBScript scripts, in a syntanctically similar yet somewhat different manner.

Two commands are available to let WSH execute a script: wscript and cscript. wscript is for GUI whereas cscript is for command line interaction. By default, .vbs extension is associated with wscript.

  1. Vbscript Books Showing 1-6 of 6 VBScript Pocket Reference (Paperback). Paul Lomax (shelved 3 times as vbscript) avg rating 3.61 — 36 ratings — published 2001.
  2. A vbscript eBooks created from contributions of Stack Overflow users.

VBScript is mostly case-insensitive as for keywords and identifiers. Thus, 'End If' is equivalent to 'end if', and 'FSO.CreateTextFile( ...' is equivalent to 'fso.createtextfile( ...'.

Data types[edit]

Unlike in VBA, variables cannot be dimensioned to be restricted to values of a particular data type, such as String. Rather, they are all of data type Variant.

However, there is still an underlying data type of each variable, depending on what you assign to the variable. You can find out about the current underlying data type of a variable content using TypeName function.

Links:

  • VBScript Data Types, msdn.microsoft.com
  • TypeName, ss64.com

File operations[edit]

Unlike in VBA, file operations are not part of the language built-in core but rather are accessible from FileSystemObject.

Writing to a text file:

Getting current directory:

Links:

  • FileSystemObject, ss64.com
  • FileSystemObject, msdn.microsoft.com

Excel[edit]

Excel can be scripted using VBScript by accessing Excel.Application object. Unlike VBA, VBScript does not support named argument passing to methods, only positional argument passing. Furthermore, functions that appear global from VBA in Excel need to be called as methods of the Excel object in VBScript.

An example:

Constants[edit]

There are multiple built-in constants, starting with vb. For instance, vbOKCancel is used in conjunction with MsgBox.

Vb scripting w3schools

Applications-specific constants such as Excel's xlAnd are not available.

Links:

  • VBScript Built-In Constants, ss64.com
  • Microsoft Excel Constants, msdn.microsoft.com
  • Microsoft Outlook Constants, msdn.microsoft.com
  • Word Enumerated Constants, msdn.microsoft.com

Clipboard[edit]

VBScript does not support VBA's MSForms.DataObject to access clipboard.

There are workarounds:

  • For writing to the clipboard, you can run clip.exe available in Windows 7.
  • For reading from the clipboard, you can access Internet Explorer via COM and let it read from the clipboard.

Links:

  • VBScript, Text to Clipboard to Paste in Any Field, stackoverflow.com

External processes[edit]

You can run external processes using Run method of WScript.Shell:

You can also do so using Exec method of WScript.Shell:

Keywords: external commands, running programs.

In another Wikibook: Excel VBA#Command Output.

Links:

  • Running Programs in Microsoft Windows 2000 Scripting Guide, technet.microsoft.com
  • .Run, ss64.com
  • The wscript.Shell + Shell.Application objects, ss64.com

Regular expressions[edit]

You can use regular expressions using RexExp object:

Alternatively, you could create the regex object via Set RegExp = CreateObject('VBScript.RegExp'), but, in VBScript, that is unnecessary.

Versions[edit]

VBScript versions include 5.1 (Win 2000), 5.6 (XP), 5.7 (Vista) and 5.8.

To find out about the version:

Links:

  • VBScript Version Information, msdn.microsoft.com

Comparison to VBA[edit]

Features missing from VBScript while present in VBA:

  • Named argument passing to functions and methods
  • Application-specific named constants such as Excel's xlAnd are not available; you have to set them on your own or pass numbers instead
  • Built-in file I/O; VBScript can use FileSystemObject
  • Creating custom collections via new Collection
  • Dimensioning variables with particular data types
  • Etc.

Links:

  • Visual Basic for Applications Features Not In VBScript, msdn.microsoft.com
  • Does VBScript allow named arguments in function calls?, stackoverflow.com

COM components[edit]

COM components often used with VBScript in WSH:

  • WScript.Shell
  • WScript.Network
  • Scripting.FileSystemObject
  • Scripting.Dictionary
  • Shell.Application
  • Excel.Application
  • Word.Application
  • Outlook.Application
  • InternetExplorer.Application

Links:

  • Windows Script Host Object Model, msdn.microsoft.com

Related Wikibooks[edit]

External links[edit]

  • VBScript Language Reference, msdn.microsoft.com
  • WSH Primer, technet.microsoft.com
  • VBScript Commands, ss64.com
Retrieved from 'https://en.wikibooks.org/w/index.php?title=VBScript_Programming&oldid=3676487'

VBScript Tutorial

VBScript is a Microsoft scripting language.

In our VBScript tutorial you will learn how to write VBScript, and how to insertthese scripts into your HTML files to make your webpages more dynamic and interactive.


VBScript Examples

Vb Scripting Tutorial Pdf

Learn by examples! With our editor, you can edit the source code, and click on a testbutton to view the result.

VBScript Reference

Vb Scripting Excel

At W3Schools you will find a complete VBScript reference.


Get Your Diploma!

W3Schools' Online Certification Program is the perfect solution for busy professionals who need to balance work, family, and career building.

The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.

The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.

The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.

The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).