Increasing Productivity: Rapid Application Development

In the early days of computer programming, even a simple program could take days or even weeks to complete. When Visual Basic was first introduced in 1991, it revolutionized programming—you no longer needed to write code to create a user interface, and you no longer needed to worry about memory management. This new way of programming was known as Rapid Application Development, or RAD.

The main benefit of RAD programming is increased productivity—Visual Basic 2008 has many features that can help you to create better applications, faster than ever before. The following are a few of those features.

Note

If you are using Visual Basic Express, some of the Help links on this page may be unavailable, depending on the options that you chose during installation. For more information, see Troubleshooting Visual Basic Express.

Code Snippets

One way to increase your productivity is to avoid writing the same code over and over again. Visual Basic 2008 includes a code library of approximately 500 pieces of code, called IntelliSense code snippets, which are ready to be inserted into your application. Each snippet performs a complete programming task, such as creating a file, sending an e-mail message, or drawing a circle. You can insert a snippet into your source code with a few mouse clicks.

Once the snippet has been inserted, the parts of the code that need to be replaced are highlighted; you can enter your own values if you like. For example, a code snippet to draw a line on a form has values for the color, location, and length of the line. You can change these values to meet your needs, or you can do nothing and draw a line using the default values.

You can also create your own snippets that suit your own needs, add them to the library, and then use them when needed. When creating your own snippets, you decide which parts of the code will be highlighted and what the default values are. For more information, see Creating and Using IntelliSense Code Snippets.

One common task that can be accomplished using code snippets is reading and writing text to a file. The following procedure shows how code snippets can make you more productive.

Try It!

To use code snippets

  1. On the File menu, point to New and then click Project.

  2. In the Templates pane, in the New Project dialog box, click Windows Forms Application.

  3. In the Name box, type Snippets and then click OK.

    A new Windows Forms project opens.

  4. Double-click the form to open the Code Editor.

  5. In the Code Editor, put your cursor in the blank line in the Form1_Load event handler, right-click, and then click Insert Snippet.

    A list of snippet categories is displayed.

  6. Double-click Fundamentals - Collections, Data Types, File System, Math.

  7. Double-click File System -Processing Drives, Folders, and Files.

    A list of code snippets is displayed.

  8. Double-click Write Text to a File.

    The following code will be inserted, and "C:\Test.txt" and "Text" will be highlighted.

    My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Text", True)
    

    Note

    The WriteAllText method will create the file if it doesn't exist. If it already exists, it will add the text at the end of the file.

  9. Replace "C:\Test.txt" with "C:\MySnippetTest.txt", and replace "Text" with "This is really fast!".

  10. Add a second snippet by right-clicking and clicking Insert Snippet.

  11. Double-click Fundamentals - Collections, Data Types, File System, Math.

  12. Double-click File System -Processing Drives, Folders, and Files.

  13. Double-click Read Text from a File.

    The following code will be inserted, and "C:\Test.txt" will be highlighted.

    Dim fileContents As String
    fileContents = My.Computer.FileSystem.ReadAllText("C:\Test.txt")
    
  14. Replace "C:\Test.txt" with "C:\MySnippetTest.txt".

  15. Add the following code below the last snippet to display the result.

    MsgBox(fileContents)
    
  16. Press F5 to run the program.

    A file is created containing the text you specified, and a message box is displayed with the contents of the file.

Take some time to familiarize yourself with the code snippets included in Visual Basic—they can save you a lot of time and wasted effort when writing code. For more information, see How to: Manage Code Snippets.

Development with My

Another RAD feature in Visual Basic is called My. My is a set of objects that contain commonly used functions related to the computer, the application, the user, and so forth. You can think of My as a speed-dial to get to functions that would otherwise require a lot of extra code.

For example, suppose that you want to determine the version number of your application. In the previous version of Visual Basic, the code would have looked like the following.

Dim VersionNumber As String
VersionNumber = System.Diagnostics.FileVersionInfo.GetVersionInfo _ (System.Reflection.Assembly.GetExecutingAssembly.Location).FileVersion

Using the new My.Application object, it looks like this.

Dim VersionNumber As String
VersionNumber = My.Application.Info.Version.ToString

As you can see, the My way is much simpler (and much easier to discover), saving you time and effort. You could still use the other way of determining the version number, by why would you?

Although you may not have noticed, you have already used My in a number of earlier lessons. As you enter code for your next application, explore the My objects by typing My and looking through the list of items that appears. For more information, see Development with My.

IntelliSense

As you have worked through the lessons and entered code, you probably noticed that as you type, a drop-down list of choices appears in the Code Editor. This is one example of the feature known as IntelliSense.

IntelliSense provides a number of features that make language references easily accessible. When writing code, you do not need to leave the Code Editor to get information about language elements. You can stay where you are, find the information you need, insert language elements directly into your code, and even have IntelliSense complete your typing for you.

IntelliSense is also helpful when you are debugging. In the Code Editor, you can move the cursor over a variable in your code to display a ToolTip with the current value of the variable. IntelliSense is also available when you are entering code in the Immediate window. For more information, see Using IntelliSense.

Next Steps

In this lesson, you learned about some of the productivity features in Visual Basic. There are many other features that help to make Visual Basic the best tool for rapid application development; links to a few of them are listed below.

In the next lesson you will learn about some of the more surprising things that you can do with Visual Basic 2008.

Next Lesson: Tips and Tricks: I Didn't Know I Could Do That.

See Also

Concepts

Moving Forward: Where Do I Go from Here?

How Do I in Visual Basic Express

Other Resources

Distributing a Program

Visual Basic Guided Tour