Link to home
Start Free TrialLog in
Avatar of jr_barros_jr
jr_barros_jr

asked on

Collapse Part of Code

Is there a way to create an outline or collapse part of code inside a function, like (if/end if) (for/next),(do/loop) etc using Visual Studio ?

thank tou
Avatar of silemone
silemone
Flag of United States of America image

#region

#endregion


put code in between and you can collapse it/expand it at will in vs
Avatar of kaufmed
Regions are the way to go, however, as your Zone is marked Vb.NET, regions are more restricted in VB. You cannot place them inside of a method body (the sytax checker will complain). You can use regions to collapse groups of methods, though.

You also must give your region a name (as a quoted string).
'Error
    Sub Main()
        #region "MyRegion"
        For i As Integer = 0 To 16
            Console.Write("a")
        Next
        #end region
    End Sub

' Proper
#Region "MyRegion"   <-- Must use quotes

    Sub Main()
        For i As Integer = 0 To 16
            Console.Write("a")
        Next
    End Sub

    Sub dosomething()

    End Sub
#End Region

Open in new window

Avatar of jr_barros_jr
jr_barros_jr

ASKER

Folks,

"'#Region' and '#End Region' statements are not valid within method bodies." (See attached picture)

So, #Region is only the solution outside "method". I would like to know inside sub, function, methods etc.

Any idea?


ExEx.png
change the language you're programming - i.e. use c# instead...unfortunately vb.net does not allow this...
otherwise you could change IDE's i suppose to one that may parse and compile vb and take into consideration regions inside of a method...
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See previous comment.
Is there any workaround for that?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial