Cavester
(Fresh Scripter)
2006-10-23 04:33 PM
Probplem with IIF() Function?

Hi, maybe this is something I am doing stupid!

I am using the IIF() function as follows...

Code:
IIf(MAPDRIVE($sDriveMap,,1) == 0, WriteAndDisplay("[OK]"), WriteAndDisplay("[WARNING] " + @SERROR))



However, if MAPDRIVE succeeds IIF seems to execute both WriteAndDisplay functions. However if I take the functions out so, i.e. "[OK]" is left and MAPDRIVE succeeds only the "[OK]" is executed hence written to the screen.

Any ideas on what is causeing this?

Thanks.

Lee.


Cavester
(Fresh Scripter)
2006-10-23 04:40 PM
Re: Probplem with IIF() Function?

Could it be because WriteAndDisplay doesn't return anything?

Mart
(KiX Supporter)
2006-10-23 04:48 PM
Re: Probplem with IIF() Function?

A link to the WriteAndDisplay function would be nice

http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=170255&an=0&page=0&vc=1


Björn
(Korg Regular)
2006-10-23 04:51 PM
Re: Probplem with IIF() Function?

lol. WriteAndDisplay doesn't return anything ya ;p

Mart
(KiX Supporter)
2006-10-23 04:53 PM
Re: Probplem with IIF() Function?

You could do this.
You need to include the mapdrive and writeanddisplay UDF's in the code.

!!WARNING!! NOT TESTED

Code:

Break on

$rc = MAPDRIVE('z','\\SERVER\share',1)
If $rc = 0
WriteAndDisplay("[OK]")
Else
WriteAndDisplay("[WARNING] " + @SERROR)
EndIf



Björn
(Korg Regular)
2006-10-23 04:55 PM
Re: Probplem with IIF() Function?

...man... just alter the WriteAndDisplay to give a output ;P
this just proves that I shouldn't 'open' my keyboard before I've thought things thro ;P


Cavester
(Fresh Scripter)
2006-10-23 04:55 PM
Re: Probplem with IIF() Function?

Sorry, yes I know I can do that but I was wondering why IIF doesn't work?

L.


Cavester
(Fresh Scripter)
2006-10-23 04:56 PM
Re: Probplem with IIF() Function?

Quote:

...man... just alter the WriteAndDisplay to give a output ;P
this just proves that I shouldn't 'open' my keyboard before I've thought things thro ;P




but shouldn't IIF just return an empty string if there is nothing to return?


Richard H.Administrator
(KiX Supporter)
2006-10-23 04:58 PM
Re: Probplem with IIF() Function?

You're not doing anything too stupid, however the way IIF() works is not obvious if you are used to tertiary constructs in other languages.

Basically, IIF() works like a function- this is *completely* different to IF/ELSE/ENDIF which is a control structure.

Because it is a function it takes parameters, so for it to work any expressions have to be resolved first. This means that your WriteAndDisplay() function calls are first executed to get their values, then the conditional part of the expression is evaluated and the relevant result is passed back.

Basically you are trying to use IIF() for a purpose that it's not designed for.


Richard H.Administrator
(KiX Supporter)
2006-10-23 05:01 PM
Re: Probplem with IIF() Function?

Code:
If MAPDRIVE('z','\\SERVER\share',1)
WriteAndDisplay("[WARNING] " + @SERROR)
Else
WriteAndDisplay("[OK]")
EndIf



Cavester
(Fresh Scripter)
2006-10-23 05:01 PM
Re: Probplem with IIF() Function?

hmm ok but surely IIF shouldn't execute both sections?

Mart
(KiX Supporter)
2006-10-23 05:02 PM
Re: Probplem with IIF() Function?

LOL. Golfing showed it’s ugly face once more

Cavester
(Fresh Scripter)
2006-10-23 05:03 PM
Re: Probplem with IIF() Function?

Quote:

LOL. Golfing showed it’s ugly face once more




Am I missing something?


Richard H.Administrator
(KiX Supporter)
2006-10-23 05:06 PM
Re: Probplem with IIF() Function?

Quote:

hmm ok but surely IIF shouldn't execute both sections?




Yes it should.

You can only pass simple parameters to the IIF() function, so the result of the expressions (your functions and the conditional part) *have* to be resolved before IIF() is called.

To do anything different would require you to be able to pass function references, which is not possible in KiXtart.


Björn
(Korg Regular)
2006-10-23 05:07 PM
Re: Probplem with IIF() Function?

Yes, check out all the kixtart-golfing series in the ot-forum you could always check out the learning-series if you wish too (under scripts and examples I think). But, now we know why it didn't really work out the way it was supposed to. back to topic - I do have to advise you to alter the WriteAndDisplay to throw ya an error-code tho...

Cavester
(Fresh Scripter)
2006-10-23 05:13 PM
Re: Probplem with IIF() Function?

Ah cool that explains it. I was likening it with the behaviour of the C++ IIF function.

Mart
(KiX Supporter)
2006-10-23 05:18 PM
Re: Probplem with IIF() Function?

Quote:

Quote:

LOL. Golfing showed it’s ugly face once more




Am I missing something?




Yes you are missing something.
If time allows do a search on this board with Golf in the subject line and you'll see. Lot’s of fun but hard to keep up with the others sometimes.


Cavester
(Fresh Scripter)
2006-10-23 05:41 PM
Re: Probplem with IIF() Function?

cool