Results 1 to 17 of 17

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

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 02:02 PM.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 02:02 PM.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 11:36 AM.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 02:07 PM.

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  11. #11

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 09:29 AM.

  12. #12

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  13. #13

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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 11:49 AM.

  14. #14

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Tip #13

    Be very careful when uninstalling any of the Visual Studio 2005 BETA editions to either install a newer beta, or to just remove it completely from your system.

    Important Information About Uninstalling VS 2005 Betas, along with uninstaller utility

    Tip Contributed Painfully by Wokawidget
    Last edited by kleinma; Feb 6th, 2006 at 01:52 PM.

  15. #15

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Tip #14

    Put that BIN in the project

    Often times you will put files in your bin folder when working on a windows forms app because the bin folder is where the compiled exe goes. If you wanted to have a textfile read in by your app, and is supposed to be in the same directory as your app, you would place it in the bin directory. Likewise if your app wrote to a textfile that was in its own directory.

    Here is a cool little trick that can save you some time if you frequently visit your bin folder for one reason or another.

    In the Solution Explorer, many of the files/folders that are not considered "crucial" to your project are not shown even though they exist in the actual file structure of the solution on your hard drive. There is a button you can click that will show these hidden files (see picture). Once you click that button, the files/folders will appear, although slightly faded out to show you they are hidden. If you right click on a folder, you can select "Include in Project" which will add that item to your Solution Explorer as if it was any other file that was already there. If you do this for a file that was in a folder, it will add the folder as well.

    As you can see this can be used for many different situaitons, but the one I personally have been using it for, is to show my bin folder as part of the Solution Explorer, so I can access items in it easily. If your app writes an XML file, you can easily double click it right from the solution explorer and view/edit the xml file right in the IDE's text editor.

    Tip Contributed by Kleinma
    Attached Images Attached Images  

  16. #16

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Tip #15

    Comment Keyboard Shortcuts

    Comment blocks are great to comment/uncomment a whole section of code easily in VB.

    Once you know the shortcut keys for doing so, it is even easier, as you don't even have to reach for the mouse.

    Ctrl + K + C = Comment Block the currently selected code
    Ctrl + K + U = Uncomment Block the currently selected code

    Tip Contributed By Joacim Andersson

  17. #17

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

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