Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Organize Your Code With Regions

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Picture it: you've just written an aspx page with 3 panels, 3 datagrids, 15 buttons, 20 textboxes, and 3 drop down lists. You've also added about 30 subs to your code behind.
THATS ALOT OF CODE!

Traditionally, viewing the code would mean one big, long page that seems to go on forever and ever in a big listing of code. You could group the code and add nice little comment lines like
'---------------------------------------------------
but that was the only real way to seperate them.

Visual Studio.NET provides a new way to organize your code that makes grouping related subs/functions a snap, and makes it look pretty. This new way is called a Region.

To make a Region, all you need to do is type

#Region "descriptive text"

#End Region

This will create a top level container that you can dump code into. To hide all the code, you just have to click on the regions +/- button and voila!

To give you an example of what I've done with one of my apps, here's a schema of my code:

-ControlList
-PageCode
-TabButtonCode
-StateCode
-MenuButtonCode
-Panel:Main
-ListBoxCode
-FillList
-ClearList
-Panel:Details
-DatagridCode
-Panel:Results
-DatagridCode
-Panel:Find
-DatagridCode

As you can see, a huge page of code is now viewed as an xml-like tree, so that only the information you want is hte information you have to dig through.


As Martha would say, "Regions: they're a good thing"

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top