Figure out how to really use your Visual Studio development environment to the max with this ace collection of secrets. From your quick guide to upgrading, COM and the API, to the tricks behind the VS .NET Command window, from a little-known place you can store often-used code to how you can tell if you re running in the IDE ”and much more.
The Task window in VB .NET is a great way of keeping track of tasks that are related to your project. For example, if you have code issues or compile errors, VB .NET will automatically list them here.
You can also add your own comments to the Task list, with the TODO keyword. To use this feature, simply add a comment to your code that starts with the TODO keyword. It will automatically be added to your existing Task list. For example:
' TODO: Rewrite function so works with .DOC files
To view the Task list, select View Other Windows Task List from the menu, or press Ctrl+Alt+K . The Task list often filters its contents, so it displays only certain information. To view everything, right-click on your list and select All Tasks All. (See Figure 7-17.)
|TOP TIP|| |
Fed up with the TODO keyword? Users of Visual Studio .NET 2003 (Everett) have automatic support for the HACK prefix, which works in the exact same way as TODO yet attracts much more kudos. You can edit the Task list keywords yourself by editing the values in Tools Options Environment Task List.
There s an easy way to store often-used code and templates in VS .NET. Simply drag and drop your code straight onto one of the toolbox tabs, such as the General tab. (See Figure 7-18.) When you need to use it again, simply drag and drop back into your code window. And, best of all, these snippets persist from project to project, saving even more development time.
Overwhelmed with the number of files that now make up your application? Starting to loose track of which VB files do what? Well, there s a simple method of keeping track. Use folders!
Right-click on your project in the Solution Explorer and select Add New Folder. Then simply drag and drop your existing code files into the new folders. For example, you may have one folder called User Interface to store your forms, or a folder called Database Code to store your data access classes.
Don t worry: there s no extra configuration required, and your entire project compiles as normal with no extra effort. It simply allows you to organize your project the way it should be.
A simple tip, but one that can turn chaos into control within minutes. (See Figure 7-19.)
The Command window in Visual Studio .NET allows you to both perform command operations as well as evaluate statements (see Figure 7-20), depending on its mode. To open the Command window, select View Other Windows Command Window from the menu, or press Ctrl+Alt+A .
The Command mode allows you to access common Visual Studio .NET commands. To enter this mode, type > cmd into the window and press the Enter key. After this, you can access the various menu commands by typing them directly into this window (for example, Window.CloseAllDocuments to close all current documents). Type alias for a full list of alias shortcuts (for example, CloseAll ).
The more-useful Immediate mode is used for evaluating and executing statements while your code is paused at runtime. To enter this mode, type immed into the window and press Enter. After this, you can use the window to run commands, set variables , or read values (for example, MyVariable = "Etc" or ? MyVariable ). Visual Studio .NET 2003 users also get the popup properties/ methods list, allowing them to browse an object.
Press the F1 key while inside the Command window for more information on the commands available.
Previous versions of Visual Basic made it easy to figure out whether you were running your application through the IDE (Integrated Development Environment). It simply allowed you to check which mode your application was in. VB .NET, however, isn t quite as easy going.
The most common method of figuring out whether the application is running in the .NET IDE is to check the System.Diagnostics.Debugger.IsAttached property to determine whether if a debugger is attached to the currently executing code. If so, you can safely assume your code is running from within the IDE.
If you re designing your own controls, you might also run into the situation where your code is running in design mode ”while you want it to execute only during full runtime. In this situation, simply check the DesignMode property of your component (that is, from inside your control: Me.DesignMode ). If it returns True , you re running in the IDE ”so cut your code short.
Simple solutions to common questions, and definitely worth remembering.
If you have a repetitive task that you often perform in the Visual Studio .NET development environment, you might want to consider creating it as a macro and running it when you require that functionality once more.
For example, you might create a macro to print all the open documents, add customized revision markers, change project properties to standardize your development, or insert common routines.
You can get highly in-depth with macros, writing code to perform almost any task. However, the simplest method is to simply record your activities and have Visual Studio .NET write the code for you. You can do this by selecting Tools Macros Record TemporaryMacro. To play it back, select Run TemporaryMacro from the same menu, or press Ctrl+Shift+P .
For more information on recording macros, look up macros, recording in the help index. For more information on macros in general, look up macros, Visual Studio .NET in the help index.
As you work through the Visual Studio .NET documentation, you ll start to realize just how many tools require you to run them from the command line for full control.
However, setting the proper directory and locating the exact EXE file required via the command prompt can prove troublesome . Thankfully, Visual Studio .NET comes with a feature that automatically sets up a command prompt with all the correct environment variables ready for you to use.
To access this, select Start Programs Microsoft Visual Studio .NET Visual Studio .NET Tools Visual Studio .NET Command Prompt. (See Figure 7-21.) Task complete!
Most books like to dedicate a good couple of chapters to moving from the old school of Visual Basic 6 programming. This one is different, of course. In the interest of saving your time and cutting all those excess pages, I m going to chop it all down to just three simple paragraphs ”one dedicated to each of the main topics: upgrading, COM, and the API.
First, upgrading. Yes, you can do it; simply open your existing Visual Basic 6 project in VS .NET, and an upgrade wizard will pop up and do its darned hardest to move your code to .NET. Most of the time it simply alters your functions so they use those in the rather uncool Microsoft.VisualBasic namespace, implemented in the .NET Framework to allow VB6 people to upgrade without feeling lost. On the whole, I d recommend only fresh development work be undertaken in .NET: simple ports like this never really work or are done for all the wrong reasons.
Second, COM. Frankly, it s just too big to die. If you want to use a COM DLL/EXE in your application (for automating Word, say), click on Project, Add Reference, and select your item through the COM tab, then click OK. If you want to use a COM control, right-click on the toolbox, select Customize Toolbox, check a COM component, and click on OK. Note that you may experience a slight performance knock due to .NET having to interoperate with the world of COM, but on the whole things should work pretty much the same as they did before. Also, if you want COM-supporting languages to see your .NET widgets, that s possible too. Look up exposing .NET Framework components to COM in the help index for more information.
Finally, the Windows API. Although it s still available on Windows machines, Microsoft is trying to drag everyone into the .NET Framework, which allows you to write managed code, with resources monitored and allocated for you automatically. It also fits in with the long- term Microsoft vision of a sort of platform-independent programming language (that is, one based on a framework, not Windows). You can, however, still call the API directly with ease (as demonstrated in the INI Files Will Never Die: How to in .NET tip earlier in this chapter). You can read more about this by looking up Windows API, calling in the help index. Still, if possible, I d recommend that you figure out a .NET alternative to the API; either search the newsgroups at www.googlegroups.com or check out the .NET section of www.allapi.net, a Web site listing API functions and their related .NET equivalents. (Although the site has unfortunately stopped updating its pages, it still serves as a highly useful reference.)