Simply Clarion - A Simple Yes/No Template

by Don Reynolds

Published 1998-01-01    Printer-friendly version

Download the code here

Getting Answers to Questions

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:

  • Are you really sure you want to delete all these files?
  • Do you want to import these records again?
  • Do you want to shut down before balancing?
  • Do you want to delete all of today’s transactions and start over?
  • Isn’t your programmer wonderful?

Well, OK, the last one I don’t really use, but you get the idea. These questions can appear throughout the system.

Handcoding a solution

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.

Dwr60001.gif

The parts of this message are as follows:

  • ‘Do you really want to delete all these files?’ is the question text.
  • ‘Question’ is the message box caption
  • ‘ICON:Question’ is the message box icon
  • ‘BUTTON:Yes+ BUTTON:No’ are buttons to appear in the message box
  • The second BUTTON:Yes is the default button
  • The ‘0’ makes this message box application modal, requiring an answer before anything else is done in this application.

Standardizing a solution

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.

The Template

#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
#!-------------------------------------------------------

Using the Template

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.

Dwr60001.gif

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

Dwr60002.gif

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

Dwr6003a.gif

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

Dwr6003b.gif

Driving the Procedure—using all defaults

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, I’m 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:

Dwr6001a.gif

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

Dwr60005.gif

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

Dwr60006.gif

Driving the Procedure – Using Some Defaults

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:

Dwr60008.gif

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

Dwr60009.gif

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

Dwr60010.gif

Remember these displays are for illustration primarily.

Driving the Procedure—using no defaults

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:

Dwr60012.gif

Pressing Yes produces:

Dwr60013.gif

Pressing No gives us the following:

Dwr60014.gif

Notes

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 I’m working on.

Printer-friendly version

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $184

(includes all back issues since '99)

Renewals from $134

Two years: $274

Renewals from $224

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links