<< Click to Display Table of Contents >> Navigation: Reference (Scripting) > VBScript Basics > Miscellaneous |
Returns an expression formatted as a number.
Syntax
result = FormatNumber(expression [,numDigitsAfterDecimal [,includeLeadingDigit [,useParensForNegativeNumbers [,GroupDigits]]]])
Part |
Description |
expression |
Required. Expression to be formatted. |
numDigitsAfterDecimal |
Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default value is -1, which indicates that the computer's regional settings are used.
|
includeLeadingDigit |
Optional. Tristate constant that indicates whether or not a leading zero is displayed for fractional values: |
useParensForNegativeNumbers |
Optional. Tristate constant that indicates whether or not to place negative values within parentheses: |
GroupDigits |
Optional. Tristate constant that indicates whether or not numbers are grouped using the group delimiter specified in the control panel -1 = True, 0 = False, -2 = Use computer's regional settings |
' Example FormatNumber Function
MyAngle = 1.3 ' Define angle in radians.
MySecant = 1 / Cos(MyAngle) ' Calculate secant.
DL.AddComment "4 decimal places: FormatNumber(MySecant, 4) = " & FormatNumber(MySecant, 4)
DL.AddComment "leading zero, 1 decimal place: FormatNumber(0.123, 1, -1) = " & FormatNumber(0.123, 1, -1)
DL.AddComment "no zero, 3 decimal places: FormatNumber(0.123, 3, 0) = " & FormatNumber(0.123, 3, 0)
DL.AddComment "negative value in brackets: FormatNumber(-MySecant, 2, , -1) = " & FormatNumber(-MySecant, 2, , -1)
DL.AddComment "no brackets, no number groups, default decimals: FormatNumber(-1000000, , , 0, 0) = " & FormatNumber(-1000000, , , 0, 0)
DL.AddComment "use brackets and number groups, no decimals: FormatNumber(-1000000, 0, , -1, -1) = " & FormatNumber(-1000000, 0, , -1, -1)
Returns an expression formatted as a date or time.
Syntax
result = FormatDateTime(date[, namedFormat])
Part |
Description |
date |
Required. Date expression to be formatted. . |
namedFormat |
Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate (0) is used.
Constant Value Description vbGeneralDate Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed. vbLongDate 1 Display a date using the long date format specified in your computer's regional settings. vbShortDate 2 Display a date using the short date format specified in your computer's regional settings. vbLongTime 3 Display a time using the time format specified in your computer's regional settings. vbShortTime 4 Display a time using the 24-hour format (hh:mm). |
' Example FormatDateTime Function
DL.AddComment FormatDateTime(Now, vbGeneralDate) & vbCrLf
DL.AddComment FormatDateTime(Now, vbLongDate) & vbCrLf
DL.AddComment FormatDateTime(Now, vbShortDate) & vbCrLf
DL.AddComment FormatDateTime(Now, vbLongTime) & vbCrLf
DL.AddComment FormatDateTime(Now, vbShortTime) & vbCrLf
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
TIP: Use the Docklight-specific DL.InputBox2 method for a dialog box that always appears on the same screen as the Docklight Scripting main window. Or see the DL.GetKeyState function on how to wait and react to keyboard or mouse input.
Syntax
result = InputBox (prompt[, title][, default][, xpos][, ypos][, helpfile, context])
Part |
Description |
prompt |
Required. String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return plus linefeed character combination (Chr(13) & Chr(10)) between each line. |
title |
Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. |
default |
Optional. String expression displayed in the text box as the default response if no other input is provided. If you omit default, the text box is displayed empty. |
xpos |
Optional. Numeric expression that specifies, in twips, the horizontal distance of the left edge of the dialog box from the left edge of the screen. If xpos is omitted, the dialog box is horizontally centered. |
ypos |
Optional. Numeric expression that specifies, in twips, the vertical distance of the upper edge of the dialog box from the top of the screen. If ypos is omitted, the dialog box is vertically positioned approximately one-third of the way down the screen. |
helpfile |
Optional. String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If helpfile is provided, context must also be provided. |
context |
Optional. Numeric expression that identifies the Help context number assigned by the Help author to the appropriate Help topic. If context is provided, helpfile must also be provided. |
' Example InputBox Function
MyInput = InputBox("Please enter text", "My Title", "Example Text")
DL.AddComment MyInput ' Add the current input as comment
Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked.
TIP: Use the Docklight-specific DL.MsgBox2 method for a message box that always appears on the same screen as the Docklight Scripting main window. Or see the DL.SetUserOutput function on how to create an additional user output area and display extra user information.
Syntax
result = MsgBox (prompt[, buttons][, title][, xpos][, ypos][, helpfile, context])
Part |
Description |
prompt |
Required. Same as InputBox Function above. |
buttons |
Optional, common values are a combination (sum) of the below constants:
Constant Value Description vbOKOnly 0 OK button only (default) vbOKCancel 1 OK and Cancel buttons vbAbortRetryIgnore 2 Abort, Retry, and Ignore buttons vbYesNoCancel 3 Yes, No, and Cancel buttons vbYesNo 4 Yes and No buttons vbRetryCancel 5 Retry and Cancel buttons vbCritical 16 Critical message vbQuestion 32 Warning query vbExclamation 48 Warning message vbInformation 64 Information message vbDefaultButton1 0 First button is default (default) vbDefaultButton2 256 Second button is default vbDefaultButton3 512 Third button is default
TIP: For a full list of all constants available, see the Microsoft VBA documentation for MsgBox. |
title |
Optional. Same as InputBox Function above. |
xpos, ypos, helpfile, context |
Optional. Same as InputBox Function above. |
result |
Returns the user action:
Constant Value Description vbOK 1 OK button pressed vbCancel 2 Cancel button pressed vbAbort 3 Abort button pressed vbRetry 4 Retry button pressed vbIgnore 5 Ignore button pressed vbYes 6 Yes button pressed vbNo 7 No button pressed |
' Example MsgBox Function
result = MsgBox("Run this test?", 3, "My Title")
If result = 6 Then
DL.AddComment "Yes button pressed"
ElseIf result = 7 Then
DL.AddComment "No button pressed"
Else
DL.AddComment "Canceled"
End If
Returns a string representing the scripting language in use.
Use the following script example to get the complete description of script language and version number.
' Example ScriptEngine Function
DL.AddComment GetScriptEngineInfo
Function GetScriptEngineInfo
Dim s
s = "" ' Build string with necessary info.
s = ScriptEngine & " Version "
s = s & ScriptEngineMajorVersion & "."
s = s & ScriptEngineMinorVersion & "."
s = s & ScriptEngineBuildVersion
GetScriptEngineInfo = s ' Return the results.
End Function