Building a Visual Basic 2008 application with BasicDSP and ZedGraph


Step 1. Create a new Basic application

  • Start Microsoft Visual Basic 2008 Express Edition
  • Select "File | New Project", then "Windows Forms Application" and a name of "TestSine".

  • When the forms designer opens, select "File | Save All", then save the project to its own folder.


Step 2. Downloading BasicDSP and ZedGraph DLLs

If you have not done so already, download the BasicDSP and ZedGraph DLLs. You can download them into the folder where the TestSine project is stored, or to another place. Here are the links again:

Right click on the links above, and choose "Save Link As" to copy to the destination folder.


Step 3. Add ZedGraph to the Toolbox

If you have not done so already, add the ZedGraph control to the IDE Toolbox, as follows:

  • Select "Tools | Choose Toolbox Items". This displays a dialogue where you can add components to the Toolbox.
  • Select the "NET Framework Components" tab, and click on "Browse". Navigate to the folder where the ZedGraph.DLL file was saved, and select it.

  • Close down the "Choose Toolbox Items" dialogue by clicking "OK".


Step 4. Add a ZedGraph control to your form

  • Display the Form for your application in the Forms Designer.
  • Find the ZedGraph control in the Toolbox and drag a copy to the form.
  • In the Properties explorer, make these changes:
    1. Set the "Name" property to "zgc"
    2. Set the "Dock" property to "Fill"


Step 5. Add the Visual Basic code

  • Display the Visual Basic code for the application in the Code Editor (Click on View Code in the Solution Explorer).
  • Type in (or cut and paste) the following VB code:
    Imports BasicDSP
    Imports ZedGraph
    Public Class Form1
        Const NUMSAMPLE As Integer = 44100      ' number of samples
        Const SAMPRATE As Double = 44100.0      ' sampling rate
        Const SINEFREQ As Double = 500.0        ' sine at 500Hz
        Const SINEAMP As Double = 10000.0       ' sine amplitude
        Dim wv As Signal
        Private Sub TestSine_Load(ByVal sender As System.Object, _
        				ByVal e As System.EventArgs) Handles MyBase.Load
            wv = New Signal(NUMSAMPLE, SAMPRATE)
            For i As Integer = 1 To NUMSAMPLE
                wv(i) = BasicDSP.Sample.Sine(SINEFREQ, SINEAMP, 0, i / SAMPRATE)
            Next
            Dim gp As New Graph(Me.CreateGraphics, zgc)
            gp.PlotSignal(1, wv.Cut(1, SAMPRATE / 100), "TestSine")
        End Sub
        Private Sub zgc_Click(ByVal sender As Object, _
        				ByVal e As System.EventArgs) Handles zgc.Click
            wv.Replay()
        End Sub
    End Class
    
  • You will get errors caused by the fact that the BasicDSP library has not yet been referenced.


Step 6. Add a reference to the BasicDSP library

  • Open the Project Properties screen by double clicking on "My Project" in the Solution Explorer:

  • On the "References" tab, click "Add".
  • In the Add Reference Dialogue, choose the "Browse" Tab and navigate to the folder where you saved BasicDSP.DLL

  • Select the "BasicDSP.DLL" file and click OK.

  • Return to the Code Editor window and you should see that the referencing errors have disappeared.


Step 7. Run the program

  • Select "Debug | Start Debugging".
  • You should see the sine wave graph displayed in the form:

  • To replay the sinewave, click on the graph.
  • If clicking on the graph causes a "LoaderLock exception", then you need to disable the detection of this exception.
  • Stop debugging.
  • Select "Debug | Exceptions" which displays the "Exceptions" dialogue.
  • Open the "Managed Debugging Assistants" list and deselect the "Loader Lock" exception.

  • You should now find that clicking on the graph replays the tone without raising an exception.


That's it! Happy exploration with your own code.

 

Mark Huckvale - January 2010

University College London - Gower Street - London - WC1E 6BT - Telephone: +44 (0)20 7679 2000 - Copyright © 1999-2013 UCL