ExportCus = IIF(GetControlValue("QBCUSTXFER", "Cnt", "Code") = "YES", .T., .F.)
can someone explain the diffrence between if and iif, i have tried if insted of iif and thats not working. help me
Asked
Active
Viewed 517 times
-1

Lone Warriour
- 15
- 3
-
2what means 'not working'? – nilsK Nov 19 '19 at 11:54
-
3Hello and welcome to SO, a.arun. Please consider [ask] and taking the [tour]. Then please improve your question, so we can help you. Happy coding! – Fildor Nov 19 '19 at 12:13
1 Answers
1
IIF
is sometimes called Immediate IF. It works much like the ternary ? :
operator in C, and other languages, or as a simplified if-then-else
.
In you example, when the function call GetControlValue("QBCUSTXFER", "Cnt", "Code")
returns "YES", ExportCus
is assigned the value .T.
(true), otherwise, it's assigned the value .F.
(false).
Written as an if
statement:
IF (GetControlValue("QBCUSTXFER", "Cnt", "Code") = "YES")
ExportCus = .T.
ELSE
ExportCus = .F.
ENDIF

Herb
- 636
- 1
- 15
- 29
-
Just to add a little more, IIF() is useful in places where you need an expression such as report fields. In regular code, you can do it either way. Personally, I think IF results in more readable code, except in cases where all three parameters of IIF() are short and simple. – Tamar E. Granor Nov 19 '19 at 21:32
-
and depending on the version VFP, ICASE() allows for multiple via such as ICASE( cond1, true, cond2, true, cond3, true, false ) – DRapp Nov 25 '19 at 23:16
-
Your answer could even be simplified one more level via.. ExportCus = GetControlValue( "QBCUSTXFER", "Cnt", "Code" ) = "YES". Because the function returns YES or NO. You are comparing to "YES". If it is the same, it returns TRUE directly to the variable. – DRapp Apr 25 '20 at 03:12
-