Sample GraphiC for Visual Basic Code:

Below is a copy of a simple Basic program which generates an array of 300 data points and uses GraphiC to create a linear plot. The subroutine Sample() would be called as a result of some action by the user from a Visual Basic form.

View the equivalent 'C' GraphiC program.

View the equivalent Fortran GraphiC program.

View the program output.

Sub Sample()
    Static x() As Single
    Static y() As Single
    Dim i As Integer
    Dim hGPCWnd, hWndMain, npts As Long
    Dim Samp_heading As String
    Dim ymin, ymax, ystep As Single
    
    
    'Initialize GraphiC Window
    hGPCWnd = GPCWINOpen(hWndMain)
    If hGPCWnd = 0 Then
        MsgBox "Failure opening GPC window.", 48, " "
        Exit Sub
    End If
    
    npts = 300                           ' The # of points in x and y vectors
    ReDim x(0 To npts)
    ReDim y(0 To npts)

    For i = 0 To npts - 1                                     ' Generate data
        y(i) = 0.3 * i
        x(i) = (y(i) * y(i)) / 2#
    Next

    bgnplot 1, Asc("g"), "sample.tkf"   ' parameters: 1 - draw plot on screen
                                        '   'g' - graphics mode
                                        '   "sample.tkf" - .TKF file name
    startplot(WHITE);
    metricunits 0                              ' Ensure scaling in inch units
    startplot WHITE
    page 9#, 6.884                                       ' Sets the page size
                              ' This is the same aspect ratio as 8192 by 6266
    area2d 7.6, 5.5                               ' Sets the area of the plot
    color BLACK                        ' Axis names and heading will be black
    xname "X-Axis"
    yname "Y-Axis"
    heading "Sample Plot"
    grid 9                      ' Draws grid through tick marks, 9 - fine dot
    color GREEN                                       ' Green axes and labels
    scales 5, 6, x(0), y(0), npts      ' Draw axes with 5 X and 6 Y divisions
    color RED                                                     ' Red curve
    sympick 12                                        ' Filled circle symbols
    curve x(0), y(0), npts, 10     ' Draw curve with a symbol every 10 points
    endplot             ' Finishes plot and waits for instructions to exit or
                  ' draw next plot. Resets file pointers and GraphiC defaults
    stopplot                         ' Close files, return to calling program 

End Sub

Back to the GraphiC Home Page