Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested IF-THEN-ELSE Syntax?

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hi Folks

I need to use some nested loops in a fomula, if I were writing in VB I would define it as such:

If Expr then
If Expr-2 then
Statements
Else
Statements
End If
Else
If Expr-3 then
Statements
End If
End If

How can I approximate this structure in a CR formula syntax? I seem to be having trouble trying to define where one set of nested ifs begin and the other ends.

Thanks

Craig

 
Here's a more specific follow-up with the actual formula I'm trying to implement:

-----------

Stringvar ToSymbol;
stringvar FromSymbol;
stringvar RecID;
StringVar TransType;

if {Orders.OrderUserDef1} = RecID then // Repeat, must be exchange
TransType := 'EXCHANGE'
if {Orders.TranCode} = 0 or {Orders.TranCode} = 2 then
ToSymbol := {Orders.Symbol}
Else
FromSymbol := {Orders.Symbol}
Else // Individual Trade
if {Orders.TranCode} = 0 then
TransType := 'BUY'
FromSymbol := 'CASH'
ToSymbol := {Orders.Symbol}
Else If {Orders.TranCode} = 1 then
TransType := 'SELL'
FromSymbol := {Orders.Symbol}
ToSymbol := 'CASH'
Else If {Orders.TranCode} = 2 then
TransType := 'SHORT SELL'
FromSymbol := 'CASH'
ToSymbol := {Orders.Symbol}
Else If {Orders.TranCode} = 3 then
TransType := "COVER SHORT'
FromSymbol := {Orders.Symbol}
ToSymbol := 'CASH'

RecID := {Orders.OrderUserDef1} // set variable to current RecID

-------------

How do I set this up? Is it the use of Semicolons to set each statement apart? Where should they be located? Please help if you can.

Craig
 
The basic format for an IF expression is ...

if expr_1 then (do_1;do_2) else (do_3;do_4)

for nested IFs use either ...

if expr_1 then (do_1;do_2)
else if expr_2 then (do_3;do_4)
else (do_5;do_6}

or...

if expr_1 then
(do_1;
do_2)
else (do_3;
if expr_2 then
(do_4;
do_5)
else
(do_6;
do_7)
)

Hth,
Geoff

 
Thanks, Geoff, that looks like it helped a lot. I got most of the way thru trial and error but your comments helped me over the hump.

Craig
 
Thanks, Geoff, that looks like it helped a lot. I got most of the way thru trial and error but your comments helped me over the hump.

Hey, is there any way to step through the formulas as they are executing, like you can in VB? I'm getting some strange results and I'd like to see where I'm going wrong.

Craig
 
Easiest way is to split the formula up into smaller formulas and display the results in your detail section !!

Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top