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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a good reference for working with Nested Ifs 2

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
I noticed and confirmed with other users that Crystal Reports XI easily gets confused when you work with nested Ifs. You must help the program by using parenthesis and semi colons. Will someone please refer me to a good reference for learning how to overcome this problem? A textbook or better yet a on-line source.

Thanks in advance.

Steve728
 
It isn't that CR gets confused--it's that the user isn't implementing the solution correctly. I doubt that a book will be of much help on this. You have to ask yourself what clauses belong together, and then enclose them in parens, as in:

if x = 1 then
(
if a = 5 then
b else
c
) else
if x = 2 then
(
if a = 2 then
d else
e
) else
y

-LB
 
I've not had problems with nested If-Then-Else even without using parenthesis. Unless you are making multiple variable assignments within your If-Then-Else. If so, see this by Ken Hamady:


Andy
 
lbass

Is the following correct when adding a third nested If?

if x = 1 then
(
if a = 5 then
(
if q = "Go" then
m else
n
)
b else
c
) else
if x = 2 then
(
if a = 2 then
d else
e
) else
y
 
Your 'b' is hanging in the middle of nowhere. if you remove that:

if x = 1 then
(
if a = 5 then
(
if q = "Go" then
m else
n
)
else
c
) else
if x = 2 then
(
if a = 2 then
d else
e
) else
y

Here it is without parens:

if x = 1 then
if a = 5 then
if q = "Go" then
m
else
n
else
c
else if x = 2 then
if a = 2 then
d
else
e
else
y


Andy
 
andymc

Will you please send me some of your samples using nested if / Else If / Else 3-4 deep? Or perhaps refer me to more examples.I also got the good examples when "Making multiple variable assignments in one formula" from kenhamady.com

Thanks in advance.

Steve728
VBA, .NET, T-Sql 2000 programmer
a newby to Crystal Reports XI
 
For writing any code in any language I'd recommend "Code Complete" by Steve McConnell (MIcrosoft Press). Although it's originally written in 1993, it has best practices for all sorts of coding structures. A whole chapter on If statements.

Also includes good testing and debugging techniques and how to test for boundary conditions

Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top