Choice variable in a message statement

Posted by gamberoni on 30-Oct-2012 04:54

I have an interesting issue to resolve. We have a piece of custom code that was written by a third-party and

I'm now obliged to support.

It's basically an if statement that if certain conditions are true then it displays a message with a prompt for

a choice. Here's the message code:

MESSAGE "SOR " xx-xxx-elements.element-code
            " is subject to Right to Repair." SKIP
            "Please confirm that the job details are correct." SKIP(1)
            "Select Cancel to amend job details." SKIP
            "Select OK to save job details as they are."
            VIEW-AS ALERT-BOX QUESTION BUTTONS OK-CANCEL
            TITLE "Right to Repair" UPDATE choice AS LOGICAL.
ASSIGN op-no-error = choice.

This all works as we expected. However, the users would like to see a different message & prompt if the

condition is false.

If I add a new message into the program code, then I get an error:

"** Duplicate variable or property name--choice. (218)"

So, I tried defining variables for each message called l-choice-a and l-choice-b, but it still doesn't like it.

And I get the duplicate variable message for both messages.

I'm not a developer - any more - but the only option I can think of is to put the message code into

sub-programs and call them as needed. But, I'd like to think that there's a more elegant solution out there.

Any thoughts?

All Replies

Posted by Marko Myllymäki on 30-Oct-2012 06:08

Hi Tim,

define 'choice' as a variable before the message statements and remove 'AS LOGICAL' from the messages:

DEF VAR choice AS LOGICAL NO-UNDO.

IF THEN
MESSAGE "Text1"
    VIEW-AS ALERT-BOX QUESTION BUTTONS OK-CANCEL
    TITLE "Right to Repair" UPDATE choice.
ELSE
    MESSAGE "Text2"
        VIEW-AS ALERT-BOX QUESTION BUTTONS OK-CANCEL
        TITLE "Right to Repair" UPDATE choice.

Another solution (maybe better): use a character variable for the message text so that you need only one message statement. In this case you need to use CHR(10) instead of SKIP for line feeds:

DEF VAR cMessageText AS CHAR NO-UNDO.

IF THEN
    cMessageText = "Text1" + CHR(10) + "Line2".
ELSE
    cMessageText = "Text2" + CHR(10) + "Line2".


MESSAGE cMessageText
    VIEW-AS ALERT-BOX QUESTION BUTTONS OK-CANCEL
    TITLE "Right to Repair" UPDATE choice AS LOGICAL.

Hope this helps.

Posted by gamberoni on 31-Oct-2012 08:56

Marko

Spot on. My user is very happy - and so am I. You learn something new every day.

Tim

This thread is closed