Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ICASE() alternative
Message
From
22/01/2019 10:47:35
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
22/01/2019 10:19:54
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01665620
Message ID:
01665621
Views:
83
>Does anyone know another way to do this? I want to set multiple values (two in this case) in an ICASE() based on the one matched condition.

Why I don't see why (you ask this), but obviously:
IIF( test1, match1(@lnVar1, @lnVar2),;
 IIF(test2, match2(@lnVar1, @lnVar2),;
 nomatch(@lnVar1, @lnVar2)))
and
LOCAL lnVar1, lnVar2
LOCAL test1, test2

* Change these values to see how it works with each
test1 = .f.
test2 = .f.

TestMatch(test1,test2,@lnVar1, @lnVar2)

? lnVar1, lnVar2


procedure TestMatch
lpara;
test1, test2, lnVar1, lnVar2

if test1
match1(@lnVar1, @lnVar2)
return
endif

if test2
match2(@lnVar1, @lnVar2)
return
endif

nomatch(@lnVar1, @lnVar2)
endproc


FUNCTION match1
LPARAMETERS tnVar1, tnVar2
    tnVar1 = 1
    tnVar2 = 2
ENDFUNC



FUNCTION match2
LPARAMETERS tnVar1, tnVar2
    tnVar1 = 10
    tnVar2 = 20
ENDFUNC



FUNCTION nomatch
LPARAMETERS tnVar1, tnVar2
    tnVar1 = -1
    tnVar2 = -2
ENDFUNC
if you like if-else-if stacks, this will work as well
and
procedure TestMatch
lpara;
test1, test2, lnVar1, lnVar2

do case
 case test1
  match1(@lnVar1, @lnVar2)
 case test2
  match2(@lnVar1, @lnVar2)
 otherwise
  nomatch(@lnVar1, @lnVar2)
endcase
endproc
update:
Ah, I missed the point you like to have it as an ICASE
ICASE(.T.,TestMatch(test1,test2,@lnVar1, @lnVar2))
Rick, I do not understand what you are trying to do. It returns .T. and altere teh paras, one way is more or less like the next.
Except
Speed
code clearence
and:
FUNCTIONS should not do this. A FUNCTION should return a value based on the parameters. No side effects, no parameter by reference.

I've done odd things with functions (in VFP SQL, to get special effects), but at least a return value ....
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform