Solved

Mismatched Curly Braces in C#

Posted on 2006-07-05
5
676 Views
Last Modified: 2012-05-05
Hello,

Does anyone know of a trick or a good way to figure out how to find the missing opening or closing brace in your code?

I have a function that is about 1500 lines long and contains several IF-THEN-ELSE structures and I'm having the worse time trying to figure out what's missing.  Any suggestions will be GREATLY appreciated.  TIA

-Mari

0
Comment
Question by:FoxProMari
[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
5 Comments
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 300 total points
ID: 17045704
Suggestons:
#1 Code formatting
Try well-format you ceode. Like:
if (a == b)
   {
      .... //code here
    }
and not like

if (a==b){
.... //code here }
if (a==b)
{
... //code here }

#2 Comments & uncomment step by step
Comment all of the code inside a function and then uncomment line by line/block by block and compile in between.

#3 Comment the end of block
Put comment on every closing brace. Like
//checking if a==b
if (a==b)
   {
    ... //code here
   } //end of checking if a==b

Combinations possible

Good luck :)

0
 
LVL 9

Assisted Solution

by:daniel_balla
daniel_balla earned 100 total points
ID: 17046248
Hi FoxProMari,
Did you try Edit.FormatSelection in VS? That would pretty-format the code and you should see it straight away.
Otherwise, I guess a more elegant solution would be to write a regular expression to find it, but I don't have such an example ready.

Cheers!
0
 
LVL 9

Assisted Solution

by:bele04
bele04 earned 100 total points
ID: 17047790
You can try to regionize your code so that you don't have to view them all at once.  Like you region a set of if else statements, for ex:

#region
if(condition)
{
//code
}
else
{
//code
}
#endregion

This way you can divide your code into different sections and it'll be much easier to debug it since you'll only be dealing with the section inside the enclosed region.
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17048606
#Region' and '#End Region' statements are not valid within method bodies.
At least thats what VB 2005 Express Edition says
0
 

Author Comment

by:FoxProMari
ID: 17055703
Hello,

Thanks to all who answered.  I ended up pulling out each section of code and putting it into a function using the Switch command to ascertain which function to execute.  I started to do it this way but ended up going off on a tangent and this mess is the result of that adventure.

If none of you mind, I'll split the points among you because they all look like good suggestions.  Hopefully I'll get to test them on a more manageable block of code :-)

Thanks again!

-Mari
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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