Functions

In computer programming, a function is a predefined formula which automatically generates various kinds of output. Its main purpose is to accept certain input from the user and return a value which is passed onto the main program to finish the execution. Functions can reduce code repetition and increase code readability.

Most programming languages such as VBScript come with a built-in range of functions that perform various actions or routines and return a specific value. AWE encompasses a VBA-compatible engine designed to extend the functionality available in AML (AWE Markup Language), the primary internal language that it uses. Not only does this allow multi-line BASIC scripts to be included in a task (with the use of the BASIC Script action), it allows all built-in, pre-defined Visual Basic functions to be used as an expression in text fields of any step of a task as well by surrounding the function with percent signs.

Some VBA-compatible functions require other parameters to properly complete a procedure or routine. The general format of a function is its name followed by any arguments contained between parentheses:

FunctionName (arguments)

For more details regarding the use of functions, see Using Functions.

A full library of pre-defined VBA functions can be found in the lower left pane of the Expression Builder under the Functions folder. Help regarding each function can be accessed by first expanding the Functions folder, then selecting the desired function from the lower right pane and pressing the F1 key or by right-clicking the function and selecting Help from the popup menu that appears.

Furthermore, AWE includes a large collection of additional functions that extend the functionality of the AWE Scripting Engine beyond the capabilities of what the basic VBA-compatible engine provides. These functions are collectively referred to as AWE Extended Functions.

Function Name

Description

Abs

Syntax:

Abs(Num)

Group:

Math

Description:

Return the absolute value.

Parameters:

Num—Return the absolute value of this numeric value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Abs(9) ' 9
Debug.Print Abs(0) ' 0
Debug.Print Abs(-9) ' 9
End Sub

Array

Syntax:

Array([expr[,]])

Group:r

Conversion

Description:

Return a variant value array containing the exprs.

Example:

Sub Main
X = Array(0,1,4,9)
Debug.Print X(2) ' 4
End Sub

Asc

Syntax:

Asc(S$)

Group:

String

Description:

Return the ASCII value.
Note:
A similar function, AscB, returns the first byte in S$. Another similar function, AscW, returns the Unicode number.

Parameters:

S$—Return the ASCII value of the first char in this string value.

Example:

Sub Main
Debug.Print Asc("A") ' 65
End Sub

Atn

Syntax:

Atn(Num)

Group:

Math

Description:

Return the arc tangent. This is the number of radians. There are 2*Pi radians in a full circle.

Parameters:

Num—Return the arc tangent of this numeric value.

Example:

Sub Main
Debug.Print Atn(1)*4 ' 3.1415926535898
End Sub

CallersLine

Syntax:

CallersLine[(Depth)]

Group:

Miscellaneous

Description:

Return the caller's line as a text string.
The text format is: "[macroname|subname#linenum] linetext".

Parameters:

Depth—This integer value indicates how deep into the stack to get the caller's line. If Depth = -1 then return the current line. If Depth = 0 then return the calling subroutine's current line, etc.. If Depth is greater than or equal to the call stack depth then a null string is returned. If this value is omitted then the depth is 0.

Example:

Sub Main
A
End Sub

Sub A
Debug.Print CallersLine '"[(untitled 1)|Main# 2] A"
End Sub

CBool

Syntax:

CBool(Num|$)

Group:

Conversion

Description:

Convert to a boolean value. Zero converts to False, while all other values convert to True.

Parameters:

Num|$—Convert a number or string value to a boolean value.

Example:

Sub Main
Debug.Print CBool(-1) 'True
Debug.Print CBool(0) 'False
Debug.Print CBool(1) 'True
End Sub

CByte

Syntax:

CByte(Num|$)

Group:

Conversion

Description:

Convert to a byte value.

Parameters:

Num|$—Convert a number or string value to a byte value.

Example:

Sub Main
Debug.Print CByte(1.6) ' 2
End Sub

CChar

Syntax:

CChar(expr)

Group:

Conversion

Description:

Convert a number or string value to an single character value.

Parameters:

expr—Convert a number or string value to an single character value. This is the first character of the string conversion.

Example:

Sub Main
Debug.Print CChar(33) '"!"
End Sub

CCur

Syntax:

CCur(Num|$)

Group:

Conversion

Description:

Convert to a currency value.

Parameters:

Num|$—Convert a number or string value to a currency value.

Example:

Sub Main
Debug.Print CCur("1E6") ' 1000000
End Sub

CDate

Syntax:

CDate(Num|$)

-or-

CVDate(Num|$)

Group:

Conversion

Description:

Convert to a date value.

Parameters:

Num|$—Convert a number or string value to a date value.

Example:

Sub Main
Debug.Print CDate(2) ' 1/1/00
End Sub

CDbl

Syntax:

CDbl(Num|$)

Group:

Conversion

Description:

Convert to a double precision real.

Parameters:

Num|$—Convert a number or string value to a double precision real.

Example:

Sub Main
Debug.Print CDbl("1E6") ' 1000000
End Sub

CDec

Syntax:

CDec(Num|$)

Group:

Conversion

Description:

Convert to a decimal (96 bit scaled real).

Parameters:

Num|$—Convert a number or string value to a 96 bit scaled real.

Example:

Sub Main
Debug.Print CDec("1E16")+0.1 ' 10000000000000000.1
End Sub

Choose

Syntax:

Choose(Index, expr[,])

Group:

Flow Control

Description:

Return the value of the expr indicated by Index.

Parameters:

Index—The numeric value indicates which expr to return. If this value is less than one or greater than the number of exprs then Null is returned.

expr—All expressions are evaluated.

Example:

Sub Main
Debug.Print Choose(2,"Hi","there") '"there"
End Sub

Chr

Syntax:

Chr[$](Num)

Group:

String

Description:

Return a one char string for the ASCII value.
Note: A similar function, ChrB, returns a single byte ASCII string. Another similar function, ChrW, returns a single char Unicode string.

Parameters:

Num—Return one char string for this ASCII numeric value.

Example:

Sub Main
Debug.Print Chr$(48) '"0"
End Sub

CInt

Syntax:

CInt(expr)

Group:

Conversion

Description:

Convert to a 16 bit integer. If the expr is too big (or too small) to fit then an overflow error occurs.

Parameters:

expr—Convert a number or string value to an integer.

Example:

Sub Main
Debug.Print CInt(1.6) ' 2
End Sub

Clipboard Instruction/Function

Syntax:

Clipboard Text$

Or

Clipboard[$][( )]

Group:

Miscellaneous

Description:

Form 1: Set the clipboard to Text$. This is like the Edit|Copy menu command.

Form 2: Returns the text in the clipboard.

Parameters:

Text$—Put this string value into the clipboard.

Example:

Sub Main
Debug.Print Clipboard$()
Clipboard "Hello"
Debug.Print Clipboard$() '"Hello"
End Sub

CLng

Syntax:

CLng(Num|$)

Group:

Conversion

Description:

Convert to a 32 bit long integer. If Num|$ is too big (or too small) to fit then an overflow error occurs.

Parameters:

Num|$—Convert a number or string value to a 32 bit integer.

Example:

Sub Main
Debug.Print CLng(1.6) ' 2
End Sub

CObj

Syntax:

CObj(expr)

Group:

Conversion

Description:

Convert to an Object. The object contains the value.

Parameters:

expr—Convert to an object. If the parameter is already an object, return it.

Example:

Sub Main
Debug.Print CObj(Sqr(2)) ' 1.4142135381699
End Sub

Command

Syntax:

Command[$]

Group:

Miscellaneous

Description:

Contains the value of the MacroRun parameters.

Example:

Sub Main
Debug.Print "Command line parameter is: """;
Debug.Print Command$;
Debug.Print """"
End Sub

Cos

Syntax:

Cos(Num)

Group:

Math

Description:

Return the cosine.

Parameters:

Num—Return the cosine of this numeric value. This is the number of radians. There are 2*Pi radians in a full circle.

Example:

Sub Main
Debug.Print Cos(1) ' 0.54030230586814
End Sub

CreateObject

Syntax:

CreateObject(Class$)

Group:

Object

Description:

Create a new object of type Class$. Use Set to assign the returned object to an object variable.

Parameters:

Class$—This string value is the application's registered class name. If this application is not currently active it will be started.

Example:

Sub Main
Dim App As Object

Set App = CreateObject("WinWrap.CppDemoApplication")
App.Move 20,30 ' move icon to 20,30

Set App = Nothing
App.Quit ' run-time error (no object)
End Sub

CSng

Syntax:

CSng(expr)

Group:

Conversion

Description:

Convert to a single precision real. If expr is too big (or too small) to fit then an overflow error occurs.

Parameters:

expr—Convert a number or string value to a single precision real.

Example:

Sub Main
Debug.Print CSng(Sqr(2)) ' 1.4142135381699
End Sub

CShort

Syntax:

CShort(Num|$)

Group:

Conversion

Description:

Convert to a 16 bit signed integer Short value. If expr is too big (or too small) to fit then an overflow error occurs.

Parameters:

expr—Convert a number or string value to a 16 bit signed integer.

Example:

Sub Main
Debug.Print CShort(1.6) ' 2
End Sub

CType

Syntax:

CShort(expr )

Group:

Conversion

Description:

Convert an expr to the specified objtype type. Conversion include inheritance, implementation and value conversion. If the expr can't be converted, a "type mismatch error" will occur.

Parameters:

expr—Convert the value of this expression.

objtype—Convert to this type.

Example:

Sub Main
Debug.Print CType(1.1, Integer) ' 1

Dim V As Object

V = Err

Debug.Print TypeName(CType(V, ErrObject)) ' ErrObject
End Sub

CStr

Syntax:

CStr(expr)

Group:

Conversion

Description:

Convert to a string.

Parameters:

expr—Convert a number or string value to a string value using the current locale (GetLocale).

Example:

Sub Main
Debug.Print CStr(Sqr(2)) '"1.4142135623731" - US English locale
End Sub

CUInt

Syntax:

CUInt(expr)

Group:

Conversion

Description:

Convert to an UInteger. If expr is too big (or too small) to fit then an overflow error occurs.

Parameters:

expr—Convert a number or string value to an UInteger.

Example:

Sub Main
Debug.Print CUInt(1.6) ' 2
End Sub

CULng

Syntax:

CULng(expr)

Group:

Conversion

Description:

Convert to a ULong. If expr is too big (or too small) to fit then an overflow error occurs.

Parameters:

expr—Convert a number or string value to a ULong.

Example:

Sub Main
Debug.Print CULng(1.6) ' 2
End Sub

CurDir

Syntax:

CurDir[$]([Drive$])

Group:

File

Description:

Return the current directory for Drive$.

Parameters:

Drive$—This string value is the drive letter. If this is omitted or null then return the current directory for the current drive.

Example:

Sub Main
Debug.Print CurDir$()
End Sub

CVar

Syntax:

CVar(expr)

Group:

Conversion

Description:

Convert to a variant value.

Parameters:

expr—Convert a number or string value (or object reference) to a variant value.

Example:

Sub Main
Debug.Print CVar(Sqr(2)) ' 1.4142135623731
End Sub

CVErr

Syntax:

CVErr(expr)

Group:

Conversion

Description:

Convert to a variant that contains an error code. An error code can't be used in expressions.

Parameters:

expr—Convert a number or string value to an error code.

Example:

Sub Main
Debug.Print CVErr(1) ' Error 1
End Sub

Date

Syntax:

Date[$]

Group:

Time/Date

Description:

Return today's date as a date value.

Example:

Sub Main
Debug.Print Date ' Example: 1/1/1995
End Sub

DateAdd

Syntax:

DateAdd(interval, number, dateexpr)

Group:

Time/Date

Description:

Return a date value a number of intervals from another date.

Parameters:

interval—This string value indicates which kind of interval to add.

number—Add this many intervals. Use a negative value to get an earlier date.

dateexpr—Calculate the new date relative to this date value. If this value is Null then Null is returned.

Interval—Description

yyyy—Year

q—Quarter

m—Month

y—Day of year

d—Day

w—Weekday

ww—Week

h—Hour

n—Minute

s—Second

Example:

Sub Main
Debug.Print DateAdd("yyyy",1,#1/1/2000#) '1/1/2001
End Sub

DateDiff

Syntax:

DateDiff(interval, dateexpr1, dateexpr2)

Group:

Time/Date

Description:

Return the number of intervals between two dates.

Parameters:

interval—This string value indicates which kind of interval to add.

number—Add this many intervals. Use a negative value to get an earlier date.

dateexpr—Calculate the new date relative to this date value. If this value is Null then Null is returned.

Interval—Description

yyyy—Year

q—Quarter

m—Month

y—Day of year

d—Day

w—Weekday

ww—Week

h—Hour

n—Minute

s—Second

Example:

Sub Main
Debug.Print DateDiff("yyyy",#1/1/1990#,#1/1/2000#) ' 10
End Sub

DatePart

Syntax:

DatePart(interval, dateexpr)

Group:

Time/Date

Description:

Return the number from the date corresponding to the interval.

Parameters:

interval—This string value indicates which kind of interval to add.

dateexpr—Calculate the new date relative to this date value. If this value is Null then Null is returned.

Interval—Description (Return value range)

yyyy—Year (100-9999)

q—Quarter (1-4)

m—Month (1-12)

y—Day of year (1-366)

d—Day (1-31)

w—Weekday (1-7)

ww—Week (1-53)

h—Hour (0-23)

n—Minute (0-59)

s—Second (0-59)

Example:

Sub Main
Debug.Print DatePart("yyyy",#1/1/2000#) ' 2000
End Sub

DateSerial

Syntax:

DateSerial(Year, Month, Day)

Group:

Time/Date

Description:

Return a date value.

Parameters:

Year—his numeric value is the year (0 to 9999). (0 to 99 are interpreted by the operating system.)

Month—This numeric value is the month (1 to 12).

Day—This numeric value is the day (1 to 31).

Example:

Sub Main
Debug.Print DateSerial(2000,7,4) '7/4/2000
End Sub

DateValue

Syntax:

DateValue(Date$)

Group:

Time/Date

Description:

Return the day part of the date encoded as a string.

Parameters:

Date$—Convert this string value to the day part of date it represents.

Example:

Sub Main
Debug.Print DateValue("1/1/2000 12:00:01 AM") '1/1/2000
End Sub

Day

Syntax:

Day(dateexpr)

Group:

Time/Date

Description:

Return the day of the month (1 to 31).

Parameters:

dateexpr—Return the day of the month for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Day(#1/1/1900#) ' 1
Debug.Print Day(#1/2/1900#) ' 2
End Sub

DDEInitiate

Syntax:

DDEInitiate(App$, Topic$)

Group:

DDE

Description:

Initiate a DDE conversation with App$ using Topic$. If the conversation is successfully started then the return value is a channel number that can be used with other DDE instructions and functions.

Parameters:

App$—Locate this server application.

Topic$—This is the server application's topic. The interpretation of this value is defined by the server application.

Example:

Sub Main
ChanNum = DDEInitiate("PROGMAN","PROGMAN")
DDEExecute ChanNum,"[CreateGroup(XXX)]"
DDETerminate ChanNum
End Sub

DDERequest

Syntax:

DDERequest[$](ChanNum, Item$[, Timeout])

Group:

DDE

Description:

Request information for Item$. If the request is not satisfied then the return value will be a null string.

Parameters:

ChanNum—This is the channel number returned by the DDEInitiate function. Up to 10 channels may be used at one time.

Item$—This is the server application's item. The interpretation of this value is defined by the server application.

Timeout—The command will generate an error if the number of seconds specified by the timeout is exceeded before the command has completed. The default is five seconds.

Example:

Sub Main
ChanNum = DDEInitiate("PROGMAN","PROGMAN")
Debug.Print DDERequest$(ChanNum,"Groups")
DDETerminate ChanNum
End Sub

Decode64

Syntax:

Decode64[$](Data)

-or-

Decode64B(Data)

Group:

Miscellaneous

Description:

Returns a string using the base 64 decoding algorithm.

Decode64B returns a Byte array.

Parameters:

Data—Return this string's base 64 decoding.

Example:

Sub Main
Debug.Print Decode64("SGVsbG8gV29ybGQhIQ==") '"Hello World!!"
End Sub

Decrypt64

Syntax:

Decrypt64[$](Data [,Password])

-or-

Decrypt64B(Data [,Password])

Group:

Miscellaneous

Description:

Returns a string using the RC4 stream decryption algorithm.

Decrypt64B returns a Byte array.

Parameters:

Data—Return this string's decryption. (The string is first decoded using base 64 decoding.)

Password—Decrypt using this password.

Example:

Sub Main
Debug.Print Decrypt64("Y4GFrF+k1YUHwjEzsg==", "abc") '"Hello World!!"
End Sub

Dialog Instruction/Function

Syntax:

Dialog dialogvar[, default]

-or-

Dialog(dialogvar[, default])

Group:

User Input

Description:

Display the dialog associated with dialogvar. The initial values of the dialog fields are provided by dialogvar. If any button is clicked, then the fields in the dialog are copied to the dialogvar. The Dialog( ) function returns a value indicating which button was clicked. (See the result table below.)

Parameters:

dlgvar—This variable that holds the values of the fields in a dialog. Use field to access individual fields in a dialog variable.

default—This numeric value indicates which button is the default button. (Pressing the Enter key on a non-button pushes the default button.) Use -2 to indicate that there is no default button. Other possible values are shown the result table below. If this value is omitted then the first PushButton, OKButton or CancelButton is the default button.

Result—Description

-1—This variable that holds the values of the fields in a dialog. Use field to access individual fields in a dialog variable.

0—This numeric value indicates which button is the default button. (Pressing the Enter key on a non-button pushes the default button.) Use -2 to indicate that there is no default button. Other possible values are shown the result table below. If this value is omitted then the first PushButton, OKButton or CancelButton is the default button.

>0—Nth push button was pressed.

Example:

Sub Main
Begin Dialog UserDialog 200,120
Text 10,10,180,15,"Please push the OK button"
OKButton 80,90,40,20
End Dialog
Dim dlg As UserDialog
Dialog dlg ' show dialog (wait for ok)
End Sub

Dir

Syntax:

Dir[$]([Pattern$][, AttribMask])

Group:

File

Description:

Scan a directory for the first file matching Pattern$.

Parameters:

Pattern$—This string value is the path and name of the file search pattern. If this is omitted then continue scanning with the previous pattern. Each macro has its own independent search. A path relative to the current directory can be used.

AttribMask—This numeric value indicates which button is the default button. (Pressing the Enter key on a non-button pushes the default button.) Use -2 to indicate that there is no default button. Other possible values are shown the result table below. If this value is omitted then the first PushButton, OKButton or CancelButton is the default button.

Example:

Sub Main
F$ = Dir$("*.*")

While F$ <> ""
Debug.Print F$
F$ = Dir$()
Wend
End Sub

DirectCast

Syntax:

DirectCast(expr, objtype)

Group:

Conversion

Description:

Return expr's type is related to objtype type. If it is not, a "type mismatch error" will occur.

Parameters:

expr—Cast the value of this expression.

objtype—Cast to this type.

Example:

Sub Main

Dim V As Object

V = Err
Debug.Print TypeName(DirectCast(V, ErrObject)) ' ErrObject
End Sub

DlgControlId

Syntax:

DlgControlId(DlgItem)

Group:

Dialog Function

Description:

Return the field's window id.
This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Hello"
End Dialog

Dim dlg As UserDialog
Debug.Print Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
If DlgItem$ = "Hello" Then
DialogFunc% = True 'do not exit the dialog
End If
Case 4 ' Focus changed
Debug.Print "DlgFocus=""";DlgFocus();""""
Debug.Print "DlgControlId(";DlgItem$;")=";
Debug.Print DlgControlId(DlgItem$)
End Select
End Function

DlgCount

Syntax:

DlgCount()

Group:

Dialog Function

Description:

Return the number of dialog items in the dialog.
This instruction/function must be called directly or indirectly from a dialogfunc.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Debug.Print "DlgCount=";DlgCount() ' 3
End Select
End Function

DlgEnable Instruction/Function

Syntax:

DlgEnable DlgItem, Enable]

-or-

DlgEnable(DlgItem)

Group:

Dialog Function

Description:

·         Instruction: Enable or disable DlgItem.

·         Function: Return True if DlgItem is enabled.

This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Note: Use -1 to enable or disable all the dialog items at once.

default—IF this numeric value is True then enable DlgItem|$. Otherwise, disable it. If this omitted then toggle it.

Enable It this numeric value is True then enable DlgItem|$. Otherwise, disable it. If this omitted then toggle it.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Disable"
End Dialog

Dim dlg As UserDialog
Debug.Print Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
Select Case DlgItem$
Case "Disable"
DlgText DlgItem$,"&Enable"
DlgEnable "Text",False
DialogFunc% = True 'do not exit the dialog
Case "Enable"
DlgText DlgItem$,"&Disable"
DlgEnable "Text",True
DialogFunc% = True 'do not exit the dialog
End Select
End Select
End Function

DlgFocus Instruction/Function

Syntax:

DlgFocus DlgItem

or

DlgFocus[$]()

Group:

Dialog Function

Description:

·         Instruction: Move the focus to this DlgItem.

·         Function: Return the field name which has the focus as a string.

This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Hello"
End Dialog
Dim dlg As UserDialog
Debug.Print Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
If DlgItem$ = "Hello" Then
MsgBox "Hello"
DialogFunc% = True 'do not exit the dialog
End If
Case 4 ' Focus changed
Debug.Print "DlgFocus=""";DlgFocus();""""
End Select
End Function

DlgListBoxArray Instruction/Function

Syntax:

DlgListBoxArray DlgItem, StrArray$( )

-or-

DlgListBoxArray(DlgItem[, StrArray$( )])

Group:

Dialog Function

Description:

·         Instruction: Set the list entries for DlgItem.

·         Function: Return the number entries in DlgItem's list.

This instruction/function must be called directly or indirectly from a dialogfunc. The DlgItem|$ should refer to a ComborBox, DropListBox or ListBox.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

StrArray$( )—Set the list entries of DlgItem|$. This one-dimensional array of strings establishes the list of choices. All the non-null elements of the array are used.

Example:

Dim lists$()
Sub Main
ReDim lists$(0)
lists$(0) = "List 0"
Begin Dialog UserDialog 200,119,.DialogFunc
Text 10,7,180,14,"Please push the OK button"
ListBox 10,21,180,63,lists(),.list
OKButton 30,91,40,21
PushButton 110,91,60,21,"&Change"
End Dialog
Dim dlg As UserDialog
dlg.list = 2
Dialog dlg ' show dialog (wait for ok)
Debug.Print dlg.list
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Select Case Action%
Case 2 ' Value changing or button pressed
If DlgItem$ = "Change" Then
Dim N As Integer
N = UBound(lists$)+1
ReDim Preserve lists$(N)
lists$(N) = "List " & N
DlgListBoxArray "list",lists$()
DialogFunc% = True 'do not exit the dialog
End If
End Select
End Function

DlgName

Syntax:

DlgName[$](DlgItem)

Group:

Dialog Function

Description:

Return the field name of the DlgItem number.
This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—This numeric value is the dialog item number. The first item is 0, second is 1, etc.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc

Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
For I = 0 To DlgCount()-1
Debug.Print I;DlgName(I)
Next I
End Select
End Function

DlgNumber

Syntax:

DlgNumber(DlgItem$)

Group:

Dialog Function

Description:

Return the number of the DlgItem$. The first item is 0, second is 1, etc.
This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem$—This string value is the dialog item's field name.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 4 ' Focus changed
Debug.Print DlgItem$;"=";DlgNumber(DlgItem$)
End Select
End Function

DlgText Instruction/Function

Syntax:

DlgText DlgItem, Text

or

DlgText[$](DlgItem|$)

Group:

Dialog Function

Description:

·         Instruction: Set the text for DlgItem

·         Function: Return the text from DlgItem.

This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Note: Use -1 to access the dialog's title.

Text—Set the text of DlgItem to this string value

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Now"
End Dialog
Dim dlg As UserDialog
Debug.Print Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
Select Case DlgItem$
Case "Now"
DlgText "Text",CStr(Now)
DialogFunc% = True 'do not exit the dialog
End Select
End Select
End Function

DlgType

Syntax:

DlgType[$](DlgItem)

Group:

Dialog Function

Description:

Return a string value indicating the type of the DlgItem|$. One of: "CancelButton", "CheckBox", "ComboBox", "DropListBox", "GroupBox", "ListBox", "OKButton", "OptionButton", "OptionGroup", "PushButton", "Text", "TextBox".
This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
For I = 0 To DlgCount()-1
Debug.Print I;DlgType(I)
Next I
End Select
End Function

DlgValue Instruction/Function

Syntax:

DlgValue DlgItem, Value

-or-

DlgValue(DlgItem)

Group:

Dialog Function

Description:

Instruction: Set the numeric value(S) DlgItem.

Function:
Return the numeric value for(S) DlgItem. (A MultiListBox user dialog item returns an array.)

This instruction/function must be called directly or indirectly from a dialogfunc. The DlgItem should refer to a CheckBox, ComboBox, DropListBox, ListBox or OptionGroup.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Text Set the text of DlgItem to this string value.

Value—Set the text of DlgItem to this numeric value. (A MultiListBox user dialog item uses an array.)

Example:

Sub Main
Begin Dialog UserDialog 150,147,.DialogFunc
GroupBox 10,7,130,77,"Direction",.Field1
PushButton 100,28,30,21,"&Up"
PushButton 100,56,30,21,"&Dn"
OptionGroup.Direction
OptionButton 20,21,80,14,"&North",.North
OptionButton 20,35,80,14,"&South",.South
OptionButton 20,49,80,14,"&East",.East
OptionButton 20,63,80,14,"&West",.West
OKButton 10,91,130,21
CancelButton 10,119,130,21
End Dialog
Dim dlg As UserDialog
Dialog dlg
MsgBox "Direction=" & dlg.Direction
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
Select Case DlgItem$
Case "Up"
DlgValue "Direction",0
DialogFunc% = True 'do not exit the dialog
Case "Dn"
DlgValue "Direction",1
DialogFunc% = True 'do not exit the dialog
End Select
End Select
End Function

DlgVisible Instruction/Function

Syntax:

DlgVisible DlgItem[, Visible]

or

DlgVisible(DlgItem)

Group:

Dialog Function

Description:

Instruction: Show or hide DlgItem

Function: Return True if DlgItem is visible.

This instruction/function must be called directly or indirectly from a dialogfunc.

Parameters:

DlgItem—If this is a numeric value then it is the dialog item number. The first item is 0, second is 1, etc. If this is a string value then it is the dialog item's field name.

Enable—If this numeric value is True then show DlgItem. Otherwise, hide it. If this omitted then toggle it.

Example:

Sub Main
Begin Dialog UserDialog 200,120,.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Hide"
End Dialog
Dim dlg As UserDialog
Debug.Print Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Debug.Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing or button pressed
Select Case DlgItem$
Case "Hide"
DlgText DlgItem$,"&Show"
DlgVisible "Text",False
DialogFunc% = True 'do not exit the dialog
Case "Show"
DlgText DlgItem$,"&Hide"
DlgVisible "Text",True
DialogFunc% = True 'do not exit the dialog
End Select
End Select
End Function

Encode64

Syntax:

Encode64[$](Data)

-or-

Encode64B[$](Data)

Group:

Miscellaneous

Description:

Return a string using the base 64 encoding algorithm.

Parameters:

Data—Return this string's base 64 decoding.

Example:

Sub Main
Debug.Print Encode64("Hello World!!") '"SGVsbG8gV29ybGQhIQ=="
End Sub

Encrypt64

Syntax:

Encrypt64[$](Data[,Password])

Group:

Miscellaneous

Description:

Return a string using the RC4 stream encryption algorithm. (The string is also encoded using base 64 encoding.)

Parameters:

Data—Return this string's encryption.

Password—Encrypt using this password.

Example:

Sub Main
Debug.Print Encrypt64("Hello World!!", "abc") '"Y4GFrF+k1YUHwjEzsg=="
End Sub

Environ

Syntax:

Environ[$](Index)

-or-

Environ[$](Name)

Group:

Miscellaneous

Description:

Return an environment string.

Parameters:

Index—Return this environment string's value. If there is no environment string at this index a null string is returned. Indexes start at one.

Name—Return this environment string's value. If the environment string can't be found a null string is returned.

Example:

Sub Main
Debug.Print Environ("Path")
End Sub

EOF

Syntax:

EOF(StreamNum)

Group:

File

Description:

Return True if StreamNum is at the end of the file.

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Open "XXX" For Input As #1
While Not EOF(1)
Line Input #1,L$
Debug.Print L$
Wend
Close #1
End Sub

Error Instruction/Function

Syntax:

Error ErrorCode

-or-

Error[$]([ErrorCode])

Group:

Error Handling

Description:

·   Instruction: Signal error ErrorCode. This triggers error handling just like a real error. The current procedure's error handler is activated, unless it is already active or there isn't one. In that case the calling procedure's error handler is tried. (Use Err.Raise to provide complete error information.)

·   Function: The Error( ) function returns the error text string.

Parameters:

ErrorCode—Return the absolute value of this numeric value. If this value is Null then Null is returned.

Example:

Sub Main
On Error GoTo Problem
Err.Raise 1 ' simulate error #1
Exit Sub

Problem: ' error handler
Debug.Print "Error$=";Error$
Resume Next
End Sub

ErrorToString

Syntax:

ErrorToString(ErrorCode)

Group:

Error Handling

Description:

The ErrorToString function returns the error text string.

Parameters:

ErrorCode—This is the error number.

Example:

Sub Main

On Error GoTo Problem

Error 1 ' simulate error #1

Exit Sub

Problem: ' error handler

Debug.Print "Description="; ErrorToString(Err.Num)

Resume Next

End Sub

Eval

Syntax:

Eval(Expr[, Depth])

Group:

Miscellaneous

Description:

Return the value of the string expression as evaluated.

Parameters:

Expr—Evaluate this string value.

Depth—This integer value indicates how deep into the stack to locate the local veriables. If Depth = 0 then use the current procedure. If this value is omitted then the depth is 0.

Example:

Sub Main
Dim X As String
X = "Hello"
Debug.Print Eval("X") 'Hello
A
End Sub

Sub A
Dim X As String
X = "Bye"
Debug.Print Eval("X") 'Bye
Debug.Print Eval("X",1) 'Hello
End Sub

Exp

Syntax:

Exp(Num)

Group:

Math

Description:

Return the exponential.

Parameters:

Num—Return e raised to the power of this numeric value. The value e is approximately 2.718282.

Example:

Sub Main
Debug.Print Exp(1) ' 2.718281828459
End Sub

FileAttr

Syntax:

FileAttr(StreamNum, ReturnValue)

Group:

File

Description:

Return StreamNum's open mode or file handle.

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

ReturnValue—1 - return the mode used to open the file: 1=Input, 2=Output, 4=Random, 8=Append, 32=Binary

2 - return the file handle

Example:

Sub Main
Open "XXX" For Output As #1
Debug.Print FileAttr(1,1) ' 2
Close #1
End Sub

FileDateTime

Syntax:

FileDateTime(Name$)

Group:

File

Description:

Return the date and time file Name$ was last changed as a Date value. If the file does not exist then a run-time error occurs.

Parameters:

Name$—This string value is the path and name of the file. A path relative to the current directory can be used.

Example:

Sub Main
F$ = Dir$("*.*")
While F$ <> ""
Debug.Print F$;" ";FileDateTime(F$)
F$ = Dir$()
Wend
End Sub

FileLen

Syntax:

FileLen(Name$)

Group:

File

Description:

Return the length of file Name$. If the file does not exist then a run-time error occurs.

Parameters:

Name$—This string value is the path and name of the file. A path relative to the current directory can be used.

Example:

Sub Main
F$ = Dir$("*.*")
While F$ <> ""
Debug.Print F$;" ";FileLen(F$)
F$ = Dir$()
Wend
End Sub

Fix

Syntax:

Fix(Num)

Group:

Math

Description:

Return the integer value.

Parameters:

Num—Return the integer portion of this numeric value. The number is truncated. Positive numbers return the next lower integer. Negative numbers return the next higher integer. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Fix(9.9) ' 9
Debug.Print Fix(0) ' 0
Debug.Print Fix(-9.9) '-9
End Sub

Format

Syntax:

Format[$](expr[, form$], [firstday], [firstweek])

Group:

String

Description:

Return the formatted string representation of expr.

Parameters:

expr—Return the formatted string representation of this numeric value.

form—Format expr using to this string value. If this is omitted then return the expr as a string.

firstday—Format using this day as the first day of the week. If this is omitted then the vbSunday is used.

firstweek—Format using this week as the first week of the year. If this is omitted then the vbFirstJan1 is used.

firstday—Value—Description (Return value range)

vbUseSystemFirstDay—0—Use the systems first day of the week.

vbSunday—1—Sunday (default)

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

firstweek—Value—Description (Return value range)

vbUseSystem—0—Use the systems first day of the week.

vbFirstJan1—1—Sunday (default)

2—vbFirstFourDays—Monday

3—vbFirstFullWeek—Tuesday

FreeFile

Syntax:

FreeFile[( )]

Group:

File

Description:

Return the next unused shared stream number (greater than or equal to 256). Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Debug.Print FreeFile ' 256
FN = FreeFile
Open "XXX" For Output As #FN
Debug.Print FreeFile ' 257
Close #FN
Debug.Print FreeFile ' 256
End Sub

GetAllSettings

Syntax:

GetAllSettings(AppName$, Section$, Key$)

Group:

Settings

Description:

Get all of Section's settings in project AppName. Settings are returned in a Variant. Empty is returned if there are no keys in the section. Otherwise, the Variant contains a two dimension array: (I,0) is the key and (I,1) is the setting. Win16 and Win32s store settings in a.ini file named AppName. Win32 stores settings in the registration database.

Parameters:

AppName$—This string value is the name of the project which has this Section and Key.

Section$—This string value is the name of the section of the project settings.

Example:

Sub Main
SaveSetting "MyApp","Font","Size",10
SaveSetting "MyApp","Font","Name","Courier"
Settings = GetAllSettings("MyApp","Font")
For I = LBound(Settings) To UBound(Settings)
Debug.Print Settings(I,0); "="; Settings(I,1)
Next I
DeleteSetting "MyApp","Font"
End Sub

GetAttr

Syntax:

GetAttr(Name$)

Group:

File

Description:

Return the attributes for file Name$. If the file does not exist then a run-time error occurs.

Parameters:

Name$—This string value is the path and name of the file. A path relative to the current directory can be used.

Example:

Sub Main
F$ = Dir$("*.*")
While F$ <> ""
Debug.Print F$;" ";GetAttr(F$)
F$ = Dir$()
Wend
End Sub

GetChar

Syntax:

GetChar(Str, Index)

Group:

String

Description:

Return the character at Index. The first char is at Index=1.

Parameters:

Str—Index into this string value.

Index—This is the index into the string value.

Example:

Sub Main
Debug.Print GetChar("abcd",2) '"b"
End Sub

GetFilePath

Syntax:

GetFilePath[$]([DefName$], [DefExt$], [DefDir$], [Title$], [Option])

Group:

User Input

Description:

Put up a dialog box and get a file path from the user. The returned string is a complete path and file name. If Cancel is pressed then a null string is returned.

Parameters:

DefName$—Set the initial File Name in the to this string value. If this is omitted then *.DefExt$ is used.

DefExt$—Initially show files whose extension matches this string value. (Multiple extensions can be specified by using ";" as the separator.) If this is omitted then * is used.

A "filter" may be specified using "description|*.ext|". Multiple descriptions can be used by repeating this format. (e.g., "Bitmap files|*.bmp|PNG files|*.png|JPEG files|*.jpg")

DefDir$—This string value is the initial directory. If this is omitted then the current directory is used.

Title$—This string value is the title of the dialog. If this is omitted then "Get File Path" is used.

Option—This numeric value determines the file selection options. If this is omitted then zero is used. See table below.

Option—Effect

0—Only allow the user to select a file that exists.

1—Confirm creation when the user selects a file that does not exist.

2—Allow the user to select any file whether it exists or not.

3—Confirm overwrite when the user selects a file that exists.

4—Selecting a different directory changes the application's current directory.

Example:

Sub Main
Debug.Print GetFilePath$()
End Sub

GetLocale

Syntax:

GetLocale

Group:

Miscellaneous

Description:

Get the locale ID for the current thread.

Example:

Sub Main

SetLocale &H409 ' English, US

Debug.Print Hex(GetLocale) '"409"
End Sub

GetObject

Syntax:

GetObject([File$][, Class$])

Group:

Object

Description:

Get an existing object of type Class$ from File$. Use Set to assign the returned object to an object variable.

Parameters:

File$—This is the file where the object resides. If this is omitted then the currently active object for Class$ is returned.

Class$—This string value is the application's registered class name. If this application is not currently active it will be started. If this is omitted then the application associated with the file's extension will be started.

Example:

Sub Main
Dim App As Object
Set App = GetObject(,"WinWrap.CppDemoApplication")
App.Move 20,30 ' move icon to 20,30
Set App = Nothing
App.Quit ' run-time error (no object)
End Sub

GetSetting

Syntax:

GetSetting[$](AppName$, Section$, Key$[, Default$])

Group:

Settings

Description:

Get the setting for Key in Section in project AppName. Win16 and Win32s store settings in a.ini file named AppName. Win32 stores settings in the registration database.

Parameters:

AppName$—This string value is the name of the project which has this Section and Key.

Section$—This string value is the name of the section of the project settings.

Key$—This string value is the name of the key in the section of the project settings.

Default$—Return this string value if no setting has been saved. If this is omitted then a null string is used.

Example:

Sub Main
SaveSetting "MyApp","Font","Size",10
Debug.Print GetSetting("MyApp","Font","Size") ' 10
End Sub

Hex

Syntax:

Hex[$](Num)

Group:

String

Description:

Return a hex string.

Parameters:

Num—Return a hex encoded string for this numeric value.

Example:

Sub Main
Debug.Print Hex$(15) 'F
End Sub

Hour

Syntax:

Hour(dateexpr)

Group:

Time/Date

Description:

Return the hour of the day (0 to 23).

Parameters:

dateexpr—Return the hour of the day for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Hour(#12:00:01 AM#) ' 0
End Sub

IIf

Syntax:

IIf(condexpr, TruePart, FalsePart)

Group:

Miscellaneous

Description:

Return the value of the parameter indicated by condexpr. Both TruePart and FalsePart are evaluated.

Parameters:

condexpr—If this value is True then return TruePart. Otherwise, return FalsePart.

TruePart—Return this value if condexpr is True.

FalsePart—Return this value if condexpr is False.

See Also:

If, Select Case, Choose( ).

Example:

Sub Main
Debug.Print IIf(1 > 0,"True","False") '"True"
End Sub

Input

Syntax:

Input[$](N, StreamNum)

Group:

File

Description:

Return N chars from StreamNum.

Parameters:

N—Read this many chars. If fewer than that many chars are left before the end of file then a run-time error occurs.

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Open "XXX" For Input As #1
L = LOF(1)
T$ = Input$(L,1)
Close #1
Debug.Print T$;
End Sub

InputBox

Syntax:

InputBox[$](Prompt$[, Title$][, Default$][, XPos, YPos])

Group:

User Input

Description:

Display an input box where the user can enter a line of text. Pressing the OK button returns the string entered. Pressing Cancel returns a null string.

Parameters:

Prompt$—Use this string value as the prompt in the input box.

Title$—Use this string value as the title of the input box. If this is omitted then the input box does not have a title.

Default$—Use this string value as the initial value in the input box. If this is omitted then the initial value is blank.

XPos—When the dialog is put up the left edge will be at this screen position. If this is omitted then the dialog will be centered.

YPos—When the dialog is put up the top edge will be at this screen position. If this is omitted then the dialog will be centered.

Example:

Sub Main
L$ = InputBox$("Enter some text:", "Input Box Example","asdf")
Debug.Print L$
End Sub

InputString

Syntax:

InputString(StreamNum, N)

Group:

File

Description:

Return N chars from StreamNum.

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

N—Return a hex encoded string for this numeric value.

Example:

Sub Main
FileOpen 1, "XXX", OpenMode.Input

DimL, T

L = LOrF(1)

T = InputString(1,L)

FileClose 1

Debug.Print T;
End Sub

InStr

Syntax:

InStr([Index, ]S1$, S2$)

Group:

String

Description:

Return the index where S2$ first matches S1$. If no match is found return 0.
NOTE:
A similar function, InStrB, returns the byte index instead.

Parameters:

Index—Start searching for S2$ at this index in S1$. If this is omitted then start searching from the beginning of S1$.

S1$—Search for S2$ in this string value. If this value is Null then Null is returned.

S2$—Search S1$ for this string value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print InStr("Hello","l") ' 3
End Sub

InStrRev

Syntax:

InStrRev(S1$, S2$[, Index])

Group:

String

Description:

Return the index where S2$ last matches S1$. If no match is found return 0.

Parameters:

S1$—Search for S2$ in this string value. If this value is Null then Null is returned.

S2$—Search S1$ for this string value. If this value is Null then Null is returned.

Index—Start searching for S2$ ending at this index in S1$. If this is omitted then start searching from the end of S1$.

See Also:

Left$( ), Len( ), Mid$( ), Replace$( ), Right$( ).

Example:

Sub Main
Debug.Print InStrRev("Hello","l") ' 4
End Sub

Int

Syntax:

Int(Num)

Group:

Math

Description:

Return the integer value.

Parameters:

Num—Return the largest integer which is less than or equal to this numeric value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Int(9.9) ' 9
Debug.Print Int(0) ' 0
Debug.Print Int(-9.9) '-10
End Sub

IsArray

Syntax:

IsArray(var)

Group:

Variable Info

Description:

Return the True if var is an array of values.

Parameters:

var—A array variable or a variant var can contain multiple of values.

Example:

Sub Main
Dim X As Variant, Y(2) As Integer
Debug.Print IsArray(X) 'False
X = Array(1,4,9)
Debug.Print IsArray(X) 'True
X = Y
Debug.Print IsArray(X) 'True
End Sub

IsDate

Syntax:

IsDate(expr)

Group:

Variable Info

Description:

Return the True if expr is a valid date.

Parameters:

expr—A variant expression to test for a valid date.

Example:

Sub Main
Dim X As Variant
X = 1
Debug.Print IsDate(X) 'False
X = Now
Debug.Print IsDate(X) 'True
End Sub

IsDBNull

Syntax:

IsDBNull(expr)

Group:

Variable Info

Description:

Returns True if expr is System.DBNull.Value..

Parameters:

expr—A variant expression to test for System.DBNull.Value.

Example:

Sub Main
DimX As Object

Debug.Print IsEmpty(X) 'True

Debug.Print IsDBNull(X) 'False

X = 1

Debug.Print IsDBNull(X) 'False

X = "1"

Debug.Print IsDBNull(X) 'False

X = System.DBNull.Value

Debug.Print IsDBNull(X) 'True

X = X*2

Debug.Print IsDBNull(X) 'True
End Sub

IsEmpty

Syntax:

IsEmpty(variantvar)

Group:

Variable Info

Description:

Return the True if variantvar is Empty.

Parameters:

Name$—A variant var is Empty if it has never been assigned a value.

Example:

Sub Main
Dim X As Variant
Debug.Print IsEmpty(X) 'True
X = 0
Debug.Print IsEmpty(X) 'False
X = Empty
Debug.Print IsEmpty(X) 'True
End Sub

IsError

Syntax:

IsError(expr)

Group:

Variable Info

Description:

Return the True if expr is an error code.

Parameters:

expr—A variant expression to test for an error code value.

Example:

Sub Main
Dim X As Variant
Debug.Print IsError(X) 'False
X = CVErr(1)
Debug.Print IsError(X) 'True
End Sub

IsMissing

Syntax:

IsMissing(expr)

Group:

Variable Info

Description:

Return the True if Optional parameter expr does not have a default value and it did not get a value. An Optional parameter may be omitted in the Sub, Function or Property call.

Parameters:

expr—Return True if this variant parameter's argument expression was not specified in the Sub, Function or Property call.

Example:

Sub Main
Opt 'IsMissing(A)=True
Opt "Hi" 'IsMissing(A)=False
Many 'No args
Many 1,"Hello" 'A(0)=1 A(1)=Hello
OptBye '"Bye"
OptBye "No" '"No"
End Sub

Sub Opt(Optional A)
Debug.Print "IsMissing(A)=";IsMissing(A)
End Sub

Sub Many(ParamArray A())
If LBound(A) > UBound(A) Then
Debug.Print "No args"
Else
For I = LBound(A) To UBound(A)
Debug.Print "A(" & I & ")=" & A(I) & " ";
Next I
Debug.Print
End If
End Sub

Sub OptBye(Optional A As String = "Bye")
Debug.Print A
End Sub

IsNothing

Syntax:

IsNothing(expr)

Group:

Variable Info

Description:

Returns True if the expr contains an object reference which is Nothing.

Parameters:

var—If objexpr reference is Nothing returns True.

Example:

Sub Main
DimX As Object

DimX As Object

X = 1

Debug.Print IsNothing(X) 'False

X = "1"

Debug.Print IsNothing(X) 'False

X = Nothing

Debug.Print IsNothing(X) 'True
End Sub

IsNull

Syntax:

IsNull(expr)

Group:

Variable Info

Description:

Return the True if expr is Null.

Parameters:

expr—A variant expression to test for Null.

Example:

Sub Main
Dim X As Variant
Debug.Print IsEmpty(X) 'True
Debug.Print IsNull(X) 'False
X = 1
Debug.Print IsNull(X) 'False
X = "1"
Debug.Print IsNull(X) 'False
X = Null
Debug.Print IsNull(X) 'True
X = X*2
Debug.Print IsNull(X) 'True
End Sub

IsNumeric

Syntax:

IsNumeric(expr)

Group:

Variable Info

Description:

Return the True if expr is a numeric value.

Parameters:

expr—A variant expression is a numeric value if it is numeric or string value that represents a number.

Example:

Sub Main
Dim X As Variant
X = 1
Debug.Print IsNumeric(X) 'True
X = "1"
Debug.Print IsNumeric(X) 'True
X = "A"
Debug.Print IsNumeric(X) 'False
End Sub

IsObject

Syntax:

IsObject(var)

Group:

Variable Info

Description:

Return the True if var contains an object reference.

Parameters:

var—A var contains an object reference if it is objexpr reference.

Example:

Sub Main
Dim X As Variant
X = 1
Debug.Print IsObject(X) 'False
X = "1"
Debug.Print IsObject(X) 'False
Set X = Nothing
Debug.Print IsObject(X) 'True
End Sub

IsReference

Syntax:

IsReference(expr)

Group:

Variable Info

Description:

Returns True if the expr contains an object reference.

Parameters:

var—If expris an object reference return True.

Example:

Sub Main
Dim X As Object

X = 1

Debug.Print IsReference(X) 'False

X = "1"

Debug.Print IsReference(X) 'False

X = Nothing

Debug.Print IsReference(X) 'True
End Sub

Join

Syntax:

Join(StrArray, [Sep])

Group:

Miscellaneous

Description:

Return a string by concatenating all the values in the array with Sep between each one.

Parameters:

StrArray—Concatenate values from this array.

Sep—Use this string value to separate the values. (Default: " ")

Example:

Sub Main
Debug.Print Join(Array(1,2,3)) '"1 2 3"
End Sub

KeyName

Syntax:

KeyName(Key)

Group:

Miscellaneous

Description:

Return the key name for a key number. This is the name used by SendKeys.

Parameters:

Key—Key number.

Example:

Sub Main
Debug.Print KeyName(&H270) '"^{F1}"
End Sub

LBound

Syntax:

LBound(arrayvar[, dimension])

Group:

Variable Info

Description:

Return the lowest index.

Parameters:

arrayvar—Return the lowest index for this array variable.

dimension—Return the lowest index for this dimension of arrayvar. If this is omitted then return the lowest index for the first dimension.

Example:

Sub Main
Dim A(-1 To 3,2 To 6)
Debug.Print LBound(A) '-1
Debug.Print LBound(A,1) '-1
Debug.Print LBound(A,2) ' 2
End Sub

LCase

Syntax:

LCase[$](S$)

Group:

String

Description:

Return a string from S$ where all the uppercase letters have been lowercased.

Parameters:

S$—Return the string value of this after all chars have been converted to lowercase. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print LCase$("Hello") '"hello"
End Sub

Left

Syntax:

Left[$](S$, Len)

Group:

String

Description:

Return a string from S$ with only the Len chars.

NOTE
: A similar function, LeftB, returns the first Len bytes.

Parameters:

S$—Return the left portion of this string value. If this value is Null then Null is returned.

Len—Return this many chars. If S$ is shorter than that then just return S$.

Example:

Sub Main
Debug.Print Left$("Hello",2) '"He"
End Sub

Len

Syntax:

Len(S$)

-or-

Len(usertypevar)

Group:

String

Description:

Return the number of characters in S$.

NOTE
: A similar function, LenB, returns the number of bytes in the string. For a usertypevar, LenB returns the number of bytes of memory occupied by the variable's data.

Parameters:

S$—Return the number of chars in this string value. If this value is Null then Null is returned.

usertypevar—Return the number of bytes required to store this user type variable. If the user type has any dynamic String and Variant elements the length returned may not be as big as the actual number of bytes required.

Example:

Sub Main
Debug.Print Len("Hello") ' 5
End Sub

LineInput

Syntax:

LineInput(StreamNum)

Group:

File

Description:

Get a line of input from StreamNum.

Example:

Sub Main
FileOpen 1, "XXX", OpenMode.Input

Dim S As String

S = LineInput(1)

Debug.Print S

FileClose 1

End Sub

Loc

Syntax:

Loc(StreamNum)

Group:

File

Description:

Return StreamNum file position. For Random mode files this is the current record number minus one. For Binary mode files it is the current byte position minus one. Otherwise, it is the current byte position minus one divided by 128. The first position in the file is 0.

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Open "XXX" For Input As #1
L = Loc(1)
Close #1
Debug.Print L ' 0
End Sub

LOF

Syntax:

LOF(StreamNum)

Group:

File

Description:

Return StreamNum file length (in bytes).

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Open "XXX" For Input As #1
L = LOF(1)
Close #1
Debug.Print L
End Sub

Log

Syntax:

Log(Num)

Group:

Math

Description:

Return the natural logarithm.

Parameters:

Num—Return the natural logarithm of this numeric value. The value e is approximately 2.718282.

Example:

Sub Main
Debug.Print Log(1) ' 0
End Sub

LSet

Syntax:

LSet(S, var)

Group:

String

Description:

Return a string from S with only the Len chars.

Parameters:

S—Return the left portion of this string value.

var—Return this many chars. If S is shorter than that then fill the remainder with spaces

Example:

Sub Main
Debug.Print LSet("Hello",6) '"Hello "

End Sub

LTrim

Syntax:

LTrim[$](S$)

Group:

String

Description:

Return the string with S$'s leading spaces removed.

Parameters:

S$—Copy this string without the leading spaces. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print ".";LTrim$(" x ");"." '".x."
End Sub

MacroCheck

Syntax:

MacroCheck(MacroName$)

Group:

Flow Control

Description:

Check the syntax of a macro/module. Does not execute the macro/module. Returns an Err object if there is a syntax error, otherwise Nothing is returned.

Parameters:

MacroName$—Check the macro named by this string value.

Example:

Sub Main
Dim E As ErrObject

Set E = MacroCheck("Demo")

If Not E Is Nothing Then Debug.Print E.Description
End Sub

MacroCheckThis

Syntax:

MacroCheckThis(MacroCode$)

Group:

MacroName$

Description:

Return the True if expr is a numeric value.

Parameters:

MacroName$—Check the macro code in this string value.

Example:

Sub Main
Dim E As ErrObject

Set E = MacroCheckThis("bad macro")

If Not E Is Nothing Then Debug.Print E.Description
End Sub

MacroDir

Syntax:

MacroDir[$]

Group:

Flow Control

Description:

Return the directory of the current macro. A run-time error occurs if the current macro has never been saved.

Example:

Sub Main
' open the file called Data that is in the
' same directory as the macro
Open MacroDir & "\Data" For Input As #1
Line Input #1, S$
Debug.Print S$
Close #1
End Sub

Mid Function/Assignment

Syntax:

Mid[$](S$, Index[, Len])

-or-

Mid[$](strvar, Index[, Len]) = S$

Group:

String

Description:

Function: Return the substring of S$ starting at Index for Len chars.

Instruction: Assign S$ to the substring in strvar starting at Index for Len chars.

Note: A similar function, MidB, returns the Len bytes starting a byte Index.

Parameters: (Mid Function)

S$—Copy chars from this string value. If this value is Null then Null is returned.

Index—Start copying chars starting at this index value. If the string is not that long then return a null string.

Len—Copy this many chars. If the S$ does not have that many chars starting at Index then copy the remainder of S$.

Parameters: (Mid Assignment)

strvar—Copy chars from this string value. If this value is Null then Null is returned.

Index—Change strvar starting at this index value. If the string is not that long then it is not changed.

S$—Copy chars from this string value.

Len—The number of chars copied is smallest of: the value of Len, the length of S$ and the remaining length of strvar. (If this value is omitted then the number of chars copied is the smallest of: the length of S$ and the remaining length of strvar.)

Example:

Sub Main
S$ = "Hello There"
Mid$(S$,7) = "?????????"
Debug.Print S$ '"Hello ?????"
Debug.Print Mid$("Hello",2,1) '"e"
End Sub

Minute

Syntax:

Minute(dateexpr)

Group:

Time/Date

Description:

Return the minute of the hour (0 to 59).

Parameters:

dateexpr—Return the minute of the hour for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Minute(#12:00:01 AM#) ' 0
End Sub

ModuleLoad

Syntax:

ModuleLoad(ModuleName$, CreateNew)

Group:

Flow Control

Description:

Load a module. Does not execute the module. Macro's can not be loaded. Returns an object if successful, otherwise Nothing is returned.

Parameters:

MacroName$—Check the macro named by this string value.

Example:

Sub Main
Dim E As ErrObject

Set E = MacroCheckThis("Demo")

If Not E Is Nothing Then Debug.Print E.Description
End Sub

ModuleLoadThis

Syntax:

ModuleLoadThis(ModuleCode$, CreateNew)

Group:

Flow Control

Description:

Load ModuleCode as a module. Does not execute the module. Macro's can not be loaded. Returns an object if successful, otherwise Nothing is returned.

Parameters:

ModuleCode$—Load the module code in this string value.

CreateNew—Return a new instance if True. Otherwise return the default instance. A class module does not have a default instance. A code module can not have a new instance.

Example:

Sub Main
Dim Obj As Object

Set Obj = ModuleLoadThis("Sub DoIt" & vbCrLf & "End Sub")

Obj.DoIt ' call Demo's DoIt method
End Sub

Month

Syntax:

Month(dateexpr)

Group:

Time/Date

Description:

Return the month of the year (1 to 12)

Parameters:

dateexpr—Return the month of the year for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Month(#1/1/1900#) ' 1
Debug.Print Month(#2/1/1900#) ' 2
End Sub

MonthName

Syntax:

MonthName(NumZ{month}[, CondZ{abbrev}])

Group:

Time/Date

Description:

Return the localized name of the month.

Parameters:

month—Return the localized name of this month. (1-12)

abbrev—If this conditional value is True then return the abbreviated form of the month name.

Example:

Sub Main
Debug.Print MonthName(1) 'January
Debug.Print MonthName(Month(Now))
End Sub

MsgBox Instruction/Function

Syntax:

MsgBox Message$[, Type][, Title$]

-or-

MsgBox(Message$[, Type][, Title$])

Group:

User Input

Description:

Show a message box titled Title$. Type controls what the message box looks like (choose one value from each category). Use MsgBox( ) if you need to know what button was pressed. The result indicates which button was pressed.

ResultValue—Button Pressed

vbOK—1—OK button

vbCancel—2—Cancel button

vbAbort—3—Abort button

vbRetry—4—Retry button

vbIgnore—5—Ignore button

vbYes—6—Yes button

vbNo—7—No button

Parameters:

Message$—This string value is the text that is shown in the message box.

Type—This numeric value controls the type of message box. Choose one value from each of the following tables.

Title$—This string value is the title of the message box.

Button—Value—Effect

vbOkOnly—1—OK button

vbOkCancel—2—OK and Cancel buttons

vbAbortRetryIgnore—3—Abort, Retry, Ignore buttons

vbYesNoCancel—4—Yes, No, Cancel buttons

vbYesNo—5—Yes and No buttons

vbRetryCancel—6—Retry and Cancel buttons

Icon—Value—Effect

 —0—No icon

vbCritical—16—Stop icon

vbQuestion—3—Question icon

vbExclamation—4—Attention icon

vbInformation—5—Information icon

Default—Value—Effect

vbDefaultButton1—0—First button

vbDefaultButton2—256—Second button

vbDefaultButton3—512—Third button

Default—Value—Effect

vbApplicationModal—0—Application modal

vbSystemModal—4096—System modal

vbMsgBoxSetForeground—&h10000—Show message box in front of all other windows

Example:

Sub Main
MsgBox "Please press OK button"
If MsgBox("Please press OK button",vbOkCancel) = vbOK Then
Debug.Print "OK was pressed"
Else
Debug.Print "Cancel was pressed"
End If
End Sub

Now

Syntax:

Now

Group:

Time/Date

Description:

Return the current date and time as a date value.

Example:

Sub Main
Debug.Print Now ' Example: 1/1/1995 10:05:32 AM
End Sub

Oct

Syntax:

Oct[$](Num)

Group:

String

Description:

Return an octal string.

Parameters:

Num—Return an octal encoded string for this numeric value.

Example:

Sub Main
Debug.Print Oct$(15) '17
End Sub

QBColor

Syntax:

QBColor(num)

Group:

Miscellaneous

Description:

Return the appropriate color defined by Quick Basic.

num—color

0—black

1—blue

2—green

3—cyan

4—red

5—magenta

6—yellow

7—white

8—gray

9—light blue

10—light green

11—light cyan

12—light red

13—light magenta

14—light yellow

15—bright white

Example:

Sub Main
Debug.Print Hex(QBColor(1)) '"800000"
Debug.Print Hex(QBColor(7)) '"C0C0C0"
Debug.Print Hex(QBColor(8)) '"808080"
Debug.Print Hex(QBColor(9)) '"FF0000"
Debug.Print Hex(QBColor(10)) '"FF00"
Debug.Print Hex(QBColor(12)) '"FF"
Debug.Print Hex(QBColor(15)) '"FFFFFF"
End Sub

Replace

Syntax:

Replace[$](S$, Pat$, Rep$, [Index], [Count])

Group:

String

Description:

Replace Pat$ with Rep$ in S$.

Parameters:

S$—This string value is searched. Replacements are made in the string returned by Replace.

Pat$—This string value is the pattern to look for.

Rep$—This string value is the replacement.

Index—This numeric value is the starting index in S$. Replace(S,Pat,Rep,N) is equivalent to Replace(Mid(S,N),Pat,Rep). If this is omitted use 1.

Count—This numeric value is the maximum number of replacements that will be done. If this is omitted use -1 (which means replace all occurrences).

Example:

Sub Main
Debug.Print Replace$("abcabc","b","B") '"aBcaBc"
Debug.Print Replace$("abcabc","b","B",,1) '"aBcabc"
Debug.Print Replace$("abcabc","b","B",3) '"caBc"
Debug.Print Replace$("abcabc","b","B",9) '""
End Sub

RGB

Syntax:

RGB(red, green, blue)

Group:

Miscellaneous

Description:

Return a color. Some useful color constants are predefined:

Color—RGB

vbBlack—same as RGB(0,0,0)

vbRed—same as RGB(255,0,0)

vbGreen—same as RGB(0,255,0)

vbYellow—same as RGB(255,255,0)

vbBlue—same as RGB(0,0,255)

vbMagenta—same as RGB(255,0,255)

vbCyan—same as RGB(0,255,255)

vbWhite—same as RGB(255,255,255)

Example:

Sub Main
Debug.Print Hex(RGB(255,0,0)) '"FF0000"
End Sub

Right

Syntax:

Right[$](S$, Len)

Group:

String

Description:

Return the last Len chars of S$.

NOTE: A similar function, RightB, returns the last Len bytes.

Parameters:

S$—Return the right portion of this string value. If this value is Null then Null is returned.

Len—Return this many chars. If S$ is shorter than that then just return S$.

Example:

Sub Main
Debug.Print Right$("Hello",3) '"llo"
End Sub

Rnd

Syntax:

Rnd([Num])

Group:

Math

Description:

Return a random number greater than or equal to zero and less than one.

NOTE: This function does not return properly randomized numbers unless Randomize is called first with a suitable seed. To avoid this problem and generate random numbers with ease, use RndEx, RndInt or RndFloat.

Parameters:

Num—See table below.

Num—Description

<0—Return the same number every time, using Num as the seed.

>0—Return the next random number in the sequence.

0—Return the most recently generated number.

omitted—Return the next random number in the sequence.

Example:

Sub Main
Debug.Print Rnd() ' 0.??????????????
End Sub

Round

Syntax:

Round([Num][, Places])

Group:

Math

Description:

Return the number rounded to the specified number of decimal places.

Parameters:

Num—Round this numeric value. If this value is Null then Null is returned.

Places—Round to this number of decimal places. If this is omitted then round to the nearest integer value.

Example:

Sub Main
Debug.Print Round(.5) ' 0
Debug.Print Round(.500001) ' 1
Debug.Print Round(1.499999) ' 1
Debug.Print Round(1.5) ' 2
Debug.Print Round(11.11) ' 11
Debug.Print Round(11.11,1) ' 11.1
End Sub

RSet

Syntax:

RSet(S, Len)

Group:

String

Description:

Return a string from S with only the Len chars.

Parameters:

S—Return this string value right justified.

Len—Return this many chars. If S is shorter than that, then fill the remainder with spaces.

Example:

Sub Main
Debug.Print RSet("Hello",6) '"Hello "
End Sub

RTrim

Syntax:

RTrim[$](S$)

Group:

String

Description:

Return the string with Sr$'s trailing spaces removed.

Parameters:

S$—Copy this string without the trailing spaces. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print ".";RTrim$(" x ");"." '". x."
End Sub

Second

Syntax:

Second(dateexpr)

Group:

Time/Date

Description:

Return the second of the minute (0 to 59).

Parameters:

dateexpr—Return the second of the minute for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Second(#12:00:01 AM#) ' 1
End Sub

Seek

Syntax:

Seek(StreamNum)

Group:

File

Description:

Return StreamNum current position. For Random mode files this is the record number. The first record is 1. Otherwise, it is the byte position. The first byte is 1.

NOTE: Unicode text files opened with Input mode use character positions, not byte positions.

Parameters:

StreamNum—Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Example:

Sub Main
Open "XXX" For Input As #1
Debug.Print Seek(1) ' 1
Line Input #1,L$
Debug.Print Seek(1)
Close #1
End Sub

Sgn

Syntax:

Sgn(Num)

Group:

Math

Description:

Return the sign.

Parameters:

Num—Return the sign of this numeric value. Return -1 for negative. Return 0 for zero. Return 1 for positive.

Example:

Sub Main
Debug.Print Sgn(9) ' 1
Debug.Print Sgn(0) ' 0
Debug.Print Sgn(-9) '-1
End Sub

Shell

Syntax:

Shell(Name$[, WindowType])

Group:

Miscellaneous

Description:

Execute program Name$. This is the same as using File|Run from the Program Manager. This instruction can run.COM,.EXE,.BAT and.PIF files. If successful, return the task ID.

Parameter Description

Name$ This string value is the path and name of the program to run. Command line arguments follow the program name. (A long file name containing a space must be surrounded by literal double quotes.)

WindowType This controls how the application's main window is shown. See the table below.

WindowType—Value—Effect

vbHide—0—Hide Window

vbNormalFocus—1,5,9—Normal Window

vbMinimizedFocus—2—Minimized Window (default)

vbMaximizedFocus—3—Maximized Window

vbNormalNoFocus—4,8—Normal Deactivated Window

vbMinimizedNoFocus—6,7—Minimized Deactivated Window

Example:

Sub Main
X = Shell("Calc") ' run the calc program
AppActivate X
SendKeys "% R" ' restore calc's main window
SendKeys "30*2{+}10=",1 '70
End Sub

ShowPopupMenu

Syntax:

ShowPopupMenu(StrArray$( )[, PopupStyle][, XPos, YPos])

Group: User Input

Description:
Show a popup menu and return the number of the item selected. The item number is the index of the StrArray selected minus LBound(StrArray). The value -1 is returned in no menu item is selected.

Parameter Description

StrArray$( ) This one-dimensional array of strings establishes the list of choices. All the non-null elements of the array are used.

PopupMenuStyle This controls how the popup menu is aligned. Any combination of styles may used together. See the table below.

XPos When the menu is put up the alignment will be at this window position. If this is omitted then the current mouse position is used.

YPos When the menu is put up the alignment will be at this window position. If this is omitted then the current mouse position is used.

PopupStyle Value Effect

vbPopupLeftTopAlign 0 Align menu left edge at XPos and top at YPos. (default)

vbPopupUseLeftButton 1 User can select menu choices with the left mouse button only.

vbPopupUseRightButton 2 User can select menu choices with the left or right mouse button.

vbPopupRightAlign 4 Align menu with right edge at the XPos.

vbPopupCenterAlign 8 Align menu center at the XPos.

vbPopupVCenterAlign 16 Align menu center at the YPos.

vbPopupBottomAlign 32 Align menu bottom at the YPos.

Example:

Sub Main
Dim Items(0 To 2) As String
Items(0) = "Item &1"
Items(1) = "Item &2"
Items(2) = "Item &3"
X = ShowPopupMenu(Items) ' show popup menu
Debug.Print X ' item selected
End Sub

Sin

Syntax:

Sin(Num)

Group:

Math

Description:

Return the sine.

Parameters:

Num—Return the sine of this numeric value. This is the number of radians. There are 2*Pi radians in a full circle.

Example:

Sub Main
Debug.Print Sin(1) ' 0.8414709848079
End Sub

Space

Syntax:

Space[$](Len)

Group:

String

Description:

Return the string Len spaces long.

Parameters:

Len—Create a string this many spaces long.

Example:

Sub Main
Debug.Print ".";Space$(3);"." '".."
End Sub

Split

Syntax:

Split(Str, [Sep], [Max])

Group:

Miscellaneous

Description:

Return a string array containing substrings from the original string.

Parameters:

Str—Extract substrings from this string value.

Sep—Look for this string value to separate the substrings. (Default: " ")

Max—Create at most this many substrings. (Default -1, which means create as many as are found.)

Example:

Sub Main
Debug.Print Split("1 2 3")(1) '"2"
End Sub

Sqr

Syntax:

Sqr(Num)

Group:

Math

Description:

Return the square root.

Parameters:

Num—Return the square root of this numeric value.

Example:

Sub Main
Debug.Print Sqr(9) ' 3
End Sub

Str$

Syntax:

Str[$](Num)

Group:

String

Description:

Return the string representation of Num.

Parameters:

Len—Return the string representation of this numeric value. Positive values begin with a blank. Negative values begin with a dash '-'.

Example:

Sub Main
Debug.Print Str$(9*9) ' 81
End Sub

StrComp

Syntax:

StrComp(Str1,Str2,Comp)

Group:

String

Description:

Compare two strings.

Parameters:

Str1—Compare this string with Str2. If this value is Null then Null is returned.

Str2—Compare this string with Str1. If this value is Null then Null is returned.

Comp—This numeric value indicates the type of comparison. See Comp table below.

Result—Description

-1—Str1 is less than Str2.

0—Str1 is equal to Str2.

1—Str1 is greater than Str2.

Null—Str1 or Str2 is Null.

Comp—Value—Effect

vbUseCompareOption—-1—Performs the comparison using the Option Compare statement value.

vbBinaryCompare—0—Compares the string's binary data.

vbTextCompare—1—Compares the string's text using the collation rules.

vbDatabaseCompare—2—Microsoft Access only. (Not supported.)

Example:

Sub Main
Debug.Print StrComp("F","e") ' -1
Debug.Print StrComp("F","e",1) ' 1
Debug.Print StrComp("F","f",1) ' 0
End Sub

StrConv

Syntax:

StrConv[$](Str,Conv)

Group:

String

Description:

Convert the string.

Parameters:

Str—Convert this string value. If this value is Null then Null is returned.

Conv—This numeric value indicates the type of conversion. See conversion table below.

Conv—Value—Effect

vbUpperCase—1—Convert a String to upper case.

vbLowerCase—2—Convert a String to lower case.

vbProperCase—3—Convert a String to proper case. (Not supported.)

vbWide—4—Convert a String to wide. (Only supported for eastern locales.)

vbNarrow—8—Convert a String to narrow. (Only supported for eastern locales.)

vbKatakana—16—Convert a String to Katakana. (Only supported for Japanese locales.)

vbHiragana—32—Convert a String to Hiragana. (Only supported for Japanese locales.)

vbUnicode or vbFromANSIBytes—64—Convert an ANSI (locale dependent) byte array to a Unicode string.

vbANSI—4160—Convert an ANSI (locale dependent) string to a Unicode string.

vbFromUnicode or vbANSIBytes—128—Convert from Unicode to an ANSI (locale dependent) byte array.

vbANSI—4224—Convert from Unicode to an ANSI (locale dependent) string.

vbUTF8—4352—Convert a Unicode string to a UTF-8 byte array.

vbUTF8Bytes—256—Convert a Unicode string to a UTF-8 string.

vbFromUTF8—4608—Convert a UTF-8 string to a Unicode string.

vbFromUTF8Bytes—512—Convert a UTF-8 byte array to a Unicode string.

vbToBytes—1024—Convert a String to a byte array containing the low byte of each char.

vbFromBytes—2048—Convert a byte array to a String by setting the low byte of each char.

Conversion Rules:

If multiple conversions are specified, the conversions occur in this order:

vbFromBytes, vbUnicode, vbFromANSI, vbFromANSIBytes, vbFromUTF8 or vbFromUTF8Bytes (choose one, optional)

vbUpperCase, vbLowerCase, vbWide, vbNarrow, vbKatakana or vbHiragana (choose one or more, optional)

vbToBytes, vbFromUnicode, vbANSI, vbANSIBytes, vbUTF8 or vbUTF8Bytes (choose one, optional)

Example:

Sub Main
Dim B(1 To 3) As Byte
B(1) = 65
B(2) = 66
B(3) = 67
Debug.Print

StrConv$(B,vbUnicode) '"ABC"
End Sub

StrDup

Syntax:

StrDup(Len, char)

Group:

String

Description:

Return the string Len long filled with char or the first char of char.

Parameters:

Len—Create a string this many chars long.

char—Fill the string with this char value. If this is a numeric value then use the ASCII char equivalent. If this is a string value use the first char of that string.

Example:

Sub Main
Debug.Print StrDup(4,65) '"AAAA"

Debug.Print StrDup(4,"ABC") '"AAAA"

End Sub

String

Syntax:

String[$](Len, Char)

Group:

String

Description:

Return the string Len long filled with Char or the first char of Char$.

Parameters:

Len—Create a string this many chars long.

Char—Fill the string with this char value. If this is a numeric value then use the ASCII char equivalent. If this is a string value use the first char of that string. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print String$(4,65) '"AAAA"
Debug.Print String$(4,"ABC") '"AAAA"
End Sub

StrReverse

Syntax:

StrReverse[$](S)

Group:

String

Description:

Return the string with the characters in reverse order.

Parameters:

S—Return this string with the characters in reverse order.

Example:

Sub Main
Debug.Print StrReverse$("ABC") 'CBA
End Sub

SystemTypeName

Syntax:

SystemTypeName(Name)

Group:

Variable Info

Description:

Return a fully qualified Common Language Runtime type name corresponding to the VB type name. Return Nothing if the specified Name is not a valid VB type Name.

Parameters:

Name—This is the VB type name.

Example:

Sub Main
Dim X As Object

Debug.Print SystemTypeName(X) '"Empty"

X = 1

Debug.Print SystemTypeName(X) '"Integer"
End Sub

Tan Function

Syntax:

Tan(Num)

Group:

Math

Description:

Return the tangent.

Parameters:

Num—Return the tangent of this numeric value.

Example:

Sub Main
Debug.Print Tan(1) ' 1.5574077246549
End Sub

Time

Syntax:

Time[$]

Group:

Time/Date

Description:

Return the current time as a date value.

Example:

Sub Main
Debug.Print Time ' Example: 09:45:00 am
End Sub

Timer

Syntax:

Timer

Group:

Time/Date

Description:

Return the number of seconds past midnight. (This is a real number, accurate to about 1/18th of a second.)

Example:

Sub Main
Debug.Print Timer ' example: 45188.13
End Sub

TimeSerial

Syntax:

TimeSerial(Hour, Minute, Second)

Group:

Time/Date

Description:

Return a date value.

Parameters:

Hour—This numeric value is the hour (0 to 23).

Minute—This numeric value is the minute (0 to 59).

Second—This numeric value is the second (0 to 59).

Example:

Sub Main
Debug.Print TimeSerial(13,30,0) '1:30:00 PM
End Sub

TimeValue

Syntax:

TimeValue(Date$)

Group:

Time/Date

Description:

Return the time part of date encoded as a string value.

Parameters:

Date$—Convert this string value to the time part of date it represents.

Example:

Sub Main
Debug.Print TimeValue("1/1/2000 12:00:01 AM") '12:00:01 AM
End Sub

TryCast

Syntax:

TryCast(expr, objtype)

Group:

Conversion

Description:

Return expr's type is related to objtype type. If it is not, nothing will be returned.

Parameters:

expr—Cast the value of this expression.

objtype—Cast to this type.

Example:

Sub Main
Dim V As Object

V = Err

Debug.Print TypeName(TryCast(V, ErrObject)) ' ErrObject
End Sub

Trim

Syntax:

Trim[$](S$)

Group:

String

Description:

Return the string with S$'s leading and trailing spaces removed.

Parameters:

S$—Copy this string without the leading or trailing spaces. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print ".";Trim$(" x ");"." '".x."
End Sub

TypeName

Syntax:

TypeName[$](var)

Group:

Variable Info

Description:

Return a string indicating the type of value stored in var.

Parameters:

var—Return a string indicating the type of value stored in this variable.

Result—Description

Empty—Variant variable is empty. It has never been assigned a value.

Null—Variant variable is null.

Boolean—Variable contains an integer value.

Byte—Variable contains a single value.

SByte—Variable contains a single value.

Short—Variable contains a byte value.

Integer—Variable contains an Integer value.

Long—Variable contains a long value.

Decimal—Variable contains a Decimal value.

Single—Variable contains a single value.

Double—Variable contains a double value.

Currency—Variable contains a currency value.

Date—Variable contains a date value.

String—Variable contains a string value.

Object—Variable contains an object reference that is not Nothing. (An object may return a type name specific to that type of object.)

Nothing—Variable contains an object reference that is Nothing.

Byte—Variable contains a byte value.

Error—Variable contains a error code value.

Variant—Variable contains a variant value. (Only used for arrays of variants.)

Unknown—Variable contains a non-ActiveX Automation object reference.

( )—Variable contains an array value. The TypeName of the element followed by ( ).

Example:

Sub Main
Dim X As Variant
Debug.Print TypeName(X) '"Empty"
X = 1
Debug.Print TypeName(X) '"Integer"
X = 100000
Debug.Print TypeName(X) '"Long"
X = 1.1
Debug.Print TypeName(X) '"Double"
X = "A"
Debug.Print TypeName(X) '"String"
Set X = CreateObject("Word.Basic")
Debug.Print TypeName(X) '"Object"
X = Array(0,1,2)
Debug.Print TypeName(X) '"Variant()"
End Sub

UBound

Syntax:

UBound(arrayvar[, dimension])

Group:

Variable Info

Description:

Return the highest index.

Parameters:

arrayvar—Return the highest index for this array variable.

dimension—Return the highest index for this dimension of arrayvar. If this is omitted then return the highest index for the first dimension.

Example:

Sub Main
Dim A(3,6)
Debug.Print UBound(A) ' 3
Debug.Print UBound(A,1) ' 3
Debug.Print UBound(A,2) ' 6
End Sub

UCase

Syntax:

UCase[$](S$)

Group:

String

Description:

Return a string from S$ where all the lowercase letters have been uppercased.

Parameters:

S$—Return the string value of this after all chars have been converted to lowercase. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print UCase$("Hello") '"HELLO"
End Sub

Val

Syntax:

Val(S$)

Group:

String

Description:

Return the value of the S$.

Parameters:

S$—Return the numeric value for this string value. A string value begins with &O is an octal number. A string value begins with &H is a hex number. Otherwise it is decimal number.

Example:

Sub Main
Debug.Print Val("-1000") '-1000
End Sub

VarType

Syntax:

VarType(var)

Group:

Variable Info

Description:

Return a number indicating the type of value stored in var.

Parameters:

var—Return a number indicating the type of value stored in this variable.

Result—Value—Description

vbEmpty—0—Variant variable is empty. It has never been assigned a value.

vbNull—1—Variant variable is null.

vbInteger—2—Variable contains an integer value.

vbLong—3—Variable contains a long value.

vbSingle—4—Variable contains a single value.

vbDouble—5—Variable contains a double value.

vbCurrency—6—Variable contains a currency value.

vbDate—7—Variable contains a date value.

vbString—8—Variable contains a string value.

vbObject—9—Variable contains an object reference.

vbError—10—Variable contains a error code value.

vbBoolean—11—Variable contains a boolean value.

vbVariant—12—Variable contains a variant value. (Only used for arrays of variants.)

vbDataObject—13—Variable contains a non-ActiveX Automation object reference.

vbDecimal—14—Variable contains a 96 bit scaled real.

vbByte—16—Variable contains a byte value.

vbUserDefinedType—36—Variable contains a User Defined Type value.

vbArray—8192—Variable contains an array value. Use VarType( ) And 255 to get the type of element stored in the array.

Example:

Sub Main
Dim X As Variant
Debug.Print VarType(X) ' 0
X = 1
Debug.Print VarType(X) ' 2
X = 100000
Debug.Print VarType(X) ' 3
X = 1.1
Debug.Print VarType(X) ' 5
X = "A"
Debug.Print VarType(X) ' 8
Set X = CreateObject("Word.Basic")
Debug.Print VarType(X) ' 9
X = Array(0,1,2)
Debug.Print VarType(X) ' 8204 (8192+12)
End Sub

VbTypeName

Syntax:

VbTypeName(Name)

Group:

Variable Info

Description:

Returns a string indicating VB type name corresponding to the fully qualified Common Language Runtime type name. Returns Nothing if the specified Name is not a valid VB type name.

Parameters:

Name—This is Common Language Runtime type name.

Example:

Sub Main
Dim X As Object

Debug.Print VbTypeName(X) '"Empty"

X = 1

Debug.Print VbTypeName(X) '"Integer"
End Sub

Weekday

Syntax:

Weekday(dateexpr)

Group:

Time/Date

Description:

Return the weekday.

Parameters:

dateexpr—Return the weekday for this date value. If this value is Null then Null is returned.

firstday—Value—Description (Return value)

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
Debug.Print Weekday(#1/1/1900#) ' 2
Debug.Print Weekday(#1/1/2000#) ' 7
End Sub

WeekdayName

Syntax:

WeekdayName(NumZ{day}[, CondZ{abbrev}])

Group:

Time/Date

Description:

Return the localized name of the weekday.

Parameters:

day—Return the localized name of this weekday. (1-7)

abbrev—If this conditional value is True then return the abbreviated form of the weekday name.

Example:

Sub Main
Debug.Print WeekdayName(1) 'Sunday
Debug.Print WeekdayName(Weekday(Now))
End Sub

Year

Syntax:

Year(dateexpr)

Group:

Time/Date

Description:

Return the year.

Parameters:

dateexpr—Return the year for this date value. If this value is Null then Null is returned.

Example:

Sub Main
Debug.Print Year(#1/1/1900#) ' 1900
Debug.Print Year(#1/1/2000#) ' 2000
End Sub

See Also:

Using Functions

Introduction to AWE Scripting

Introduction to Extended Functions

More on Operators

Order of Precedence