how to create collapsible code

  • Thread starter Thread starter cj2
  • Start date Start date
C

cj2

how do I make a block of my code collapsible with one of those +s like
functions have to collapse and expand them? I want to make a page long
sql insert statement collapse. it's taking too much monitor real estate
while I'm scrolling around.
 
cj2 said:
how do I make a block of my code collapsible with one of those +s like
functions have to collapse and expand them? I want to make a page long
sql insert statement collapse. it's taking too much monitor real estate
while I'm scrolling around.

\\\
#Region "<label>"
...
#End Region
///

Alternatively you could place the method in a partial class.
 
Hi Cj,

If what you want to just make a code block collapsed when being displayed
in Visual studio IDE, you can refer to Herfried's suggestion(using the
#region directive). Here is the reference about #region in MSDN:

#region
http://msdn.microsoft.com/en-us/library/9a1ybwek(VS.71).aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications


--------------------
 
Thanks Herfried and Steven but I get "#Region and End Region statements
are not allowed within method bodies. I'm just trying to make a very
long sql statement collapse in the IDE. This is inside a web method.
 
cj2 said:
Thanks Herfried and Steven but I get "#Region and End Region
statements are not allowed within method bodies. I'm just trying to
make a very long sql statement collapse in the IDE. This is inside a
web method.

Could you put the SQL into a stored procedure in the database instead?

That way you'd only see the name of the sp and the code for setting the
parameters.

Andrew
 
Thanks Herfried and Steven but I get "#Region and End Region statements
are not allowed within method bodies.  I'm just trying to make a very
long sql statement collapse in the IDE.  This is inside a web method.

As stated, stored procedures may be an alternative, however, you can
also try to use a Region outside your method within a string, then
call that string, which holds the whole SQL statement, from your
method as follows:

Public Class Class_Name
#Region "<Statement>"
' That's short just for example, you can extend and split
' using an _ underscore and & operator in that region
Dim statement As String = "SELECT * FROM Table Where ID=5"
#End Region
Sub ExecuteSQL()
' Do the stuff
' Use "statement" variable here
End Sub
End Class

Thus, your region can be collapsed, plus your whole SQL statement will
be held in just as a string. Not sure, but hope it helps.

Onur Güzel
 
how do I make a block of my code collapsible with one of those +s like
functions have to collapse and expand them? I want to make a page long
sql insert statement collapse. it's taking too much monitor real estate
while I'm scrolling around.

Make the sql a resource.
 
Yes that would work.
As stated, stored procedures may be an alternative, however, you can
also try to use a Region outside your method within a string, then
call that string, which holds the whole SQL statement, from your
method as follows:

Public Class Class_Name
#Region "<Statement>"
' That's short just for example, you can extend and split
' using an _ underscore and & operator in that region
Dim statement As String = "SELECT * FROM Table Where ID=5"
#End Region
Sub ExecuteSQL()
' Do the stuff
' Use "statement" variable here
End Sub
End Class

Thus, your region can be collapsed, plus your whole SQL statement will
be held in just as a string. Not sure, but hope it helps.

Onur Güzel
 
Yes, but I'm not a fan of stored procs any more. I did a lot of them a
couple years ago and I find it more difficult to maintain as the code is
in so many places.
 
Tom Shelton said:
I means embed the sql as a resource. Then, you don't have it lying around
in
your code. You can just retrieve it by name.

.... via 'My.Resources.*' in VB.
 
Back
Top