Page 1 of 1 1
Topic Options
#169774 - 2006-10-23 04:33 PM Probplem with IIF() Function?
Cavester Offline
Fresh Scripter

Registered: 2006-10-17
Posts: 18
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.

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

Registered: 2006-10-17
Posts: 18
Could it be because WriteAndDisplay doesn't return anything?
Top
#169776 - 2006-10-23 04:48 PM Re: Probplem with IIF() Function?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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


Edited by Mart (2006-10-23 04:49 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
lol. WriteAndDisplay doesn't return anything ya ;p
Top
#169778 - 2006-10-23 04:53 PM Re: Probplem with IIF() Function?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
...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

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

Registered: 2006-10-17
Posts: 18
Sorry, yes I know I can do that but I was wondering why IIF doesn't work?

L.

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

Registered: 2006-10-17
Posts: 18
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?

Top
#169782 - 2006-10-23 04:58 PM Re: Probplem with IIF() Function?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#169783 - 2006-10-23 05:01 PM Re: Probplem with IIF() Function?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Code:
If MAPDRIVE('z','\\SERVER\share',1)
WriteAndDisplay("[WARNING] " + @SERROR)
Else
WriteAndDisplay("[OK]")
EndIf


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

Registered: 2006-10-17
Posts: 18
hmm ok but surely IIF shouldn't execute both sections?
Top
#169785 - 2006-10-23 05:02 PM Re: Probplem with IIF() Function?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
LOL. Golfing showed it’s ugly face once more
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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

Registered: 2006-10-17
Posts: 18
Quote:

LOL. Golfing showed it’s ugly face once more




Am I missing something?

Top
#169787 - 2006-10-23 05:06 PM Re: Probplem with IIF() Function?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

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

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
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...
Top
#169789 - 2006-10-23 05:13 PM Re: Probplem with IIF() Function?
Cavester Offline
Fresh Scripter

Registered: 2006-10-17
Posts: 18
Ah cool that explains it. I was likening it with the behaviour of the C++ IIF function.
Top
#169790 - 2006-10-23 05:18 PM Re: Probplem with IIF() Function?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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

Registered: 2006-10-17
Posts: 18
cool
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org