Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I add a TIMEOUT clause to MESSAGEBOX?

Tips -N- Tricks

How can I add a TIMEOUT clause to MESSAGEBOX?

by  ChrisRChamberlain  Posted    (Edited  )
How can I add a TIMEOUT clause to the MESSAGEBOX function?

If you want to use a TIMEOUT clause with the MESSAGEBOX function, try the following:-

Create a new class based on the timer class and call it [color blue]tmrMsgBox[color black]

Set [color blue].Enabled = .F.[color black] and [color blue].Interval = 2500[color black]

Add a new property called [color blue].Key[color black] and a new method called [color blue].KeyToPress()[color black].

In the [color blue].KeyToPress()[color black] event put:-
[color blue]
LPARAMETERS lcKey, lnInterval

WITH THIS
[tab]IF EMPTY(lcKey)
[tab][tab].Enabled = .F.
[tab]ELSE
[tab][tab].Key = lcKey
[tab][tab].Enabled = .T.
[tab]ENDIF
[tab]IF !EMPTY(lnInterval) AND VAL(lnInterval) # 0
[tab][tab].Interval = VAL(lnInterval) * 1000
[tab]ENDI
ENDW
[color black]

In the [color blue].Timer()[color black] event put:-
[color blue]
WITH THIS
[tab]DO CASE
[tab]CASE .Key = "O"
[tab][tab]KEYBOARD CHR(13)
[tab]CASE .Key = "C"
[tab][tab]KEYBOARD CHR(27)
[tab]CASE .Key = "A"
[tab][tab]KEYBOARD CHR(65)
[tab]CASE .Key = "R"
[tab][tab]KEYBOARD CHR(82)
[tab]CASE .Key = "I"
[tab][tab]KEYBOARD CHR(73)
[tab]CASE .Key = "Y"
[tab][tab]KEYBOARD CHR(89)
[tab]CASE .Key = "N"
[tab][tab]KEYBOARD CHR(78)
[tab]ENDC
[tab].Key = .F.
[tab].Interval = 2500
[tab].Enabled = .F.
ENDW
[color black]

Save the class and drop it on a form.

Add the following code immediately before and after MESSAGEBOX...
[color blue]
THISFORM.tmrMsgBox.KeyToPress("O")
MESSAGEBOX("This is to test if this thing works!",;
[tab]0 + 64 + 0 ,;
[tab]"Keypress test")
THISFORM.tmrMsgBox.KeyToPress()
[color black]


The following character in () represents the choice of first parameter to pass to tmrMsgBox, and should correspond to the first value in the second parameter passed to MESSAGEBOX().

0 + 64 + 0 -> (O)K button only
1 + 64 + 0 -> (O)K and (C)ancel buttons
2 + 64 + 0 -> (A)bort, (R)etry, and (I)gnore buttons
3 + 64 + 0 -> (Y)es, (N)o, and (C)ancel buttons
4 + 64 + 0 -> (Y)es and (N)o buttons
5 + 64 + 0 -> (R)etry and (C)ancel buttons

The second optional parameter is "n", (seconds interval, default = 2.5 seconds),
eg [color blue]THISFORM.tmrMsgBox.KeyToPress("Y","4")[color black]

IF the user does not keypress/click within the default/developer designated time,
[color blue]tmrMsgBox.Timer()[color black] will [color blue]KEYBOARD CHR(n)[color black] and close the messagebox with normal return values.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top