VB 2005: Building applications in VS 2005 IDE

Build Configurations

New in VS 2005 IDE is the ability to choose which build configuration you want to use to build your applications.  You can create your own build configuration besides the Debug and Release build configuration that VS 2005 IDE already provides.

To choose which build configuration you want, you need to display the settings first by going to Tools -> Options… -> Projects and Solutions -> General and checking the Show advanced build configurations checkbox.  Then go to your project’s properties by right-clicking your project and selecting Properties and clicking the Compile tab.  From there you can see the Configuration drop-down listbox where you can choose which build configuration you want and you can also change the settings associated to that build configuration like the Build output path, Option explicit, Option strict, etc.  You can also click the Advanced Compile Options… button for more advanced compiler settings.

To add a new build configuration or include/exclude projects from your build configuration if you are working on a solution with multiple projects, go to the  Build menu and select Configuration Manager….

Building and Debugging Applications

To build your application, you can use Build or Rebuild just like in the old versions of Visual Studio.  During debugging, you have the Output, Call Stack, Breakpoints, Locals, and Watch windows to use to help you in your debugging efforts.  There is this another window, the Autos window, that automatically displays the variables used in the statement currently being executed and the statement just before it.

Other Useful Features

Task List not only tracks errors when building your applications but you can also use this to keep track of your TODO comments in your source code and user-entered tasks as well.  To be able to track comments in your source code, you need to create a standard comment with the apostrophe and begin your comment with TODO, just like this:

    ' TODO: Put your code here...

Then on your Task List window, if you double-click a comment task, you will be directed to the source code where the comment is, pretty neat huh?  You can open your Task List window by going to View -> Other Windows -> Task List.

The Command window is useful especially if it’s in immediate mode.  It is like the Immediate window we are used to in Visual Basic 6.  The immediate mode is accessed by typing immed in the command prompt > and pressing ENTER.  To return to the command mode, type cmd and press ENTER.

Server Explorer, as the name suggests, explores resources available on the server.  By default it inspects resources on the local machine.  You can also add a server for the Server Explorer to inspect.  Resources like SQL Server databases, event logs, registry, and message queues are just among the resources inspected by Server Explorer.

Macros

If you have programmed in Excel and used it’s macro recording facility, you will find it similar in Visual Studio 2005 as well.  You start recording by going to Tools -> Macros -> Record TemporaryMacro.  A floating toolbar will appear to let you pause, stop, or cancel your recording.  Once finished you can view or edit your macro by going to Tools -> Macros -> Macro Explorer.  Now why would you want to use a macro?  Well this is useful if you have a code that you use frequently and by using a macro it can save you from typing the code.  Plus you can transfer the macro-generated code to a Visual Studio Add-In project so you can share it with others.  Another one of those cool features.

VB 2005: The Global keyword

I was looking at the code generated by Visual Studio and I encounter this Global keyword.  Found out that you use this when you want to start the qualification chain at the outermost level of the .NET Framework class library, e.g.:

    Global.System.Int32

This is useful if you are in a situation where you have defined a namespace in your code nested in another namespace (e.g. MyNamespace.System) and you have a System.Int32 declaration inside.

VB 2005: Putting XML comments to your source code

A new feature in Visual Studio 2005 is the ability to add XML comments to your procedures and functions and even classes, which can be picked up by Visual Studio’s IntelliSense besides providing means to generate documentation and help files for the source code. 

To add the XML comments, type 3 single quotes (”’) to the line before the procedure or function and Visual Studio will add the following block of comments:

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>

What you have now is a template where you can enter your description and parameters for the procedure or function you want to document or comment on.

You will find an XML file containing all the XML comments in your project directory when you compiled your project.  You can use this to generate the documentation and help files.

VB 2005: Code generation in Visual Studio 2005

Visual Studio 2005 generates some code for us when we create our projects.  Code generated by this tool can be found in a separate file with .Designer.vb extension.  The code we make are saved in a file with .vb extension only.  This is possible with the use of partial class.

Let’s take an example, say Form1.vb.  Code generated by Visual Studio 2005 is in Form1.Designer.vb.  Inside this file you will see your Form1 class being declared as a partial class and being inherited from System.Windows.Forms.Form.  One of it’s method is InitializeComponent() which is where all initializations and custom settings of properties of the form and the controls that you put on the form are generated.  So if you’ve set the Text property of your Form1 to something else, say My Form on the form’s Properties window, you will see this property being set inside the InitializeComponent() method.  Also if you added a button control on the form, you will also see initialization code for this button as well:

    Me.Button1 = New System.Windows.Forms.Button
    Me.SuspendLayout()
    '
    'Button1
    '
    Me.Button1.Location = New System.Drawing.Point(116, 150)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(75, 23)
    Me.Button1.TabIndex = 0
    Me.Button1.Text = "Button1"
    Me.Button1.UseVisualStyleBackColor = True
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.Controls.Add(Me.Button1)
    Me.Name = "Form1"
    Me.Text = "My Form"
    Me.ResumeLayout(False)

Note that Button1 is declared outside the InitializeComponent() method but inside the Form1 class as:

    Friend WithEvents Button1 As System.Windows.Forms.Button 

It’s cool that we can view the generated code and this will actually help us understand more what’s involved in let’s say, creating a form and adding a button control on the form.

VB 2005: Things to know about the Visual Studio 2005 IDE

When you first started your Visual Studio 2005 you were asked to specify the default settings and I set mine to Visual Basic Development Settings.  If you want to change this setting, say to Visual C# Development Settings, you need to go to Tools -> Import and Export Settings… and go through the wizard to change it.

When you go create a new project, one of the project templates that you can select is Database.  This project template lets you create classes that can run inside SQL Server 2005.  Note that there is another project template of the same name under the Other Project Types option.  They are not the same.

If you have used a previous Microsoft development tool (e.g. Visual Studio 6.0), you will notice that the Solution Explorer is similar to the project group, except that it can contain projects of any .NET language and may include database, testing, and installation projects as part of the overall solution.

Application settings are now stored in an XML file named app.config but when you create a new project, it does not create one by default.  Since this app.config file is stored in the application directory, you can run different versions of your application without encountering problems that you usually get if the settings were stored in the Windows Registry.

When you get to the Assembly Information screen (by double-clicking the My Project on the Solution Explorer and on the Application tab display, clicking the Assembly Information… button), you will notice the GUID attribute there.  The value of that attribute is used as the ID of the type library that will be created when the assembly is made visible to COM applications (the checkbox Make assembly COM-Visible is checked).

A new feature in the code window is outlining.  You will notice a + or sign on the left side of your code window.  This allows you to hide or show portions of your code.  If you don’t like this feature you can disable it by selecting Edit -> Outlining -> Stop Outlining.  To bring outlining back, select Edit -> Outlining -> Collapse to Definitions

There is also this #Region directive that allows you to hide regions of code.  The code should be enclosed with #Region at top and #End Region at the end.  There should be a description after the #Region keyword which will be shown when this region of code is collapsed.  Example of code enclosed with the #Region directive:

    #Region "My region of code"
    Private Sub mySub()
        ' ...
    End Sub
    #End Region

You’ll notice in the Visual Studio 2005 IDE, that all the files that you are working on are in tabbed layout unlike in previous versions of Visual Studio, they are in MDI layout.  If you prefer the MDI layout, just go to Tools -> Options and under the Environment -> General category, on the Window layout section, select Multiple documents.

Tools -> Options is the place to customize your IDE.  It has customizations for your text editor like line numbering which if you turn it on will number all your lines of code.

You might also want to use the Dynamic Help feature in the IDE.  To show this window, select Help -> Dynamic Help or press Ctrl+Alt+F4.  This feature tries to guess what you are trying to do and shows a list of things that you might be interested in looking at.