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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying output of logic field

Status
Not open for further replies.

OldtTimerDon

Programmer
Oct 6, 2012
34
US
My table contains a logic field. I want the output to display "True" if the value is "T" or 't' otherwise, the value should be blank.
I tried "iif(upper(member)="T", "True"," ") in the When method. It doesn't work...I am baffled. How can I accomplish this simple task. I have been away from Foxpro for 10 years and some brain cells have died after such a long sojourn.
Don
Sun City, AZ
 
Hello again Don,

First of all, if the field Member is a logical field, then upper(member)="T" isn't going to get you anywhere. You can't use UPPER() with a logical field, and the field can't contain "T". The values of a logical field are .T. and .F. (note the dots). Those aren't character string, like "T". They are the way Foxpro shows logical values.

So, what you want is something like this.

Code:
THIS.Value = IIF(Member = .T., "True", "False")

However, you can omit = .T., as that's implied. So the following is OK:

Code:
THIS.Value = IIF(Member, "True", "False")

You can put that in the Init of the textbox, and also execute it when you refresh the form (in which case, THIS would become THISFORM.MyTextbox).

Do not set the textbox's ControlSource to the logical field. Just give it an initial value of an empty string, then execute the above code.

Give it a try, and come back if any problems.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I want the output to display

If you mean printed output, you want to print IIF(logicalfield,"True","").

If you're just talking about a field on a form, the usual way to display logical fields is the checkbox control. It has a caption property you could set, probably in the form's Refresh method.
 
While it is not precisely as you describe, you can also use the InputMask property for new entries

If you look in your VFP Help for InputMask you will find:
Y Y, y, N, and n for the logical values true (.T.) and false (.F.), respectively.

otherwise, the value should be blank.
Keep in mind that the default for Logical fields is FALSE.
So if the Logical field value is Blank (Empty) its 'seen' as FALSE.

However if you were utilizing the conversions suggested by Mike above you might want to add something like:
Code:
THIS.Value = IIF(Member, "True", IIF(ISBLANK(Member),"","False"))

Good Luck,
JRB-Bldr
 
You've got all advice you need.

You saying "if the value is "T" or 't'" makes me wonder where you saw this. A logical field can have values .T., .F., .NULL. and be blank. The browse may show T without the dots, but I never saw it displaying a lower case t.

Anyway, being displayed as a letter, it is not a letter. Indeed what is stored in the DBF file is a byte, a char being really the letter "T", "F", or " ", but nevertheless you can't use string functions on a logical type field.

Bye, Olaf.
 
Mike, Olaf, et al
Thanks for the help...problem solved.

Originally, members was a one character field with several alpha options. When I reduced the options, I converted the field to a logical field and forgot to adjust the code because of change in field type. I made much bigger mistakes before I forgot most of what I knew 10 years ago...

Senile Senior Don
Sun City, AZ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top