#179603 - 2007-08-22 10:22 PM
Re: Golf Code...
[Re: Gargoyle]
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
$Input = "Site-Loc-A-Type"
If "A" = split($Input,"-")[2]
? "Do stuff"
Else
? "Do other stuff"
EndIf
IIF is only good to return a value not to perform multiple steps of code.
Edited by Howard Bullock (2007-08-22 10:23 PM)
|
Top
|
|
|
|
#179610 - 2007-08-22 10:45 PM
Re: Golf Code...
[Re: Gargoyle]
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
works either way.
"A" = split or split ="A"
|
Top
|
|
|
|
#179628 - 2007-08-23 10:42 AM
Re: Golf Code...
[Re: Björn]
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
It is on page 79 of the kix2010.doc you youngster , IIF only returns values.
|
Top
|
|
|
|
#179629 - 2007-08-23 12:09 PM
Re: Golf Code...
[Re: Witto]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
IIf is cool, but realize that it has 2 limitations. Besides only returning values, it generally only compares values. You can't put a UDF or most other functions in the test part. Otherwise you could golf it down to $x = IIf(Split($String, '-')[2] = 'A', 'True', 'False') (which might work, actualy - just an example of what you really need to test)
One of my favorite uses for IIf is flag setting when there are multiple conditions in a long cycle of code that can set the flag. Here's some pseudo code:
For Each $X in $Array
$Flag = 0
; process $X
$Flag = IIf($X = 3, 1, $Flag)
; process $X some more
$Flag = IIf($X = 27, 1, $Flag)
; process $X yet again
$Flag = IIf($X < 0, 1, $Flag)
If $Flag "message" EndIf
Next
In this example, there are 3 conditions in each iteration where the flag can be set. Note that IIf either sets the flag to one, or to the current value of flag. This allows any test to set the flag, but no test can reset it once set until the loop iteration is complete.
This is really handy in checking for non-fatal errors, where you want to discard data but not terminate the script.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#179638 - 2007-08-23 06:09 PM
Re: Golf Code...
[Re: Witto]
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
if IIf(Split($String, '-')[2] = 'A', 1, 0)
;true
else
;false
endif
Edited by Bryce (2007-08-23 06:10 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
2 registered
(morganw, mole)
and 415 anonymous users online.
|
|
|