This is in response to the whole 'how do i check if a checkbox is true' question.
THe problem people have is they compare against the wrong type (ive done it myself).
You would EXPECT a checkbox to return an L type - but I think there are certain events or times where it doesnt.
Sometimes it returns "1" or "true" instead of .t. and "0"/"false" instead of .f.
This makes the comparison fieldname==.t. lead to unexpected results in certain events/cases.
So here you go world:
Here is my guide. I use checkboxes no problem.
FieldName: active
Control Type:Checkbox
Treat as Logical Field: Checked
In other fields:
Show hide Expression: active=0or1
Enable Expression: active=0or1
Comparison in Xbasic:
convert_type(active,"L")==.t. <<Force a convert to L type (Failure to convert to L results in 0 which makes this statement false)
convert_type(active,"N")==1 <<If the above fails (which it shouldnt, you can convert to N and compare against N)
THe problem most people have is they're comparing against the wrong type
for example:
IF active==1 'if active is an L type, this may not evaluate properly
IF active==.t. 'if active is a C type, this may not evaluate properly
Using convert_type(active,"L") converts it to type L (boolean).
So, you compare the converted type L to .t.|.f. (boolean operators)
Interactive Window Mumbo Jumbo:
Moral of the story, dont compare apples to oranges.
If you are comparing x against y make sure they're the same type and you wont get unexpected results.
THe problem people have is they compare against the wrong type (ive done it myself).
You would EXPECT a checkbox to return an L type - but I think there are certain events or times where it doesnt.
Sometimes it returns "1" or "true" instead of .t. and "0"/"false" instead of .f.
This makes the comparison fieldname==.t. lead to unexpected results in certain events/cases.
So here you go world:
Originally posted by Larsman
View Post
FieldName: active
Control Type:Checkbox
Treat as Logical Field: Checked
In other fields:
Show hide Expression: active=0or1
Enable Expression: active=0or1
Comparison in Xbasic:
convert_type(active,"L")==.t. <<Force a convert to L type (Failure to convert to L results in 0 which makes this statement false)
convert_type(active,"N")==1 <<If the above fails (which it shouldnt, you can convert to N and compare against N)
THe problem most people have is they're comparing against the wrong type
for example:
IF active==1 'if active is an L type, this may not evaluate properly
IF active==.t. 'if active is a C type, this may not evaluate properly
Using convert_type(active,"L") converts it to type L (boolean).
So, you compare the converted type L to .t.|.f. (boolean operators)
Interactive Window Mumbo Jumbo:
Code:
?convert_Type(1,"L") = .T. ?convert_Type(0,"L") = .F. ?convert_type("true","L") = .T. ?convert_type("false","L") = .F. ?convert_type(.t.,"L") = .T. ?convert_type(.f.,"L") = .F. COMPARISONS ?"true"==.t. CORRECT BUT MISUNDERSTOOD RETURN BECAUSE OF COMPARING 2 DIFFERENT TYPES = .F. ?convert_type("true","L")==.t. CORRECT = .T. ?"false"==.t. CORRECT BUT MISUNDERSTOOD RETURN BECAUSE OF COMPARING 2 DIFFERENT TYPES = .F. ?convert_type("false","L")==.t. CORRECT = .F. ?1==.t. CORRECT BUT MISUNDERSTOOD RETURN BECAUSE OF COMPARING 2 DIFFERENT TYPES = .F. ?convert_type(1,"L")==.t. CORRECT = .T. ?0==.t. = .F. ?convert_type(0,"L")==.t. = .F. FINAL EXAMPLE: APPLES TO ORANGES dim myfield as C="true" ?typeof(myfield) = "C" ?typeof(.t.) = "L" ?myfield==.t. 'C to L comparison - WRONG! = .F. ?typeof(convert_type(myfield,"L")) = "L" ?convert_type(myfield,"L")==.t. = .T.
If you are comparing x against y make sure they're the same type and you wont get unexpected results.