Question How to check the Character Value for Logical field

reynold12

New Member
Hello All,

I am using OE11.1.

I just stuck in one situation where I need to check the value stored in the logical field with a Character string value (which I am getting it from somewhere else).
I can re-create the above issue with the below code snippet:

Code:
def var lChk as log  format "$/%" no-undo.
def var cVar as char              no-undo.
 
cVar = "$". /*I am getting it from other source*/
assign lChk = True.
 
/*Now I want to check whether the lChk is containing $ or % by comparing with cVar and then need to process some logic*/
/*But if I am trying to use String(lChk) then it's resulting yes.. So how Can I get $ of lChk*/
 
if string(lChk) = cVar then
  message "getting $" view-as alert-box.
else
  message "Getting %" view-as alert-box.
 
/*In Result I am always getting message - Getting %.. How can I achieve to get the message - Getting $ */

Could anyone Please help in this regard.

Thanks...
 

oli

Member
Try

Code:
if string(lChk,"$/%") = cVar then
  message "getting $" view-as alert-box.
else
  message "Getting %" view-as alert-box.
 

RealHeavyDude

Well-Known Member
You need to be aware that "$/%" is only the display representation of TRUE / FALSE ( or yes / no, respectively ). If you convert the value of a logical to character utilizing the STRING function you will always get "yes" or "no". You need to add the FORMAT so that the conversion knows what it is that you expect as character represention for TRUE/FALSE by adding "$/%" to it. But you could add any other format phrase that is valid for a logical.

Heavy Regards, RealHeavyDude.
 

TomBascom

Curmudgeon
The ability to use formats like "$/%" for a logical field is one of those capabilities that makes a nice demo.

Actually using that capability in production code is grounds for having your programmer license revoked.
 

Cringer

ProgressTalk.com Moderator
Staff member
My personal favourite use for this is DISPLAY STRING(TRUE,"No/Yes").
 

TomBascom

Curmudgeon
Just as there are names that shall not be mentioned, there is code that one should not type.

I was once explaining the syntax for a recursive delete command. In particular I was explaining the usefulness of the -f option to suppress errors. I was doing this while positioned in front of a keyboard. And logged in. As root. In the / directory. The ending of the story is seared into my memory.
 

Cringer

ProgressTalk.com Moderator
Staff member
Ouch!!! The only consolation I suppose is it helped to make you the man you are today, and I'd class you amongst the most respected Progress developers on the planet.
 

GregTomkins

Active Member
I remember Dan (I'll omit his last name, but let's just say maybe he is the 2nd most respected Progress person) saying once (at a conference presentation) how when you do that, your best course of action is to pull the plug on the server as quickly as possible and hope the delays in the caching system will save you ...

These days that would be hard since the plug is usually some unknown distance away in some unknown city, but anyway ...
 
Top