Solved

Mismatched Curly Braces in C#

Posted on 2006-07-05
5
668 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now