Save Custom Functions from Excel VBA in Add-in Files
How to Edit Macros in Excel's Visual Basic Editor
Shortcut Keys to Debug Code in VBA 2007

Working with Code in Visual Basic 2008

Of the programs you create with Visual Studio, most of what you want the user to see are the controls and the forms. But you will be spending most of your time working with code. Fortunately, Visual Studio has a ton of tools to help you write code.

Getting to Code View

Code View, like Design View or Diagram View, is just another way to look at a file in the Solution Explorer. To get to Code View, you have several choices:

  • You can right-click a form in the Solution Explorer or in Design View and select View Code from the context-sensitive menu.
  • You can click the View Code button in the Solution Explorer.
  • You can double-click an object in a form.

When you're working in Code View, most of the tool windows becomes inactive. The Toolbox and Properties windows, for instance, have little available because their features are designed for use with the Design View rather than the Code View. This is by design, to keep the code out of your way when building business logic.

Using IntelliSense

The problem with using Code View is that you need to know what to type. Welcome to programming! To help you get started, you can use some very productive code-based tools, such as IntelliSense.

Just to see how great IntelliSense is, check this out. Get started with these steps:

1. In the default project, double-click the blank Form1 to move to Code View.

2. Start to type My. in the Form1_Load method. (Just press M on the keyboard, and you can see what I mean).

A special context-sensitive menu (the IntelliSense menu) appears when you start typing. This menu shows the code that is available to you. It guesses what you need based on what you are doing — in this case, it doesn't have much to work with so it started with the MID method.

Finish typing 'My.' and you will get all the available methods, properties, and events in the My object. It's a great way to remember the best way to get things done.

You can continue to use IntelliSense menus as long as Visual Studio thinks there are more types after the selected object. For instance, double-click Application in the context-sensitive menu and then type . (period). You see another IntelliSense menu.

Reading the documentation

In the case of Visual Studio, there is so much power in the documentation model that it deserves a little space of its own. The most straightforward use of the documentation requires little more than clicking on or in the object that you have a question about and pressing F1 to launch context-sensitive Help.

For instance, in any application, click somewhere on the form (make sure that you click the form and not an object on the form) and press F1. The Microsoft Document Explorer launches with the Form object documentation loaded.

The Document Explorer has a sophisticated set of tools, mostly represented in the Document Explorer toolbar. The tools you find there give you various ways to access the documentation, as follows:

  • The toolbar's first section has navigation buttons, a Refresh button, and font size maintenance.
  • The How Do I button has preset questions that relate to the selected topic, and may help with general queries about certain types of development; if you are stuck, give it a try.
  • Clicking the Search button allows phrase searching. The Index button and Contents button allow browsing through the index or table of contents of the documentation. You can save favorites in the Help Favorites just like you can in Internet Explorer. The double arrow is handy — it synchronizes the Contents panel with the page you are currently viewing.
  • The Ask a Question button takes you directly to the NNTP newsgroups (using a Web-based viewer) hosted by Microsoft, where you can ask questions and have them answered by Microsoft MVPs, authors, and other experts.

And don't overlook the online tools provided by Microsoft. Choose Help --> Technical Support to access a wealth of information available on the Web, right from inside Visual Studio.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Understanding VBA Functions and Their Uses
Organizing Your Project with the Solution Explorer
Touring the Design View of Visual Basic 2008
Visual Studio 2010 All-in-One For Dummies Cheat Sheet
Visual Basic .NET Data Types
Advertisement

Inside Dummies.com