.Application - VBScript
.Application
Overview
The .Application
object in VB Script is a powerful tool that provides access to the global state of the VB Script runtime environment. It allows scripts to control and interact with various aspects of the script execution process, including error handling, object creation, and script termination.
Syntax
Dim Application
Options/Flags
None.
Examples
' Get the current error object
Dim errorObject = Application.GetLastError
' Display the error description
If Not errorObject Is Nothing Then
MsgBox errorObject.Description
End If
' Create a new VB Script object
Dim obj = Application.CreateObject("Scripting.FileSystemObject")
' Use the object to create a new file
obj.CreateTextFile("c:\test.txt")
Common Issues
- Runtime Errors: When accessing the
.Application
object within a function, ensure that you qualify it with theApplication
keyword, e.g.,Application.GetLastError
. Failing to do so may result in an “Object Required” error. - Object Not Created: When creating objects using
Application.CreateObject
, verify that the object’s class is registered on the system. An unregistered class will cause an “Invalid Class String” error.
Integration
The .Application
object can be used in conjunction with other VB Script commands for advanced tasks. For example:
' Display a custom error message and terminate the script
On Error Resume Next
Dim errorObject = Application.GetLastError
If Not errorObject Is Nothing Then
MsgBox errorObject.Description
Application.Quit
End If
Related Commands
- GetObject: Returns a reference to an existing object.