Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
MESSAGEBOX()
, FoxTool’s MsgBox(), INPUTBOX()
Haven’t you wondered how all those cool Windows programs display the same type of dialogs—with the same icons, text faces, and screen positioning? Perhaps it’s a conspiracy. Nah. Maybe they all agreed on a convention and are actually sticking with it? Get real. The only reason those boxes all look the same is because they are all produced from the same function, and FoxPro programmers have access to that function as well.
MESSAGEBOX()
is a function introduced to the language in Visual FoxPro 3.0 that duplicates much of the functionality already available to FoxPro 2.x programmers in the FoxTools.FLL function MsgBox. (See FoxTools and SET LIBRARY
TO for more information on FoxTools and libraries in general.) The big difference between using the two is that MESSAGEBOX()
is built in and doesn’t require the use of any external libraries. The little difference is that the order of parameters differs between the two. Both functions return the same values to indicate the user’s choice.
INPUTBOX()
was introduced in VFP 7 to give developers access to the single input dialog used for collecting View Parameters.
nReturnValue = MESSAGEBOX( uMessage [, nIconButtons [, cTitle
[, nTimeOut ] ] ] )
nReturnValue = MSGBOX( cMessage, cTitle,
nIconButtons ) && FoxTools version
Parameter |
Value |
Meaning |
uMessage |
Any |
The message to display in the body of the dialog box. In VFP 6 and earlier, this parameter must be character. Beginning in VFP 7, any type may be used and it's converted to character. If uMessage is character, you can use CHR(13) to separate lines of text, and the text is automatically word-wrapped. VFP cuts off the message after 1024 characters. |
cMessage |
Character |
A character string or expression to display in the body of the dialog box. Use CHR(13) to separate lines of text. Automatically word-wrapped. |
nIconButtons: Choose one icon: |
0 |
No icon. |
16 (MB_ICONSTOP) |
Stop icon. |
|
32 (MB_ICONQUESTION) |
Question mark. |
|
48 (MB_ICONEXCLAMATION) |
Exclamation point. |
|
64 (MB_ICONINFORMATION) |
Information (i). |
|
Add to that value which button set to display: |
0 (MB_OK) |
OK. |
1 (MB_OKCANCEL) |
OK, Cancel. |
|
2 (MB_ABORTRETRYIGNORE) |
Abort, Retry, Ignore. |
|
3 (MB_YESNOCANCEL) |
Yes, No, Cancel. |
|
4 (MB_YESNO) |
Yes, No. |
|
5 (MB_RETRYCANCEL) |
Retry, Cancel. |
|
and add to </td> | 0 (MB_DEFBUTTON1) |
First button has the focus. |
</tr>
256 (MB_DEFBUTTON2) |
Second button has the focus. |
|
512 (MB_DEFBUTTON3) |
Third button has the focus. |
|
And if desperate: |
4096 (MB_SYSTEMMODAL) |
System modality: forces the message box to always be on top. |
cTitle |
Character |
A character string or expression to display in the title bar of the box. |
nTimeOut (added in VFP 7) |
Numeric |
The number of milliseconds after which the dialog should be closed, even if the user hasn't made a choice. |
Omitted |
The dialog stays open until the user makes a choice. |
|
nReturnValue |
1 (IDOK) |
OK |
2 (IDCANCEL) |
Cancel |
|
3 (IDABORT) |
Abort |
|
4 (IDRETRY) |
Retry |
|
5 (IDIGNORE) |
Ignore |
|
6 (IDYES) |
Yes |
|
7 (IDNO) |
No |
|
-1 |
The dialog timed out |
Parameter |
Value |
Meaning |
cMessage |
Character |
The prompt to appear in the dialog. Unlike MessageBox(), the prompt is limited to a single line. Any message too long for the dialog (94 characters with default settings) gets cut off. |
cCaption |
Character |
The caption to appear on the title bar of the dialog. Like the message, captions that are too long get cut off. |
Omitted or empty |
The dialog caption is the caption of the main Visual FoxPro window. |
|
cDefault |
Character |
An initial string to offer the user. The string appears, highlighted, in the text box portion of the dialog. |
Omitted |
Nothing appears initially in the text box portion of the dialog. |
|
nTimeOut |
Numeric |
The number of milliseconds after which the dialog closes, even if the user hasn't pressed a button. |
Omitted |
The dialog stays open until the user chooses either OK or Cancel, or uses the keyboard equivalents. |
|
cTimeoutValue |
Character |
The string to return if the dialog times out. |
Omitted |
The empty string is returned if the dialog times out. |
|
cResult |
Character |
The user's input (or cDefault if the user didn't change it) if he chooses OK; the empty string if the user chooses Cancel or presses ESC; cTimeoutValue if the dialog times out. |