Understated Features of the Code Window

The code window will be your primary focus when you are programming with VBA. I've already discussed numerous ways in which you can customize this window. Now you'll look at it and I'll discuss the different ways in which you might work with it. An example of the code window is shown in Figure 2.10.

The drop-down list at the upper left is known as the Object list. This list contains any objects associated with the code window. For a standard module, (General) is the only item. However, a User Form will have an entry for each control or element on the form. The drop-down list at the upper right is known as the Procedure list. It lists all of the procedures associated with the object selected in the Object list. As you select different elements in each list, the code window displays the appropriate procedure.

UNDERSTATED FEATURES OF THE CODE WINDOW 23

Figure 2.10

The code window looks rather sparse initially, but its subtle features can help facilitate the development process.

Margin ■ Indicator Bar

Event/Procedure List Split Bar

Event/Procedure List Split Bar

/ \ Procedure View Full Module View

The code window also has a split bar (see Figure 2.11). You can drag the split bar down the window to create two independent views. Just drag and drop the split bar to where you want the split to appear. If I were a betting man, I would bet that in the initial stages of your development as a programmer, as soon as you start writing any procedures of significance, these procedures will be very long, perhaps requiring two or three windows to display a procedure in its entirety. As you go through this stage, you may find that the split bar is a convenient way to view a critical piece of the procedure while you are working on a related critical piece as opposed to scrolling up and down repeatedly.

The split bar also allows you to view two procedures at once if you are not using the Procedure view (described momentarily). You can use the Page Up/Page Down keys to toggle among the various procedures in your module.

Figure 2.11

The split bar can save you time by eliminating the need to scroll back and forth in a long procedure.

; Chapter 2 Fxamples.xls - Module! (Code)

g mm

1 J (General)

jrj 1 Aiito0.ït<Vri|>s

-31

Sub SuperLongProcedure() Dim x As Integer Dim y Integer Dim s As String Dim to As String Dim cl As Double Dim a As String

i

a =

"a"

jj

For x ■ 1 To 100 F = v + 1 s = s s "a" A = d - 1 Debug.Print sib b = a s y Next x

a 1

In the "Turn On All of the Code Settings" section, we discussed the use of the Default to Full Module View option. You can easily toggle between full module view and procedure view by clicking the appropriate icon in the lower-left corner of the code window. By using the split bar in conjunction with the Procedure view, you can see more than one procedure at a time using this feature. If you use the split bar with the Procedure view, the drop-down list box selections apply to whatever pane the cursor is in.

0 0

Post a comment