Solved

Nested if else statements giving error

Posted on 2009-04-15
6
550 Views
Last Modified: 2013-12-14
I have the following nested if else statement and it keeps giving me the error that it has an illefal else without matching if .  I've tried playing with the brackets and can't get it to work.  Can someone point out where the problem is?  Thanks in advance!
if (!bEndOfDay)
	{
		if (!MoveData(csTblName, csBlobTable, csBulkTable,pSqlDb))
		{
			update_detail("Error in moving data from ....");
			uRetVal = FALSE;
		}
		else
		{
			if (g_SysCfg.IsVerbose())
				update_detail("Data moved from to .....");
		}
	}
	else
	{
		if (!MoveBulkData(csBulkTable,pSqlDb))
		{
			update_detail("Error in moving data from ....");
			uRetVal = FALSE;
		}
		else
		{
			if (g_SysCfg.IsVerbose())
				update_detail("Data moved from to .....");
		}
	}
	else
	{
		if (!MoveAlertData(csAPAlertTable,pSqlDb))
		{
			update_detail("Error in moving data from ....");
			uRetVal = FALSE;
		}
		else
		{
			if (g_SysCfg.IsVerbose())
				update_detail("Data moved from to .....");
		}
	}
	return uRetVal;

Open in new window

0
Comment
Question by:Cashmgmt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 24149528
Well, take a look at your code, there's indeed one 'else' that has no 'if':
if (!bEndOfDay)
        {
                if (!MoveData(csTblName, csBlobTable, csBulkTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        }
        else
        {
                if (!MoveBulkData(csBulkTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        } // <---------- if (!bEndOfDay) ends here
 
        else // <----------- there's no if for that one
        {
                if (!MoveAlertData(csAPAlertTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        }
        return uRetVal;

Open in new window

0
 

Author Comment

by:Cashmgmt
ID: 24149846
Yeah, I see it and that's where the program is stopping when I try to build, but I'm new to programming and I can't figure out how to make the else that's causing the error part of the if (!bEndOfDay).  can you help?
0
 
LVL 86

Expert Comment

by:jkr
ID: 24150075
Well, that's pretty hard, since that's not a complete function and I have no idea what it is supposed to do ;o)

Well, is 'MoveAlertData()' supposed to execute when 'bEndOfDay' is 'true' or 'false' or under what other condition?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Cashmgmt
ID: 24150098
if bEndOfDay is false, then i need it to do the MoveDate then MoveBulkDate then MoveAlertData
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 24150121
Then, you don't need ansy 'else' for 'if (!bEndOfDay)':
if (!bEndOfDay)
        {
                if (!MoveData(csTblName, csBlobTable, csBulkTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        
                if (!MoveBulkData(csBulkTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        
                if (!MoveAlertData(csAPAlertTable,pSqlDb))
                {
                        update_detail("Error in moving data from ....");
                        uRetVal = FALSE;
                }
                else
                {
                        if (g_SysCfg.IsVerbose())
                                update_detail("Data moved from to .....");
                }
        }
        return uRetVal;

Open in new window

0
 

Author Closing Comment

by:Cashmgmt
ID: 31570530
You're absolutely right.  So obvious and I didn't see it.  Thanks, that worked!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question