D.10.0- Miscellaneous Functions, Statements and Keywords
Created
by Brendan Doss.
|
| << D.1.0- Overview | AppendixD | D.2.0- Operators >> |
Miscellaneous Functions, Statements and Keywords
Some functionality does not fit under any of the other categories, and so they have been gathered here. Below you will find descriptions of various functions for handling objects, user input, variable checks, output on screen, etc.
|
Create |
Returns a reference to an Automation/COM/ActiveX object. The object is created using COM object creation services.
|
|
Syntax
|
CreateObject(servername.typename[, location])
servername is the name of the application that
provides the object. location (Optional) is the name of the network server you want the object created on. If missing the object is created on the local machine.
|
|
Note
|
|
|
Example |
Dim objRemote
Set objRemote = CreateObject( "MyApp.MyClass", "FileSrv")
|
|
See Also |
GetObject |
|
Dim |
Declares a variable of type Variant and allocates storage space.
|
|
Syntax
|
Dim varname[([subscripts])][, varname[([subscripts])]]...
varname is the name of the variable
subscripts (Optional) indicates the dimensions
when you declare an array variable. You can declare up to 60 multiple
dimensions using the following syntax:
upperbound specifies the
upper bounds of the array. Since the lower bound of an array in VBScript is
always zero, upperbound is one less than the number
|
|
Note
|
|
|
Example |
' Declare a dynamic array
|
|
See Also |
ReDim and Set |
|
Eval |
Evaluates and returns the result of an expression.
|
|
Syntax
|
result = Eval(expression)
result (Optional) is the variable you want to
assign the result of the evaluation to. Although result is optional,
you should consider using the Execute
statement, if you don't want to specify it.
|
|
Note
|
|
|
Example |
Dim blnResult
blnResult holds the value false, because 15 is not equal to 10.
|
|
See Also |
Execute statement |
|
Execute |
Executes one or more statements in the local namespace.
|
|
Syntax
|
Execute statement
statement is a string containing the statement(s) you want executed. If you include more than one statement, you must separate them using colons or embedded line breaks.
|
|
Note
|
Because the assignment operator and the comparison
operator is the same in VBScript, you need to be careful when using them with
Execute. Execute
always uses the equal sign (=) as an assignment
operator, so if you need to use it as a comparison operator, you should use
the Eval function instead.
|
|
Example |
Dim lngResult
lngResult holds the value 25.
|
|
See Also |
Eval and ExecuteGlobal statement |
|
ExecuteGlobal |
Executes one or more statements in the global namespace.
|
|
Syntax
|
ExecuteGlobal statement
statement is a string containing the statement(s) you want executed. If you include more than one statement, you must separate them using colons or embedded line breaks.
|
|
Note
|
Because the assignment operator and the comparison
operator is the same in VBScript, you need to be careful when using them with
ExecuteGlobal. ExecuteGlobal always uses the equal sign
(=) as an assignment operator, so if you need to use it as a comparison
operator, you should use the Eval
function instead.
|
|
Example |
Dim lngResult
lngResult holds the value 25.
|
|
See Also |
Eval and Execute |
|
Filter |
Returns an array that contains a subset of an array of strings. The array is zero-based as are all arrays in VBScript and it holds as many elements as are found in the filtering process The subset is determined by specifying a criteria.
|
|
Syntax
|
Filter(inputstrings, value[, include[, compare]])
inputstrings is a one dimensional string array that you want to search.
value is the string you want to search for.
include (Optional) is a boolean value indicating if you want to include (true) or exclude (false) elements in inputstrings that contains value.
compare (Optional) indicates the comparison
method used when evaluating.
|
|
Note
|
An empty array is returned if no matches are found. A
runtime error occurs
|
|
Example |
Dim arrstrColors(3)
|
|
See Also |
See the String Function Replace |
|
GetObject |
Returns a reference to an Automation object.
|
|
Syntax
|
GetObject([pathname][, class]])
pathname (Optional) is a string specifying the full path and name of the file that contains the object you want to retrieve. You need to specify class if you omit this argument.
class (Optional) is a
string that indicates the class of the object. You need to specify pathname
if you omit this argument. The following syntax is used for class:
appname is a string indicating the application that provides the object.
objecttype is a string specifying the object's type or class that you want created.
|
|
Note
|
You
can use this function to start the application associated with pathname and activate/return the
object specified in the pathname. A new
Some
applications allow you to activate part of a file and you can do this by
suffixing pathname with an exclamation mark (!)
|
|
Example |
Dim objAutomation
|
|
See Also |
CreateObject |
|
GetRef |
Returns a reference to a procedure. This reference can
be bound to
|
|
Syntax
|
Set object.eventname = GetRef(procname)
object is the name of the object in which eventname is placed.
eventname is the name of the event to which the procedure is to be bound.
procname is the name of the procedure you want to bind to eventname.
|
|
Example
|
Sub NewOnFocus() |
|
InputBox |
Displays a dialog box with a custom prompt and a text box. The content of the text box is returned when the user clicks OK.
|
|
Syntax
|
InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context])
prompt is the message you
want displayed in the dialog box. The string can contain up to 1024
characters, depending on the width of the characters you use. You can
separate the lines using one of these VBScript constants: vbCr, vbCrLf, vbLf or vbNewLine
title (Optional) is the text you want displayed
in the dialog box title bar.
default is the default text that will be
returned, if the user doesn't type in
xpos (Optional) is a
numeric expression that indicates the horizontal
context (Optional) is a numeric expression that
indicates the help context number that makes sure that the right help topic
is displayed. This
|
|
Note
|
A zero-length string will be returned if the user
clicks Cancel or presses |
|
Example |
Dim strInput strInput = InputBox( "Enter User Name:", "Test") MsgBox strInput The MsgBox will display either an empty string or whatever the user
|
|
See Also |
MsgBox |
|
IsEmpty |
Returns a boolean value indicating if a variable has been initialized.
|
|
Syntax
|
IsEmpty(expression)
expression is the variable you want to check has been initialized.
|
|
Note
|
You can use more than one variable as expression. If for Example, you concatenate two Variants and one of them is empty, the IsEmpty function will return false, because the expression is not empty.
|
|
Example |
Dim strTest strInput = "Test" MsgBox
IsEmpty(strTest) ' true
|
|
See Also |
IsArray, IsDate, IsNull, IsNumeric, IsObject and VarType |
|
IsNull |
Returns a boolean value indicating if a variable contains Null or valid data.
|
|
|
IsNull(expression)
expression is any expression.
|
|
Syntax
|
This function returns true if the whole of expression evaluates to Null. If you have more than one variable in expression, all of them must be Null for the function to return true.
Please be aware that Null is not the same as empty (a variable that hasn't been initialized) or a zero-length string (""). Null means no valid value!
You should always use the IsNull
function when checking for Null values, because
using the normal operators will return false even if
|
|
Example |
Dim strInput
strInput = "Test"
|
|
See Also |
IsArray, IsDate, IsEmpty, IsNumeric, IsObject and VarType |
|
IsNumeric |
Returns a boolean value indicating if an expression can be evaluated as a number.
|
|
Syntax
|
IsNumeric(expression)
expression is any expression.
|
|
Note
|
This function returns true if the whole expression evaluates to a number. A Date expression is not considered a numeric expression.
|
|
Example |
MsgBox IsNumeric(55.55)
' true
|
|
See Also |
IsArray, IsDate, IsEmpty, IsNull, IsObject and VarType |
|
IsObject |
Returns a boolean value indicating if an expression is a reference to a valid Automation object.
|
|
Syntax
|
IsObject(expression)
expression is any expression.
|
|
Note
|
This function returns true only if expression is in fact a variable of Variant subtype Object (9) or a user-defined object.
|
|
Example |
Dim objTest Set objTest = CreateObject( "Excel.Application") MsgBox IsObject(objTest) ' true
|
|
See Also |
IsArray, IsDate, IsEmpty, IsNull, IsNumeric, Set and VarType |
|
LoadPicture |
Returns a picture object.
|
|
Syntax
|
LoadPicture(picturename)
picturename is a string expression that
indicates the file name of
|
|
Note
|
This function is only available on 32-bit platforms. The following graphic formats are supported:
A runtime error occurs if picturename doesn't exist or if it is not a valid picture file. Use LoadPicture("") to return an "empty" picture object in order to clear a particular picture.
|
|
Example |
Dim objPicture
|
|
MsgBox |
Displays a dialog box with a custom message and a custom set of command buttons. The value of the button the user clicks is returned as the result of this function.
|
||
|
Syntax |
MsgBox(prompt[, buttons][, title [, helpfile, context])
prompt is the message you
want displayed in the dialog box. The string can contain up to 1024
characters, depending on the width of the characters you use. You can
separate the lines using one of these VBScript constants: vbCr, vbCrLf, vbLf or vbNewLine
buttons (Optional) is the sum of
values indicating the number and type of button(s) to display, which icon
style to use, which button is the default and if the MsgBox is
modal. The settings for this |
||
|
|
vbOKOnly
vbOKCancel
vbAbortRetryIgnore
vbYesNoCancel
|
0
1
2
3 |
Displays OK button.
Displays OK and Cancel buttons.
Displays Abort, Retry, and Ignore buttons.
Displays Yes, No, and Cancel buttons.
|
|
|
vbYesNo
vbRetryCancel
vbCritical
vbQuestion
vbExclamation
vbInformation
vbDefaultButton1
vbDefaultButton2
vbDefaultButton3
vbDefaultButton4
vbApplicationModal
vbSystemModal |
4
5
16
32
48
64
0
256
512
768
0
4096 |
Displays Yes and No buttons.
Displays Retry and Cancel buttons.
Displays critical icon.
Displays query icon.
Displays warning icon.
Displays information icon.
Makes the first button the default one.
Makes the second button the default one.
Makes the third button the default one.
Makes the fourth button the default one
When the MsgBox is application
modal,
The same effect as
vbApplicationModal.
|
|
|
Please note how the values are grouped:
Buttons (values 0-5) Icon (values 16, 32, 48 and 64) Default button (values 0, 256, 512 and 768) Modal (values 0 and 4096)
You should only pick one value from each group when creating your MsgBox.
|
||
|
|
title (Optional) is the text you want displayed in the dialog box title bar. The application name will be displayed if this argument is omitted.
helpfile (Optional) is a string expression that
indicates the help file to use when providing context-sensitive help for the
dialog box. This argument must be
context (Optional) is a numeric expression that indicates the help context number that makes sure that the right help topic is displayed. This argument must be used in conjunction with helpfile.
|
|
Note
|
The
following values can be returned: vbOK (1)
The ESC key has the same effect
as the Cancel button. Clicking the Help
|
|
Example |
Dim intReturn
The MsgBox will display the message "Exit the application?", the buttons Yes, No and Cancel, and the question mark icon. This MsgBox will be application modal.
|
|
See Also |
InputBox |
|
RGB |
Returns an integer that represents an RGB color value. The RGB color value specifies the relative
intensity of red, green, and blue to cause a specific color
|
|
Syntax
|
RGB(red, green, blue)
red is the red part of the color. Must be in the range 0-255.
green is the green part of the color. Must be in the range 0-255.
blue is the blue part of the color. Must be in the range 0-255.
|
|
Note
|
255 will be used, if the value for any of the arguments is larger than 255. A runtime error occurs if any of the arguments cannot be evaluated to a numeric value.
|
|
Example |
' Returns the RGB number for white |
|
ScriptEngine |
Returns a string indicating the scripting language being used.
|
|
Syntax |
ScriptEngine |
|
Note
|
The following scripting engine values can be returned:
VBScript MS VBScript JScript MS JScript VBA MS Visual Basic for Applications
Other third-party ActiveX Scripting Engines can also be returned, if you have installed one.
|
|
See Also |

RSS