Extended Functions

AWE provides a library of additional functions that extend the functionality of the AWE Scripting Engine beyond the capabilities that the basic VBA-compatible engine provides. These functions, collectively referred to as Extended Functions, provide operations in several areas to provide more functionality and make formulating AWE scripts even easier. These functions provide a more straightforward approach to file-related operations, date/time manipulation, and viewing or modifying attributes of a running task. The extended functions can be used from within any AWE Action just like the normal VBA-compatible functions.

AWE extended functions can be extremely useful because they provide added functionality to a given task. The extended functions are capable of returning multiple attributes regarding the task currently being executed, such as returning the path and filename of the presently running task, returning the amount of time the task or particular step within the task took to execute in minutes, seconds or milliseconds or returning the last error generated by a task step. They can supply system information, such as returning the computer name that AWE is running on, returning the IP address of the specified host name or local machine or returning the amount of space remaining on a specific drive. The extended functions can perform extensive date/time and file related procedures as well, such as returning the first or last day of the specified month, quarter or year, returning the number of files found in the specified folder or extracting the file name or the path within a particular string.

The general format of a function is its name followed by any arguments contained between parenthesis. For example:

FunctionName (arguments)

Similar to the regular VBA-compatible functions, some extended functions may or may not require other parameters to properly complete a procedure or routine. A function without arguments must include an empty set of parentheses ().

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

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

Extended Function Name

Description

ArrayAvg

Syntax:

ArrayAvg(array)

Description:

Calculates the average of the values in an array.

Return Value:

Number. If the array parameter value is an empty array, returns zero.

ArrayMax

 

Syntax:

ArrayMax(array)

Description:

Array maximum function. Returns the largest numeric value in an array. If the array parameter value is an empty array, returns zero.

Parameters:

Array—Name of an array

ArrayMin

 

Syntax:

ArrayMin(array)

Description:

Array minimum function. The smallest numeric value in an array. If the array parameter value is an empty array, returns zero.

Parameters:

 Array—Name of an array

ArraySum

 

Syntax:

ArraySum(array)

Description:

Array sum function. Returns the sum of values in an array. If the array parameter value is an empty array, returns zero.

Parameters:

Array—Name of an array

Example:

Dim arr As Integer() = {3, 7, 8, 2, 0, 9}

MessageBox.Show(ArraySum(arr))

ArrayToList

Syntax:

ArrayToList(array [, delimiter ])

Description:

Converts a one-dimensional array to a list. Returns delimited list, as a string.

Parameters:

 Array—Name of an array

Delimiter—Character or multicharacter string to separate list elements. The default value is comma.

CreateGUID

 

Syntax:

ArraySum(array)

Description:

Array sum function. Returns the sum of values in an array. If the array parameter value is an empty array, returns zero.

Parameters:

array—Name of an array

Example:

Dim arr As Integer() = {3, 7, 8, 2, 0, 9}

MessageBox.Show(ArraySum(arr))

CreateODBCDate

 

Syntax:

CreateODBCDate(dateexpr)

Description:

In order to use dates in a SQL language query, the date must be formatted properly. CreateODBCDate converts a BASIC date type to a string of text that is valid for use in a SQL Query through ODBC or OLEDB.

Parameters:

dateexpr—A valid data type or variant that can be converted to a date.

Example:

Sub Main
CreateOdbcDate(date())End Sub

CreateODBCDateTime

 

Syntax:

CreateODBCDateTime(dateexpr)

Description:

In order to use dates in a SQL language query, the date must be formatted properly. CreateODBCDateTime converts a BASIC datetime type to a string of text that is valid for use in a SQL Query through ODBC or OLEDB.

Parameters:

dateexpr—A valid data + time type or variant that can be converted to a date + time value

Example:

Sub Main
myodbcdatetime = CreateOdbcDateTime(Now())
'is the same as
myodbcdatetime = CreateOdbcDateTime(Date() + Time())End Sub

CreateODBCTime

 

Syntax:

CreateODBCTime(dateexpr)

Description:

In order to use dates in a SQL language query, the date must be formatted properly. CreateODBCTime converts a BASIC time type to a string of text that is valid for use in a SQL Query through ODBC or OLEDB.

Parameters:

dateexpr—A valid time type or variant that can be converted to a time value.

Example:

Sub Main
myodbcdatetime = CreateOdbcTime(Time())End Sub

DaysInMonth

 

Syntax:

DaysInMonth(dateexpr)

Description:

Returns the number of days in the month of the date specified.

Parameters:

dateexpr—A valid time type or variant that can be converted to a date value.

Example:

Sub Main
'display the number of days in the current month
numberofdaysthismonth = DaysInMonth(Now())

'display the number of days in next month
numberofdaysnextmonth = DaysInMonth(DateAdd("m",1, Now()))

'display the number of days in month of a custom date
numberofdayscustommonth = DaysInMonth(DateSerial(2004,02,34))
End Sub

DaysInYear

Syntax:

DaysInYear(dateexpr)

Description:

Returns the number of days in the year of the date specified.

Parameters:

dateexpr—A valid time type or variant that can be converted to a date value.

Example:

Sub Main
'display the number of days in the current year
numberofdaysthisyear = DaysInYear(Now())

'display the number of days in next year
numberofdaysnextyear = DaysInYear(DateAdd("y",1, Now()))

'display the number of days in a year of a custom date
numberofdayscustomyear = DaysInYear(DateSerial(2004,02,34))

End
Sub

DriveAvailableSpace

Syntax:

DriveAvailableSpace(Str)

Description:

Returns, in megabytes (MB), the amount of space remaining on the specified drive letter.

Parameters:

Str—A text string containing the drive letter to be checked for available space.

Example:

Sub Main

MsgBox DriveAvailableSpace("c:")

End Sub

DriveExists

Syntax:

DriveExists(Str)

Description:

Returns true if the specified drive letter exists and false if it does not.

Parameters:

Str—A text string containing the drive letter to check for existence.

Example:

Sub Main
MsgBox DriveExists("c:")

End Sub

ExtractFileName

Syntax:

ExtractFileName(Str)

Description:

Extracts the name and extension parts of a file name. The resulting string is the rightmost characters of FileName, starting with the first character after the colon or backslash that separates the path information from the name and extension. The resulting string is equal to FileName if FileName contains no drive and folder parts.

Parameters:

Str—A text string containing the full path from which the filename should be extracted.

Example:

Sub Main
'will return filename.txt
MsgBox ExtractFileName("c:\foldername\filename.txt")

End Sub

ExtractFilePath

Syntax:

ExtractFilePath(Str)

Description:

Returns the drive and folder portions of a file name. The resulting string is the leftmost characters of FileName, up to and including the colon or backslash that separates the path information from the name and extension. The resulting string is empty if FileName contains no drive and folder parts.

Parameters:

Str—A text string containing the full path from which the path should be extracted.

Example:

Sub Main
'will return c:\foldername

MsgBox ExtractFilePath("c:\foldername\filename.txt")

End Sub

FileCount

Syntax:

FileCount(Str)

Description:

Returns the number of files found in the specified folder.

Parameters:

Str—A text string containing the folder that should be scanned for number of files.

Example:

Sub Main
MsgBox FileCount("c:\foldername")

End Sub

FileExists

Syntax:

FileExists(Str)

Description:

Returns true if the specified file exists and false if it does not.

Parameters:

Str—A text string containing the path and filename of the file to check for existence.

Example:

Sub Main
MsgBox FileExists("c:\foldername\filename.txt")

End Sub

FirstDateOfDayInMonth

Syntax:

FirstDateOfDayInMonth(dateexpr, NumZ{day})

Description:

Returns the date of the first instance of the specified day in the month of the date specified. For example, this function could return the date of the first Monday of next month.

Parameters:

dateexpr—The date to be used when determining the first instance of the day.

NumZ{day}—Value—Description

  • vbSunday—1—Sunday

  • vbMonday—2—Monday

  • vbTuesday—3—Tuesday

  • vbWednesday—4—Wednesday

  • vbThursday—5—Thursday

  • vbFriday—6—Friday

  • vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the first Sunday of this month.
firstSundayofthismonth= FirstDateOfDayInMonth(Now(),1)

'return the date of the first Monday of next month.
firstMondayofnextmonth = FirstDateOfDayInMonth(DateAdd(1,"m",Now()),2)

End Sub

FirstDateOfDayInQuarter

Syntax:

FirstDateOfDayInQuarter(dateexpr, NumZ{day})

Description:

Returns the date of the first instance of the specified day in the quarter of the date specified. For example, this function could return the date of the first Monday of the next quarter.

Parameters:

dateexpr—The date to be used when determining the first instance of the day.

NumZ{day}—Value—Description

  • vbSunday—1—Sunday

  • vbMonday—2—Monday

  • vbTuesday—3—Tuesday

  • vbWednesday—4—Wednesday

  • vbThursday—5—Thursday

  • vbFriday—6—Friday

  • vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the first Sunday of this quarter.
firstSundayofthisquarter = FirstDateOfDayInQuarter(Now(),1)

'return the date of the first Monday of next quarter.
firstMondayofnextquarter = FirstDateOfDayInQuarter(DateAdd(1,"q",Now()),2)

End Sub

FirstDateOfDayInYear

Syntax:

FirstDateOfDayInYear(dateexpr, NumZ{day})

Description:

Returns the date of the first instance of the specified day in the year of the date specified. For example, this function could return the date of the first Monday of next year.

Parameters:

dateexpr—The date to be used when determining the first instance of the day.

NumZ{day}—Value—Description

  • vbSunday—1—Sunday

  • vbMonday—2—Monday

  • vbTuesday—3—Tuesday

  • vbWednesday—4—Wednesday

  • vbThursday—5—Thursday

  • vbFriday—6—Friday

  • vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the first Sunday of this year.
firstSundayofthisyear = FirstDateOfDayInYear(Now(),1)

'return the date of the first Monday of next year.
firstMondayofnextyear = FirstDateOfDayInQuarter(DateAdd(1, "yyyy",Now()),2)

End Sub

FolderCount

Syntax:

FolderCount(Str)

Description:

Returns the number of subfolders found in the specified folder.

Parameters:

Str—A text string containing the folder that should be scanned for number of sub-folders.

Example:

Sub Main
MsgBox FolderCount("c:\foldername")

End Sub

FolderExists

Syntax:

FolderExists(Str)

Description:

Returns true if the specified folder exists and false if it does not.

Parameters:

Str—A text string containing the path of the folder to check for existence.

Example:

Sub Main
MsgBox FolderExists("c:\foldername\")

End Sub

GetAutoMateDirectory

Syntax:

GetAutoMateDirectory()

Description:

Returns folder of the current installation.

Parameters:

(No parameters needed)

Example:

Sub Main
'usually c:\program files\AutoMate 7\
MsgBox GetAutoMateDirectory()

End Sub

GetAutoMateLogfile

Syntax:

GetAutoMateLogfile()

Description:

Returns the path and name of the AWE text log file. Events are logged to this text file when the logging preferences are set to "Text file" or "Both" in the AWE Configuration Manager logging options.

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetAutoMateLogfile()

End Sub

GetAutoMateVersion

 

Syntax:

GetAutoMateVersion()

Description:

Returns the version of the current installation.

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetAutoMateVersion()
End Sub

GetComputerName

 

Syntax:

GetComputerName()

Description:

Returns the name of the computer that AWE is running on.

Example:

Sub Main
MsgBox GetComputerName()

End Sub

GetCurrentLineNumber

 

Syntax:

GetCurrentLineNumber()

Description:

Returns the step number of the currently running task. The step number returned is in the context of the Task not the BASIC script (if any).

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetCurrentLineNumber()
End Sub

GetCurrentTagText

Syntax:

GetCurrentTagText()

Description:

Returns the AML tag currently being executed.

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetCurrentTagText()

End Sub

GetDesktopDirectory

Syntax:

GetDesktopDirectory()

Description:

Returns folder of the Windows Desktop.

Parameter:

(No parameters needed)

Example:

Sub Main
MsgBox GetDesktopDirectory()

End Sub

GetEnvironmentVariable

 

Syntax:

GetEnvironmentVariable(Str)

Description:

GetEnvironmentVariable returns the value of the EnvVar environment variable. If the specified variable does not exist or EnvVar is empty, an empty string is returned. This function can retrieve either a system environment variable or a user environment variable.

Example:

Dim variable As String

Dim returnValue As String

returnValue = Environment.GetEnvironmentVariable(variablename)

GetErrorText

 

Syntax:

GetErrorText(ErrorNumber)

Description:

Returns the error message corresponding to the specified error ID or number.

GetFileAttr

 

Syntax:

GetFileAttr(Str)

Description:

Returns a string representing the attributes of the specified file. Although the standard BASIC language contains the GetAttr function to retreive file attributes, this function is superior because the attributes are returned in a format that is human readable and may be used directly in any AML action parameter that supports attribute filters. Examples of such actions include Copy File and Delete File.

Parameters:

Str—A text string containing the full path and filename from which the attributes should be extracted.

The return value string is comprised of any combination of the following attribute indicators:

Attribute—Indicators

  • R - Read only—Specifying "+R" causes files with this attribute turned on to be included, "-R" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • A - Archive—Specifying "+A" causes files with this attribute turned on to be included, "-A" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • S - System—Specifying "+S" causes files with this attribute turned on to be included, "-S" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • H - Hidden—Specifying "+R" causes files with this attribute turned on to be included, "-H" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • C - Compression—Specifying "+C" causes files with this attribute turned on to be included, "-C" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

Example:

Sub Main
MsgBox GetFileAttr("c:\foldername\filename.txt")

End Sub

GetFocusedWindowHandle

 

Syntax:

GetFocusedWindowHandle()

Description:

Returns the "handle" of the currently focused Window.

A "handle" is a unique number assigned by the operating system to every window on the system. The return value may be used in either the GetWindowCaption extEnded function or in any of the actions that have a" handle" parameter to identify a window.

Parameter:

(No parameters needed)

Example:

Sub Main
MsgBox GetDesktopFolder()

End Sub

GetFontDirectory

 

Syntax:

GetFontDirectory()

Description:

Returns the folder path of the Windows "fonts" folder.

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetFontDirectory()

End Sub

GetIPAddress

 

Syntax:

GetIPAddress (hostname)

Description:

Returns the IP address of the machine specified by hostname. Use an empty string to return the IP address of the local machine.

Parameters:

Hostname (optional)—The hostname of the machine for which to return the IP address. If this parameter is an empty string, the IP address of the current machine is returned.

Example:

Sub Main
' Display the IP address of the current machine
MsgBox GetIPAddress ()

' Display the IP address of Yahoo!
MsgBox GetIPAddress ("www.yahoo.com")

End Sub

GetLastError

Syntax:

GetLastError()

Description:

Returns the last error generated by a task step in the AML language. The error is returned as a number that uniquely identifies the error. This is very important function as it allows conditional execution based on the error generated by a step. If the last step did not generate an error GetLastError returns 0.

NOTE: This function returns errors for AML only - it does not work with BASIC functions or methods.

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetLastError()

End Sub

GetLastErrorText

Syntax:

GetLastErrorText()

Description:

Returns a text string describing the last error encountered by the task (the error string corresponds to the error code returned by GetLastError)

Parameter:

(No parameters)

Example:

Sub Main
' Display the last error code and text
strError = "Error Code: " & GetLastError() & " Error: " & GetLastErrorText()
MsgBox strError

End Sub

GetLastStepExecutionTimeMin

 

Syntax:

GetLastStepExecutionTimeMin()

Description:

Returns the amount of time the last step took to execute in minutes. If the step took less than one minute the function returns 0

Parameters:

(no parameters needed)

Example:

Sub Main
MsgBox GetLastStepExecutionTimeMin()

End Sub

GetLastStepExecutionTimeMS

 

Syntax:

GetLastStepExecutionTimeMS()

Description:

Returns the amount of time the last step took to execute in milliseconds.

Parameters:

(no parameters)

Example:

Sub Main
MsgBox GetLastStepExecutionTimeMS()

End Sub

GetLastStepExecutionTimeSec

Syntax:

GetLastStepExecutionTimeSec()

Description:

Returns the amount of time the last step took to execute in seconds. If the step took less than one second the function returns 0

Parameters:

(no parameters)

Example:

Sub Main
MsgBox GetLastStepExecutionTimeSec()

End Sub

GetMousePosX

Syntax:

GetMousePosX()

Description:

Returns the x coordinate of the current mouse position. The very left of the screen is 0.

Parameters:

(No parameters needed)

Example:

Sub Main
' Display the position of the mouse
strMousePos = GetMousePosX() & "," & GetMousePosY()
MsgBox strMousePos

End Sub

GetMousePosY

Syntax:

GetMousePosY()

Description:

Returns the y coordinate of the current mouse position. The very top of the screen is 0.

Parameters:

(No parameters needed)

Example:

Sub Main
' Display the position of the mouse
strMousePos = GetMousePosX() & "," & GetMousePosY()
MsgBox strMousePos

End Sub

GetParentTaskName

Syntax:

GetParentTaskName()

Description:

Returns the name of the task that launched the current task. The function returns a blank string if the task was not started by another task.

Parameters:

(no parameters)

Example:

Sub Main
' Display the name of the parent task
strParentTask = GetParentTaskName()
if (strParentTask == "")
MsgBox "Not started by another task"
else
MshBox "Task was started by " & strParentTask

End Sub

GetProgramsDirectory

Syntax:

GetProgramsDirectory()

Description:

Returns the folder path of the Windows "Program Files" folder.

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetProgramsDirectory()

End Sub

GetStartupDirectory

Syntax:

GetStartupDirectory()

Description:

Returns the folder path of the Windows "Startup" folder. The startup folder is a special folder in Windows. Any program files located in this folder are automatically started when the user logs on.

Parameters:

(No parameters needed)

Example:

Sub Main
MsgBox GetStartupDirectory()

End Sub

GetSystemDirectory

Syntax:

GetSystemDirectory()

Description:

Returns the folder path of the Windows "System" folder.

Parameters:

(No parameters)

Example:

Sub Main
MsgBox GetSystemDirectory()
End Sub

GetTaskExecutionTimeMin

Syntax:

GetTaskExecutionTimeMin()

Description:

Returns the amount of time the task took to execute in minutes. If the task took less than one minute the function returns 0

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetTaskExecutionTimeMin()

End Sub

GetTaskExecutionTimeMS

Syntax:

GetTaskExecutionTimeMS()

Description:

Returns the amount of time the task took to execute in milliseconds.

Parameter:

(No parameters)

Example:

Sub Main
MsgBox GetTaskExecutionTimeMS()

End Sub

GetTaskExecutionTimeSec

Syntax:

GetTaskExecutionTimeSec()

Description:

Returns the amount of time the task took to execute in seconds. If the task took less than one second the function returns 0

Parameter:

(No parameters)

Example:

Sub Main
MsgBox GetTaskExecutionTimeSec()

End Sub

GetTaskName

Syntax:

GetTaskName()

Description:

Returns the path and filename of the currently running task.

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetTaskName()
End Sub

GetTasksDirectory

Syntax:

GetTasksDirectory()

Description:

Returns the folder path of the default location for new AWE task files.

Parameters:

(No parameters)

Example:

Sub Main
MsgBox GetTasksDirectory()

End Sub

GetUsername

Syntax:

GetUsername()

Description:

Returns the user name of the currently logged on Windows user.

Parameter:

(No parameters)

Example:

Sub Main
MsgBox GetUsername()
End Sub

GetVar

Syntax:

GetVar (iIndex)

Description:

Returns the name of the variable at enumerated variable list index iIndex. (Note: this function returns valid results only from within a running task).

Parameters:

index—The index number of the variable name to return from the list of enumerated variable names.

Example:

Sub Main
' Display the names of all the variables and their
' contents

Dim iTotalVariables As Integer

iTotalVariables = GetVarCount()

For iIndex=0 to iTotalVariables
MsgBox GetVar(iIndex)
MsgBox GetVarValueByVarName(GetVar(iIndex))
Next iIndex

End
Sub

GetVarCount

Syntax:

GetVarCount()

Description:

Returns the total number of variables created by the current task. (Note: this function returns valid results only from within a running task).

Parameters:

(No parameters needed)

Example:

Sub Main
' Display the names of all the AWE variables and their
' contents

Dim iTotalVariables As Integer

iTotalVariables = GetVarCount()

For iIndex=0 to iTotalVariables
MsgBox GetVar(iIndex)
MsgBox GetVarValueByVarName(GetVar(iIndex))
Next iIndex

End Sub

GetVarValueByVarName

Syntax:

GetVarValueByVarName (strVarName)

Description:

Returns the contents of the variable whose name is strVarName. strVarName is a string of the Autoate variable name, and not the variable name itself. (Note: this function returns valid results only from within a running task)

Parameters:

strVarName—String of the name of the variable whose contents are to be returned.

Example:

Sub Main
' Display the contents of an variable named "test"
MsgBox GetVarValueByVarName("test")End Sub

Sub Main
' Display the names of all the variables and their
' contents

Dim iTotalVariables As Integer

iTotalVariables = GetVarCount()

For iIndex=0 to iTotalVariables
MsgBox GetVar(iIndex)
MsgBox GetVarValueByVarName(GetVar(iIndex))
Next iIndex

End
Sub

GetWindowCaption

Syntax:

GetWindowCaption(Num)

Description:

Returns the caption from the Window title bar) of the Window with the handle specified.

To obtain the handle of the current top level window use the GetFocusedWindowHandle function.

The Run action can also return a Window handle.

Parameters:

(No parameters)

Example:

Sub Main
MsgBox GetDesktopFolder()

End Sub

GetWindowsDirectory

Syntax:

GetWindowsDirectory()

Description:

Returns the folder path of the Windows folder.

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetWindowsDirectory()
End Sub

GetWindowsVersion

Syntax:

GetWindowsVersion()

Description:

Returns a string with the version number of Windows.

Parameter:

(no parameters)

Example:

Sub Main
MsgBox GetWindowsVersion()End Sub

IsDefined

IsDefined

Syntax:

IsDefined (Str)

Description:

Tests a Str expression to determine whether it is the name of a product or platform constant at run time. IsDefined returns TRUE (-1) if Str is the name of a product or platform constant at run time. Otherwise IsDefined returns FALSE (0).

Parameters:

Str—Name of variable to test for.

Notes:

The constants can define platforms at different levels and are not mutually exclusive. For example, on WinNT, the platform returned can be WIN32_X86, WINNT, WIN32, or WINDOWS.

Product constants are defined by, and are specific to, the host product, for example Notes, 1-2-3, ESB, and so on. Refer to the product's documentation for a list of product-defined constants.

IsLeapYear

 

Syntax:

IsLeapYear(date)

Description:

Returns true if date is in a leap year, and false otherwise.

Parameters:

date—A valid date string or date variable.

Example:

Sub Main
If IsLeapYear (Now()) Then
MsgBox "This is a leap year"
Else
MsgBox "This is not a leap year"
End Sub

IsLocked

 

Syntax:

IsLocked(Str)

Description:

Returns a true if the file is locked and/or currently in use by another application, and false otherwise.

Parameters:

Str—A text string containing the full path and filename to be checked.

Example:

Sub Main
MsgBox GetFileAttr("c:\foldername\filename.txt")

End Sub

LastDateOfDayInMonth

 

Syntax:

LastDateOfDayInMonth(dateexpr, NumZ{day})

Description:

Returns the date of the last instance of the specified day in the month of the date specified. For example, this function could return the date of the last Monday of next month.

Parameters:

dateexpr—The date to be used when determining the last instance of the day in the month.

NumZ{day}—The day to check for.

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the last Sunday of this month.
lastSundayofthismonth= LastDateOfDayInMonth(Now(),1)

'return the date of the last Friday of next month.
lastMondayofnextmonth = LastDateOfDayInMonth(DateAdd(1,"m",Now()),6)

End Sub

LastDateOfDayInQuarter

 

Syntax:

LastDateOfDayInQuarter(dateexpr, NumZ{day})

Description:

Returns the date of the last instance of the specified day in the quarter of the date specified. For example, this function could return the date of the last Monday of the next quarter.

Parameters:

dateexpr—The date to be used when determining the last instance of the quarter.

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the last Sunday of this quarter.
lastSundayofthisquarter= LastDateOfDayInQuarter(Now(),1)

'return the date of the last Friday of next quarter.
lastMondayofnextquarter = LastDateOfDayInQuarter(DateAdd(1,"q",Now()),6)

End Sub

LastDateOfDayInYear

 

Syntax:

LastDateOfDayInYear(dateexpr NumZ{day})

Description:

Returns the date of the last instance of the specified day in the year of the date specified. For example, this function could return the date of the last Monday of next year.

Parameters:

dateexpr—The date to be used when determining the last instance of the day in the year.

NumZ{day}—The day to check for.

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the last Sunday of this year.
lastSundayofthisyear= LastDateOfDayInYear(Now(),1)

'return the date of the last Friday of next year.
lastMondayofnextyear = LastDateOfDayInYear(DateAdd(1,"yyyy",Now()),6)

End Sub

LastDateOfWeek

 

Syntax:

LastDateOfWeek(dateexpr, NumZ{day})

Description:

Returns the date of the last instance of the specified day in the week of the date specified.

Parameters:

dateexpr—The date to be used when determining the last instance of the day in the week.

NumZ{day}—The day to check for.

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the date of the last Sunday of this week.
lastSundayofthisweek = LastDateOfWeek(Now(),1)

'return the date of the last Friday of this week.
lastMondayofthisweek = LastDateOfWeek(Now(),6)

End Sub

LastDayOfMonth

 

Syntax:

LastDayOfMonth(dateexpr)

Description:

Returns the last day (i.e. Sunday, Monday, etc.) of the month specified by dateexpr. For example, this function could return the name of last day of the current month.

Parameters:

dateexpr—The date to be used when determining the last day of the current month.

The return integer is one of the following:

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the name of the last day of this month
lastDayOfTheMonth = LastDayOfTheMonth (Now())

End Sub

LastDayOfQuarter

 

Syntax:

LastDayOfQuarter(dateexpr)

Description:

Returns the last day (i.e. Sunday, Monday, etc.) of the quarter specified by dateexpr. For example, this function could return the name of last day of the second quarter of the current year. A quarter occurs every three months starting in January.

Parameters:

dateexpr—The date to be used when determining the last day of the quarter.

The return integer can be one of the following:

NumZ{day}—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the name of the last day of this quarter
lastDayOfThisQuarter = LastDayOfQuarter (Now())

End Sub

LastDayOfYear

Syntax:

LastDayOfYear(dateexpr)

Description:

Returns the last day (i.e. Sunday, Monday, etc.) of the year specified by dateexpr. For instance, this function could return the name of last day of the current year.

Parameters:

dateexpr—A date which contains the year to be examined.

The return integer can be one of the following:

Firstday—Value—Description

vbSunday—1—Sunday

vbMonday—2—Monday

vbTuesday—3—Tuesday

vbWednesday—4—Wednesday

vbThursday—5—Thursday

vbFriday—6—Friday

vbSaturday—7—Saturday

Example:

Sub Main
'return the name of the last day of this year
lastDayOfYear = LastDayOfYear (Now())

End Sub

RndEx

Syntax:

RndEx()

Description:

Returns a random number between 0 and 1. This function should be used in place of Rnd() as its results are more widely distributed in repeated calls than Rnd().

Parameter:

(No parameters)

Example:

Sub Main
MsgBox Rnd()

End Sub

RndFloat

Syntax:

RndFloat (Floor as Double, Ceiling As Double)

Description:

Returns a random floating point number between Floor and Ceiling.

Parameters:

Floor—The lowest random number possible. This cannot be a negative value.

Ceiling—The highest random number possible. This cannot be a negative value and must be greater than Floor.

Example:

Sub Main
Dim MyRandomNumber As Double
MyRandomNumber = RndFloat (1, 100) 'Random number between 1 and 100
MsgBox Str(MyRandomNumber)

End Sub

RndInt

Syntax:

RndInt (Floor as Integer, Ceiling As Integer)

Description:

Returns a random number between Floor and Ceiling.

Parameters:

Floor—The lowest random number possible. This cannot be a negative value.

Ceiling—The highest random number possible. This cannot be a negative value and must be greater than Floor.

Example:

Sub Main
Dim MyRandomNumber As Integer
MyRandomNumber = RndInt (1, 100) 'Random number between 1 and 100
MsgBox Str(MyRandomNumber)

End Sub

TaskId

Syntax:

TaskId()

Description:

Returns the ID number of the currently running task. Each running AWE task has a unique number assigned to it at runtime to differentiate it from other tasks running with the same name. The TaskID is a read-only property of the running task.

Parameters:

(no parameters)

Example:

Sub Main
' Display the task ID of the currently running task
MsgBox TaskId()

End Sub

See Also:

Introduction to AWE Scripting

Introduction to Functions

More on Operators

Order of Precedence