views:

18

answers:

3

I have an VB ASP.NET (.aspx) file that has deeply nested logic and I'm getting lots of build errors like "If must end with a matching End If" and "Do must end with a matching Loop". How do I begin to debug this beast to at least get it to build?

+1  A: 

The simple answer is to remove a large nested section and if it passes add a bit more until it fails. That's how I approach a problem like this.

Preet Sangha
A: 

Debugging starts after you get it to compile. Really effed code that won't compile you sometimes have to comment out blocks of code fix whats left and uncomment. Also if it just went haywire all of a sudden check for quote issues as a missed quote and break the whole file.

rerun
And since you will know what file is causing the problem, if you are running under some sort of source code versioning system, compare that file with previous versions for a hint...
Martin Milan
A: 

I have found that Visual Studio will generate the correct ending statements, so you have probably deleted a line by mistake, or commented one out.

As a rule, I try to avoid deeply nested statements. Can you refactor? A sequence of IF / ELSE IF / ELSE IF / ELSE / END IF construction is easier for the human eyes and mind to parse. Maybe even temporarily take some deep logic and make a temporary function. Remember, someone will have to maintain your code - and even if that someone is you, in 12 months time, complex structures are almost intelligible.

Ken Ray