Getting Help (Quick Tour of the IDE) (AutoCAD VBA)

The online Help facility is another indispensable feature of the IDE—not only does it offer you a helpful explanation about many topics, but it often gives some sample code, too. You can copy this sample code and run it from the IDE. While you are building your expertise in Visual Basic, it is often useful to see how a method or property is actually put to work in coding statements. You may even be lucky enough to find a sample that you can use as the basis of a macro.

You’re probably familiar with using the Help facility in AutoCAD. Well, the IDE’s Help works exactly the same. The following steps show you how to copy and run the sample code for generating a random number from the IDE’s Help facility:

1.    Open the IDE and choose Help ^ Microsoft Visual Basic Help. The Help window shown in Figure 3.12 appears.

2.    As shown in Figure 3.12, enter the text randomi into the box labeled “Type the first few letters of the word you’re looking for.” As you type, watch the scrolling list of index entries in the large window. It rolls up to match the string you’ve entered so far.

After you type the last letter (i), the Randomize Statement topic will be highlighted in the list box.

3.  Click the Display button. The Visual Basic Reference window shown in Figure 3.13 appears, containing helpful information about the Randomize statement.


The Index tab from the IDE's online Help facility

Figure 3.12 The Index tab from the IDE’s online Help facility

Then click the Example link near the top-center of the reference window, and you’ll see the sample code shown in the inset of Figure 3.13.

The inset shows a code example for Randomize statement after you click Example link.

Figure 3.13 The inset shows a code example for Randomize statement after you click Example link.

4. Right-click anywhere in the Visual Basic Example window to display this pop-up menu:

tmp757e-111_thumb

5.    Choose Select All to highlight all the text. Right-click again and choose Copy from the pop-up menu. The content of the Example window is copied to the Clipboard.

6.    Open the IDE, choose Insert ^ Module, then choose Edit ^ Paste. The Code window for Module1 opens, and all the text from the Example window is pasted into it.

7.    Replace the text above the Dim statement with the name of your procedure; I’ve called mine RandomNumberGenerator, as shown in Figure 3.14. Notice I’ve also used the Edit ^ Indent command to indent my code.

8.    Add End Sub at the end, as shown in Figure 3.14.

9.    With the insertion point somewhere in the End Sub statement, choose Debug ^ Toggle Breakpoint. End Sub is highlighted, and a black circle with an arrowhead in it appears in the gray margin on the left.

10.    Choose Run ^ Run Sub/UserForm and pause the mouse cursor over MyValue.

The code is executed up to the breakpoint, and the pop-up ToolTip displays a value, as shown in Figure 3.14. The value is chosen at random every time the procedure is run.

Procedure name and End Sub statement have been added, shown here with the pop-up ToolTip giving the random value assigned to MyValue.

Figure 3.14 Procedure name and End Sub statement have been added, shown here with the pop-up ToolTip giving the random value assigned to MyValue.

Context-Sensitive Help

You can get immediate context-sensitive help by making an item in the IDE window active, and pressing the F1 function key. This opens the Help page for that topic if there is one. For example,highlight the Visual Basic word Dim and press F1 to open the Help window giving information about the Dim statement.

If you are a seasoned AutoCAD user, you’ll know that the F1 key was originally used to view the full text window in AutoCAD. This was changed to F2 in AutoCAD 2000 and later versions, in order to conform to the Windows pseudo-standard of reserving F1 for viewing the Help facility.

Summary

After your quick tour of IDE in this topic, you know how to use the IDE’s features to do the following:

•    Identify the components that make up the IDE.

•    Display the Project Explorer window.

•    Position and size Toolbox controls on a UserForm.

•    Format several controls placed on a UserForm simultaneously.

•    Print the graphical representation of a UserForm.

•    Use the IDE’s commands for running code.

•    Set the options in the Editor tab of Tools + Options.

•    Access the online Help facility.

•    Copy and run sample code on a specific topic from the online Help facility.

Next post:

Previous post: