VB.NET Example Code & Hints you may not know-VBForums
Results 1 to 17 of 17

Thread: VB.NET Example Code & Hints you may not know

Hybrid View

  1. #1

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    VB.NET Example Code & Hints you may not know

    This thread is going to be devoted to giving helpful hints about VB.NET, not in the code sense, but in a general sense. I would like to get a long list going, but to avoid this from being a runaway thread, it will be locked. If you would like to submit something, please PM me. I will review your submission and if it fits the thread, I will post it here. People who submit valid tips will be given credit for the submission.

    This is more of a tip of the day type thread. So please no CODE examples like "how to cancel a keypress", that is a topic for its own thread (which there are many of already). What I am looking for is more tips and tricks for the IDE, the framework, the help, etc....

    All tips currently are from VS.NET 2003, but most (if not all) still apply in both 2002, and 2005 version of Visual Studio.NET

    GET YOUR EXAMPLE VB CODE HERE!!!!!
    The 101 VB.NET Examples are now located right here, for your downloading pleasure.

    101 VB.NET Examples (for .NET Framework 1.1/VB.NET 2003)

    101 VB.NET Examples (For .NET Framework 2.0/VB.NET 2005)

    VB.NET 9 WPF Samples (For .NET Framework 3.5/VB.NET 2008)
    Last edited by kleinma; Mar 28th, 2009 at 01:43 PM. Reason: updated URLs
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  2. #2

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #1

    Don't cut and paste controls that have event code in them. It removes their handlers which can cause massive headaches.

    For example. If you add a button to a form, put some code in its click event, then cut and paste it back to the form, the code in the click event will no longer work.

    What happens is the code is still there, but it removes the "Handles button1.Click" from the end of the sub since the IDE is using the background compiler.

    You can only imagine what would happen if you had 100 controls on your form and you cut and paste them for some reason (like putting them in a frame or panel)

    Drag the controls instead, they will retain the links to the handlers.

    Tip Contributed by Kleinma
    Last edited by kleinma; Feb 6th, 2006 at 01:02 PM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  3. #3

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #2

    Using the How-To XML Comments sample app in the sticky 101 VB.NET samples, you can add comments to your own classes in your DLLS

    for example, when you are coding and use one of microsofts functions/properties in one of the .net framework classes, each param of the function has a comment tooltip in intellisense that describes it, but when you make your own class, there is no such place to do something like this. With the XML comment sample, you can do this with ease.

    This is very useful when your DLLs will be used by others because it makes them even more self descriptive

    Tip Contributed by Kleinma
    Last edited by kleinma; Feb 6th, 2006 at 01:02 PM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  4. #4

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #3

    Advanced Members

    Some members of classes in the framework are invisible to VB.NET by default. While many may truly be advanced members that you will not likey use, some are common ones (possibly marked advanced in error!)

    In the options menu under text editor -> basic, you can turn on these advanced members.

    SIDE NOTE: These memebers are shown, not hidden by default in C#

    Tip contributed by Trunks

    An original thread on this topic:
    http://www.vbforums.com/showthread.p...hreadid=308399
    Attached Images Attached Images  
    Last edited by kleinma; Oct 31st, 2005 at 10:36 AM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  5. #5

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #4

    ctrl+m+o (ctrl+m then ctrl+o right after)

    Collapses all the regions in the code in the current file.


    ctrl+m+m will collapse/expand the current code block


    alt+E+G (hold alt, hit E and then G)

    Prompts you for a number and then takes you to that line number in the current code file.

    You can also set different settings based on the build type you are in (i.e. Debug, Release, Other). For instance I also change the output folder for release mode so it goes to the actual production location. I also set certain commandline prompts for another that I named DebugWithoutLogon. The app is then set up to bypass logon and set certain test flags so during debugging I don't have to login and do those things every time.

    Tip contributed by
    Edneeis
    and
    NuclearIntern
    Last edited by kleinma; Jul 19th, 2007 at 11:20 AM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  6. #6

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #5

    ctrl+spacebar in the .NET IDE will bring up intellisense wherever you are, this includes the IDE attempting to autocomplete variables you are typing (very good when you have some LONG variable names, or if you just can't remember what you called that variable 4 modules over)


    Tip contributed by Graff
    Attached Images Attached Images  
    Last edited by kleinma; Feb 6th, 2006 at 01:07 PM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  7. #7

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #6

    VB AT THE MOVIES
    Microsoft has a ton of VB movies you can view online that show you how to do various different things with VB.NET.

    What is great about this, is that they show you what they are talking about instead of you just having to read about it. It is the perfect visual aid. You can pick a topic you know little about, and sit back while they give you a short lesson on it.

    VB AT THE MOVIES

    Tip contributed by Ideas Man
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  8. #8

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #7

    WEBCASTS
    The MSDN has webcasts you can load up at any time that give good insight on how to do things in the .NET world.

    While they currently don't have any VB.NET webcasts listed, there are some other ones that are very worthy of taking a look at.

    Such as:
    Object-Oriented Concepts and Best Practices- Level 300
    Patterns for Successful .NET Application Development - Level 200
    Securing Your Data and Applications with Microsoft .NET - Level 300

    also a bunch on ASP.NET

    MSDN WEBCASTS

    Tip contributed by RobDog888
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  9. #9

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #8

    Keyboard IDE launch

    I like this one a lot because I do it myself for many programs that don't need fully qualified paths to run.

    If you want to open the VS.NET IDE you can simply hit
    start -> run -> and type devenv and hit enter

    Tip contributed by Mendhak
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  10. #10

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #9

    FULL SCREEN CODE VIEW

    Alt+Shift+Enter gives you a code only view and maximizes how much code you can see. Use the same key combination to return to normal.

    Tip contributed by VBCrazyCoder
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  11. #11

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #10

    COMMENTS, COMMENTS, AND MORE COMMENTS

    Tip #2 talked about some sample code to create documentation for classes and such that you write in VB.NET

    well here is a link to an addin to Visual Studio.NET that will help to make your documentation as easy as can be. This was written by MS, so no worries about installing it (well no more than the usual MS program )

    Generating Documentation for Your Visual Basic .NET Applications

    Edit: The above link doesn't work so I Goggled the topic and Found this
    Generating Documentation For Your Visual Basic .NET Applications - Hack

    Tip Contributed by Ideas man
    Last edited by Hack; Jan 24th, 2008 at 08:29 AM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  12. #12

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #11

    Installing .NET applications to network drives
    When I first noticed this, it really worried me. If you install a .NET app to a network drive, the exe will not have full trust running in the .net environment (by default). I think this is sort of silly as any mapped network drive should be considered safe (but I guess I do see the point in its existance)

    Well I found an article which talks about an exe called caspol. It is in your framework directory at
    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322

    and it is used to give/takeaway permissions (the same as the "Microsoft .NET Framework 1.1 Configuration" GUI basically in Administrative Tools) but you can run it silently, and run it without end user interaction. This means you can include it as part of your install if the user selected to install to a network drive.

    Giving a Mapped Drive .NET FullTrust

    Tip Contributed by Kleinma
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  13. #13

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Tip #12

    You can use special comments to not only provide commented information, but to also create spots where you know you will need to later reference, either to fix code, write code, or basically anything you want.

    There are some default keywords you can use like HACK, TODO, etc, but you can also create your own.

    They will appear in the tasklist (where build errors appear) and you can filter the list to show them or not show them at any time by right clicking on the list

    Tip Contributed by wild_bill


    Attached Images Attached Images   
    Last edited by kleinma; Oct 31st, 2005 at 10:49 AM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

  14. #14

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,273

    Re: VB.NET Example Code & Hints you may not know

    Since this thread is 10 years old, I have unstuck it. However if you guys want to come up with some more modern tips and tricks, maybe we will start a new sticky.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-
    Share on Google+

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.