I hope this doesn't sound like a stupid question but what is the #Region namespace do?
Thanks from a frustrated VB6 Programmer.
Printable View
I hope this doesn't sound like a stupid question but what is the #Region namespace do?
Thanks from a frustrated VB6 Programmer.
Its not a namespace per se. It a way to create a custom grouping of code. Its only for ease of reading.
You can make one to hold related code or properties etc. Whatever you want.
VB Code:
#Region "RobDog's Code" 'My Region Private Sub Button1_Click(sender blah blah... Messagebox.show("Blah") End Sub End Region 'Example of it collapsed. "RobDog's Code"
Thanks for the post and congrats on your MVP well deserved :).
So let me get this straight, it is just used for formatting your code, in order to allow your code to be read easier. Wherever the #Region is located will allow you to collapse the code inbetween the "Tags"?
Ok, thanks I figured it out, one note the End Region requires a # before the word End:Quote:
Originally Posted by RobDog888
VB Code:
#Region "Mark's Code" 'My Region 'Put your code here #End Region
Any line of code that starts with "#" is not compiled. Code regions are purely an IDE device to make code more readable. They have nothing whatsoever to do with the language (VB) or the platform (.NET). They are purely for Visual Studio's use.
Thanks for the post, I was a little confused as to what it was used for but as usual the members of VBF cleared it up for me :) !Quote:
Originally Posted by jmcilhinney
Unless you're using C++ since # usually begins a preprocessor statementQuote:
Originally Posted by jmcilhinney
You confirm my point. The line beginning with the "#" is not compiled. It is an instruction to the compiler/preprocessor. VB.NET supports conditional compilation these days, a la the C preprocessor, e.g.Quote:
Originally Posted by kasracer
VB Code:
Try IO.File.Delete(path) Catch ex As Exception #If DEBUG Then MessageBox.Show(ex.ToString()) #Else MessageBox.Show("The file could not be deleted.", "I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error) #End If End Try
I know. I just wanted to add that incase someone saw this post and tried to use a REGION in C++Quote:
Originally Posted by jmcilhinney
You can create regions in C++ as well. In VC++ you use "#pragma region" and "#pragma endregion". Like I said, it's a Visual Studio feature, so it will only work in Visual Studio.
Even with conditional compilation it wont confuse the #If with the #Region since it probably doesnt look at just the # character.
[picky]They are not statements or instructions, they are called "Directives" :)[/picky]