Previous Topic: Sleep - Miscellaneous FunctionNext Topic: Network Functions


SortArray - Sort an Array

Valid on UNIX and Windows

The SortArray function sorts an array.

This miscellaneous function has the format:

SortArray(array as array) as Boolean
SortArray(array as array, start as integer) as Boolean
SortArray(array as array, start as integer, end as integer) as Boolean
Array

Identifies the name of the array to be sorted.

Start

Specifies the start index for the sort. The array is sorted from the start index to the end of array.

End

Specifies the last index for sort.

The function only handles basic types of arrays. Depending on the format chosen, (1) the whole array is sorted, (2) the array is sorted beginning with the start index, and (3) the array is sorted from the start index to the end index.

On successful completion, the function returns TRUE; otherwise, it returns FALSE.

Example: SortArray function

Dim a[10], b[10], i As Integer
Dim TAB As Char
TAB = chr(9)

For i=0 to 9
	a[i] = 10 - i
Next i

b = a
If SortArray(b) Then
	For i = 0 To 9
		Print("a("+Str(i)+")="+Str(a[i])+TAB+"b("+Str(i)+")="+Str(b[i]))
	Next i
Else
	Print("SortArray(b) failed!")
End If

Handling Backward Compatibility or Unknown Functions

DMScript provides functions that handle new functions on an old interpreter or unknown functions within a script. The following functions help ensure that the newer scripts run successfully on older DSM agents by ignoring the new or unknown functions:

ALLOW_UNRESOLVED_FUNCTIONS

The IsFunctionSupported function checks whether a particular given function is understood by the current version of dmscript. This directive has the following format:

#pragma ALLOW_UNRESOLVED_FUNCTIONS

When you add this directive to a DMScript, the compiler performs the following action when it finds an unknown function in the script:

IsFunctionSupported

The IsFunctionSupported function checks whether a function is supported. This function has the following format:

IsFunctionSupported (name as string) as Boolean

Example: IsFunctionSupported

#pragma ALLOW_UNRESOLVED_FUNCTIONS
If IsFunctionSupported ("OpenDetectedSoftwareOutputFiles") then
OpenDetectedSoftwareOutputFiles ("A7C1E14A-7C93-4E17-B4E5-45B796717F49", "V1", "OS Detection for Windows")
else
    dsmtrace(“error”,”This version of dmscript does not support Intellisigs.”)
    exit
end if

Input Parameters

This function has the following input parameter:

name

Specifies the name of the function.

Return Values

If the given function is either defined in the script or is a built-in function, the function returns true; else, returns false. This function is used in conjunction with the ALLOW_UNRESOLVED_FUNCTIONS pragma to allow scripts to handle backward compatibility. If a script uses a function that exists in the current release but not in previous releases, the script fails compilation and does not perform any action on computers running the old releases. IsFunctionSupported allows such a script to pass compilation on old releases and perform a special action at runtime to handle the missing feature. It is not possible to compensate for the missing function but an error message is output and collected to be read by the user.

Note: You can also use the GetFileInfo and CompareVersions functions to verify that the script is executing on a particular version of DMScript.