![]() |
|
Published 1998-01-01 Printer-friendly version
Occasionally during the execution of a program, I need to get a yes or no response from the end user. This may occur for a number of reasons, such as:
Well, OK, the last one I dont really use, but you get the idea. These questions can appear throughout the system.
Any of the above questions can be coded similar to the following code:
CASE MESSAGE('Do you really want to delete all these files?'|
,'Question' |
,ICON:Question |
,BUTTON:Yes + BUTTON:No |
,BUTTON:Yes |
,0)
OF BUTTON:No
! Some terrific code goes here
OF BUTTON:Yes
! More terrific code goes here
END
This would look like the following in a program.

The parts of this message are as follows:
Since this was handcoded each time, I desired a faster way to get the same results. I also wanted to establish a standardized solution based upon the application needs plus hide the message details so I could concentrate on the logic flow of the program.
#TEMPLATE(SMPL0006,'Simple Yes/No Procedure')
#!-----------------------------------------------------!
#! O_YNReply Procedure !
#!-----------------------------------------------------!
#PROCEDURE(O_YNReply,'Generic Yes/No Reply')
#PROTOTYPE('(STRING,<<STRING>,<<STRING>),BYTE')
#DISPLAY('')
#DISPLAY('This is a generic Yes/No message')
#DISPLAY('')
#DISPLAY(' Default icon is Question')
#DISPLAY(' Default title is Question')
#DISPLAY('')
#DISPLAY('Possible Calling Conventions:')
#DISPLAY(' If O_YNReply(''Message Text'')')
#DISPLAY(' If O_YNReply(''Message Text'',''Title'')')
#DISPLAY(' If O_YNReply(''Message Text'',''Title'',ICON)')
#DISPLAY('')
#LOCALDATA
Loc_Title STRING(30)
#ENDLOCALDATA
%Procedure %ProcedureType(YNTxt,YNTitle,YNIcon)
#FOR(%LocalData)
%[20]LocalData %LocalDataStatement
#ENDFOR
CODE
Loc_Title = YNTitle
IF Loc_Title = '' THEN Loc_Title = 'Question'.
IF OMITTED(3)
CASE MESSAGE(YNTxt|
,Loc_Title|
,ICON:Question|
,BUTTON:Yes+BUTTON:No|
,BUTTON:Yes|
,0)
OF BUTTON:No
RETURN(FALSE)
OF BUTTON:Yes
RETURN(TRUE)
END !CASE
ELSE
CASE MESSAGE(YNTxt|
,Loc_Title|
,YNIcon|
,BUTTON:Yes+BUTTON:No|
,BUTTON:Yes|
,0)
OF BUTTON:No
RETURN(FALSE)
OF BUTTON:Yes
RETURN(TRUE)
END !CASE
END !IF
#!-------------------------------------------------------
First we register the template as we would any template.
We then open an application where we want to use this template. In the application tree, press INSERT. A window comes up where you can enter the name of the new procedure. I choose O_YNReply. Press OK.

The standard Select Procedure Type window displays. Find ClassSMPL0006 Simple Yes/No Procedure, highlight O_YNReply Generic Yes/No Reply, and press Select.

Press OK. Your application tree should now have the procedure O_YNReply.

For purpose of showing which leg of the IFTHENELSE is being executed, Ive also included in this sample application the procedure O_Message that displays a generic message.

Most of the time I use the defaults in the procedure template. In the appropriate embed point I insert something like the following code:
IF O_YNReply('Do you really want to delete all these files?')
O_Message('Files will be deleted')
!
! wonderful code to delete these files
!
ELSE
O_Message('Files will not be deleted')
END !IF
Note: for use of these examples, Im displaying the results of pressing either yes or no (Using O_Message). In production, I would probably not include the code to display what was chosen.
The default question appears as follows:

If the YES button is pressed, the following message appears:

If the NO button is pressed, we get a different response:

Occasionally I may not want the default window title Notice. In the following example, I override the default still using the same procedure:
IF O_YNReply('Do you want to import these records again?'|
,'Warning')
O_Message('Records will be imported again')
ELSE
O_Message('Records will not be imported again')
END !IF
This question will now appear as follows:

The question title has changed from Notice to Warning. If the YES button is pressed, the following message appears:

If the NO button is pressed, the files will not be deleted:

Remember these displays are for illustration primarily.
If I want to change both the window title and the icon I code something similar to the following:
IF O_YNReply('Do you want to shut down before balancing'|
,'Balancing'|
,ICON:Exclamation)
O_Message('Shut down without balancing')
ELSE
O_Message('Stop shutdown in order to balance first')
END !IF
This question now appears as follows:

Pressing Yes produces:

Pressing No gives us the following:

Care needs to be taken in phrasing your questions. I usually try to phrase the questions so that YES is the expected answer to the question.
Using this template, I can create a standardized response look and feel throughout my application. Using the template is brief, and lets me concentrate on the logic Im working on.
Copyright © 1999-2008 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $184
(includes all back issues since '99)
Renewals from $134
Two years: $274
Renewals from $224