Multiple Classes in a Visual Basic Component

To create the component for this example, see the first few steps of the Multiple Classes in a .NET Component. Then create a Microsoft® Visual Basic® application as follows:

  1. Review the sample application for this example in matlabroot\toolbox\dotnetbuilder\Examples\VSVersion\NET\SpectraExample\SpectraVBApp\SpectraApp.vb.

    The program listing is shown here.

     SpectraApp.vb

    The program does the following:

    • Constructs an input array with values representing a random signal with two sinusoids at 15 and 40 Hz embedded inside of it

    • Uses MWNumericArray to handle data conversion

      Note

      For information about these data conversion classes, see the MATLAB MWArray Class Library Reference, available in the matlabroot\help\dotnetbuilder\MWArrayAPI folder, where matlabroot represents your MATLAB® installation folder

    • Instantiates a SignalAnalyzer object

    • Calls the computefft method, which computes the FFT, frequency, and the spectral density

    • Instantiates a Plotter object

    • Calls the plotfft method, which plots the data

    • Uses a try/catch block to handle exceptions

    The following statements

    Dim data As MWNumericArray = New MWNumericArray_
        (MWArrayComplexity.Real, MWNumericType.Double, numSamples)
    ...
    Dim resultArray As MWNumericArray = New MWNumericArray_
        (MWArrayComplexity.Complex, 
         MWNumericType.Double, numElements)
    

    show how to use the MWArray class library to construct the necessary data types.

    The following statement

    Dim signalAnalyzer As SignalAnalyzer = New SignalAnalyzer

    creates an instance of the class SignalAnalyzer, and the following statement

    Dim argsOut() As MWArray = 
        signalAnalyzer.computefft(3, data, 
            MWArray.op_Implicit(interval))

    calls the method computefft and request three outputs.

  2. Build the SpectraApp application using Visual Studio® .NET.

    1. The SpectraVBApp folder contains a Visual Studio .NET project file for this example. Open the project in Visual Studio .NET by double-clicking SpectraVBApp.vbproj in Windows® Explorer. You can also open it from the desktop by right-clicking SpectraVBApp.vbproj > Open Outside MATLAB.

    2. Add a reference to the MWArray component, which is matlabroot\toolbox\dotnetbuilder\bin\architecture\framework_version\mwarray.dll.

    3. If necessary, add (or update the location of) a reference to the SpectraComp component which you built in a previous step. (The component, SpectraComp.dll, is in the \SpectraExample\SpectraComp\x86\V2.0\Debug\distrib subfolder of your work area.)

  3. Build and run the application in Visual Studio .NET.