?
Solved

Mismatched Curly Braces in C#

Posted on 2006-07-05
5
Medium Priority
?
682 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:Mariyam
[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 1200 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 400 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 400 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:Mariyam
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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