Questions tagged [vbscript]

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic. VBScript is not the same thing as VBA or VB.NET. They are three different things, so use the correct tags.

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic.

VBScript is commonly used for automating administrative and other tasks in the Windows operating systems (via Windows Script Host --) and for server-side scripting in web applications. It can also used for client-side scripting in (not other browsers), but is generally used for this purpose only in intranet web applications, where the browser can be limited to IE. VBScript is also the language used to create custom Outlook forms ().

Although VBScript has much common syntax with VBA, do not tag questions as unless you are specifically asking about both. It is also completely different than VB.NET.

Some differences between VBScript and VBA:

  • Does not support enumerated constants; replace with the numeric value:

    'VBScript
    Outlook.CreateItem(0)
    
    'VBA allows this:
    Outlook.CreateItem(olMailItem)
    
  • All variables are of type Variant, and are declared without a type specification:

    'VBScript
    Dim olApp  
    Dim msg
    
    'VBA allows this:
    Dim olApp As Outlook.Application  
    Dim msg As Outlook.MailItem
    
  • Method calls don't support named arguments.

    'VBScript
    wb.SaveAs "output.csv", 6, , , , False
    
    'VBA allows this:
    wb.SaveAs FileName:="output.csv", FileFormat:=xlCSV, CreateBackup:=False
    

Executing VBScripts with WSH -- WScript/CScript

VBScript can be executed locally either in GUI mode, in which output is displayed as a window:

wscript.exe C:\Script\Location\script.vbs

or in console mode, in which input is read from and written to a console window.

cscript.exe C:\Script\Location\script.vbs

Running wscript.exe or cscript.exe without specifying the path will run the script in the machine's architecture -- 32-bit on 32-bit machines, and 64-bit on 64-bit machines. On 64-bit machines, it is possible to have the script run in the 32-bit emulation layer:

C:\windows\SysWOW64\wscript.exe  C:\Script\Location\script.vbs
C:\windows\SysWOW64\cscript.exe  C:\Script\Location\script.vbs

Note: Scheduled VBScript tasks must be run with cscript.exe because computer/domain policies limit activation of GUI applications when no user is logged on.

Debugging scripts

Visual Studio (Community Edition, or the Integrated Shell of pre-2013 versions) can be used to step through scripts and locate errors.

  • //X will trigger the debugger if there is a runtime error, or a code breakpoint
  • //D will trigger the debugger at the beginning of the script

No variable expansion
Like other languages in the Visual Basic family, VBScript does not expand variables inside string literals, so in code like

var1 = "fox"
var2 = "The quick brown var1 jumps over the lazy dog."

the value of var2 will remain The quick brown var1 jumps over the lazy dog. instead of becoming The quick brown fox jumps over the lazy dog. To get the value of a variable in a string, the variable must be concatenated with the rest of the string:

var1 = "fox"
var2 = "The quick brown " & var1 & " jumps over the lazy dog."

Frequently Asked Questions

Resources

Related Tags

18718 questions
3
votes
2 answers

What is the syntax for the pattern in a VBScript RegExp object?

I'm not too familiar with VB script and am having trouble with the syntax for the pattern property of my regexp object. I have some data that looks like this: Front SHD Trip CLEAR OBSTRUCTION BEFORE CONTINUING [Table Position = 0mmFwd] Front…
3
votes
1 answer

How to add zero to single digit in a string

I need to to append zero in my below string whenever I get date with single digit without changing Quantity digit (below string is system generated in my application not created by user), Data Added Quantity:1 on Dec 9 2015 modified on Jun 7…
J_Coder
  • 707
  • 5
  • 14
  • 32
3
votes
3 answers

Clicking on specific row in a WebTable using UFT/QTP

I am having hard time clicking specific row in a Web Table. My code finding proper row, but when I use Child Item method it complains that Object is not found. Here is my code: Desc = "Record to click" If…
K.G.
  • 33
  • 1
  • 1
  • 4
3
votes
0 answers

Detect coordinates of touchpad

I want to develop something like Synaptics touchpad gesture application. The Synaptics settings show x and y coordinates. Is there any software I can use? Like this code: $x_start = 300 $y_start = 300 While 1 If $ontouch == True Then …
shunz19
  • 495
  • 4
  • 13
3
votes
1 answer

Handling ADODB connections in classic ASP

I'm an ASP.NET C# guy who has to go back to classic ASP, and need some help with it. First, look at this two functions (I know in VBScript the comments are declared by ' and not by // but the syntax highlighter here messes up with '). First…
Albireo
  • 10,977
  • 13
  • 62
  • 96
3
votes
0 answers

How to get query param from URL string in VBS

I am getting as XML which contains a URL with some query param so is there any way to get those param other then string parsing in vbscript. For example: www.example.com?a=abc&b=xyz&c=pqr After parsing and getting…
Jyotish Singh
  • 2,065
  • 3
  • 20
  • 28
3
votes
1 answer

Check the Syntax of a URL via VBS Script

Is there a way to check the syntax of a URL via visual basic? Here is my code below. I need a way to just check the syntax and to be sure it is correct (i.e has http, .com or .net or .edu). I need to check the format to be sure the url's are typical…
3
votes
1 answer

VBscript WMI doesn't locate files, FSO does

I have two files weblogic.jar and weblogic.policy in C:\Weblogic\wlserver\server\lib. With the first method, the script finds them and displays the name of the file: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder =…
Harald
  • 31
  • 3
3
votes
2 answers

In VBS, return MySQL query results when using 'INSERT INTO'

In VBS, taking the following example into consideration, what (if any) results are returned by the Open() method of the ADODB.Recordset object? Dim CN : Set CN = CreateObject("ADODB.Connection") Dim RS : Set RS =…
David Gard
  • 11,225
  • 36
  • 115
  • 227
3
votes
2 answers

windows command line: open file with active process?

I'd like to be able to tell an active process to open a file using the Windows command line ideally -- but any solution using built-in Windows (7+) capabilities (eg powershell or vbscript) also works. For example, if I have an instance of notepad…
Mac
  • 31
  • 2
3
votes
3 answers

How to programmatically convert Access 1997 .mdb to Access 2007 .accdb

I'm in the starting process of building an application that walks through a folder structure, starting at a given root path, and converts all found Access 1997 .mdb files into the newer Access 2007/2010 .accdb format. However, I'm running into some…
p4r1
  • 2,490
  • 16
  • 18
3
votes
1 answer

How to make properties visible to COM in a .NET DLL (Methods DO work)

Solved, see comments! I have a simple .NET DLL written in c#. In asp-classic or VB.NET i can create the object and call a member function in the DLL without any problem. But, and this is my stumbling point, i can't access class properties. Here's…
rudy
  • 185
  • 2
  • 11
3
votes
1 answer

invalid window handle with error code : 80070578

I have written below vb script to find an window and bring it to focus Dim oShell Set oShell = CreateObject("WScript.Shell") 'bring the window to front 'title must be exactly what you see in the titlebar of the window oShell.AppActivate…
Sanmoy
  • 589
  • 2
  • 9
  • 23
3
votes
1 answer

0x800a01ad - Microsoft VBScript runtime error: ActiveX component can't create object

I've created Class library project with next code and settings: using System.Runtime.InteropServices; namespace MyDll { [ComVisible(true)] public class TestClass { [ComVisible(true)] public string[] SomeFunc(string…
Ted
  • 1,682
  • 3
  • 25
  • 52
3
votes
3 answers

Using VBScript or batch to change Shortcut Icon

I'm trying to create a batch file that will toggle a desktop shortcut icon from icon0 to icon1 and back again on second execute. The Desktop Shortcut points to the batch file in Desktop/toggleicon.BAT, (Batch files is in same directory) but I'm…
Ace Thanks
  • 123
  • 1
  • 1
  • 9