Coding a VBA Program

Other topics about Operation Basics

Overview

This section provides descriptive information on the user interface elements of a code window that lets you code a VBA program, and walks through a sample program (procedure) that finds the maximum value contained in an array so you can gain insight into how to create your own programs.

User Interface Elements of a Code Window

A code window is where you code a VBA program. When you are working with a user form, you can open the code window for that user form by double-clicking a control (such as a button or text box) placed on the form. Similarly, when you are working with a standard or class module, you can open the code window associated with that module by double-clicking the module's icon in Project Explorer.

Code window for a standard module

1. Object box

Provides a list of objects currently used within the code window.

2. Procedure box

Provides a list of procedures that reside within the code window. When you are working with a user form, this provides a list of events (actions such as click or double-click).

3. Margin indicator bar

Primarily intended for use when debugging a program.

4. Show Procedure button

Displays only the procedure at the cursor position.

5. Show Module button

Displays the entire program contained in the code window.

Creating a Simple VBA Program

The following figure shows a simple sample program.  This program allows you to select the measurement parameter from S11, S21, S22 and S12.

When you run this program, the following dialog box is displayed and you can change measurement parameter by selecting parameter from combo box. Clicking the exit button quit the program.

 

Auto-complete Feature

When you use COM objects in Visual Basic Editor, the editor's auto-complete feature allows you to easily type in keywords without misspelling them.

The following procedure assumes that you are entering the SCPI.INITiate(Ch).CONTinuous object.

  1. In a standard module, type sub main and press the Enter key. End Sub is automatically added.

  2. Typing scpi followed by a dot (.) brings up a list of classes under the SCPI class.

  3. Typing in automatically moves focus to INITiate in the list box.

  4. Typing ( brings up a list of indexes.

  5.  Typing 1). brings up a list of classes under the INITiate class.

  6.  Typing c automatically moves focus to CONTinuous in the list box.

  7. Typing = brings up a list box for setting a Boolean value (True/False).

  8. Typing t automatically moves focus to True.

  9. Pressing the Enter key completes the statement: SCPI.INITiate(1).CONTinuous = True.