MATLAB Excel Builder    

Creating The Visual Basic Form

The next step in the integration process develops a user interface for your add-in using the Visual Basic Editor. Follow the steps outlined here to create a new user form and populate it with the necessary controls.

  1. Right-click on the VBAProject item in the project window and select Insert->UserForm from the pop-up menu.
  2. A new form appears under Forms in the VBA Project. In the form's property page, set the name property to frmFourier and the Caption property to Spectral Analysis.

Figure 4-18: Creating the Visual Basic Form

  1. Now add a series of controls to the blank form to complete the dialog, as summarized in the following table.

    Control Type
    Control Name
    Properties
    Purpose
    Frame
    Frame1
    Caption = Input Data
    Groups all input controls.
    Label
    Label1
    Caption = Input Data:
    Labels the RefEdit for input data.
    RefEdit
    refedtInput

    Selects range for input data.
    Label
    Label2
    Caption = Sampling Interval
    Labels the TextBox for sampling interval.
    CheckBox
    chkPlot
    Caption = Plot time domain Signal and Power Spectral Density
    Plots input data and power spectral density.
    Frame
    Frame2
    Caption = Output Data
    Groups all output controls.
    Label
    Label3
    Caption = Frequency:
    Labels the RefEdit for frequency output.
    RefEdit
    refedtFreq

    Selects output range for frequency points.
    Label
    Label4
    Caption = FFT - Real Part:
    Labels the RefEdit for real part of FFT.
    RefEdit
    refedtReal

    Selects output range for real part of FFT of input data.
    Label
    Label5
    Caption = FFT - Imaginary Part:
    Labels the RefEdit for imaginary part of FFT.
    RefEdit
    refedtImag

    Selects output range for imaginary part of FFT of input data.
    Label
    Label6
    Caption = Power Spectral Density
    Labels the RefEdit for power spectral density.
    RefEdit
    refedtPowSpect

    Selects output range for power spectral density of input data.
    CommandButton
    btnOK
    Caption = OK
    Default = True
    Executes the function and dismisses the dialog
    CommandButton
    btnCancel
    Caption = Cancel
    Cancel = True
    Dismisses the dialog without executing the function.

Figure 4-19, Layout of Controls on Main Form, shows the controls layout on the form.

Figure 4-19: Layout of Controls on Main Form

When the form and controls are complete, right-click on the form and select View Code from the pop-up menu. The following code listing shows the code to implement. Note that this code references the control and variable names listed above. If you have given different names for any of the controls or any global variable, change this code to reflect those differences.


  Integrating the Component with Visual Basic for Applications Adding The Spectral Analysis Menu Item to Excel