Results 1 to 12 of 12

Thread: [RESOLVED] #Region?

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved [RESOLVED] #Region?

    I hope this doesn't sound like a stupid question but what is the #Region namespace do?

    Thanks from a frustrated VB6 Programmer.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: #Region?

    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:
    1. #Region "RobDog's Code" 'My Region
    2.     Private Sub Button1_Click(sender blah blah...
    3.         Messagebox.show("Blah")
    4.    End Sub
    5. End Region
    6.  
    7. 'Example of it collapsed.
    8. "RobDog's Code"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: #Region?

    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"?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: #Region?

    Quote Originally Posted by RobDog888
    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:
    1. #Region "RobDog's Code" 'My Region
    2.     Private Sub Button1_Click(sender blah blah...
    3.         Messagebox.show("Blah")
    4.    End Sub
    5. End Region
    6.  
    7. 'Example of it collapsed.
    8. "RobDog's Code"
    Ok, thanks I figured it out, one note the End Region requires a # before the word End:

    VB Code:
    1. #Region "Mark's Code" 'My Region
    2.      'Put your code here
    3.  
    4. #End Region
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] #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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] #Region?

    Quote Originally Posted by jmcilhinney
    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 !
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [RESOLVED] #Region?

    Quote Originally Posted by jmcilhinney
    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.
    Unless you're using C++ since # usually begins a preprocessor statement
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] #Region?

    Quote Originally Posted by kasracer
    Unless you're using C++ since # usually begins a preprocessor statement
    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.
    VB Code:
    1. Try
    2.             IO.File.Delete(path)
    3.         Catch ex As Exception
    4. #If DEBUG Then
    5.             MessageBox.Show(ex.ToString())
    6. #Else
    7.             MessageBox.Show("The file could not be deleted.", "I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    8. #End If
    9.         End Try
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [RESOLVED] #Region?

    Quote 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.
    I know. I just wanted to add that incase someone saw this post and tried to use a REGION in C++
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] #Region?

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] #Region?

    Even with conditional compilation it wont confuse the #If with the #Region since it probably doesnt look at just the # character.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] #Region?

    [picky]They are not statements or instructions, they are called "Directives" [/picky]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width