Results 1 to 2 of 2

Thread: Vb6 - graph32

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012

    Vb6 - graph32

    I was in need of a graphical representation of some data, so I dug up an old program and cleaned up the code. The attached example uses "Graph32.ocx" from Pinnacle. Some people are under the impression that VB6 does not support this ActiveX Control. In fact, this control and several others were included in the VB6 CD, but were not installed by default. They can be found in the directory "\COMMON\TOOLS\VB\CONTROLS". The "readme.txt" file has this to say about "Graph32":
    "Graph32.ocx has been updated to work properly in Visual Basic 6.0 and it requires two additional support files: gsw32.exe and gswdll32.dll. You must place the three files together in the \Windows\System directory or the control will not function properly."
    \Windows\System is actually \Windows\System32\ on 32 bit systems, and \Windows\Syswow64\ on 64 bit systems. The help file (CTRLREF.HLP) is easily accessible by setting the focus on the "Graph" control and pressing the "F1" key. This may require the upgrading of "winhlp32.exe".

    This is a fairly easy control to utilize. In it's simplest form it will use the defaults, which consists of random data.
    Private Sub cmdGet5_Click()
        Graph1.Left = 0
        Graph1.Top = 0
        Graph1.ZOrder 0
        Graph1.Width = Me.ScaleWidth
        Graph1.Height = lblRecords.Top
        Graph1.Visible = True
    End Sub
    For data, the control uses "1" based arrays containing single precision numbers input as string data. If we imagine the graph data to be a 2 dimensional array, in our example it would be a 3x11 array with the dimensions determined by ".NumSets" & ".NumPoints". The number of items in ".LegendText" should match ".NumSets", and the number of items in ".LabelText" should match ".NumPoints". We have used the "QuickData" function to enter the data, which uses a Tab character to separate Point items and a CrLf to separate Set items. Using this function automatically creates ".NumSets" & ".NumPoints".
    Private Sub cmdGet1_Click()
        Const LABEL_LIST As String = "2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015"
        Const LEGEND_LIST As String = "Crude Oil,Gasoline,Natural Gas"
        Const SET1_LIST As String = "10.44,11.36,12.52,16.96,10.65,13.60,16.25,16.10,16.77,15.88,8.33"
        Const SET2_LIST As String = "20.18,22.72,24.56,28.68,21.61,24.47,30.96,32.02,33.16,29.56,21.75"
        Const SET3_LIST As String = "12.52,12.81,12.65,14.44,11.21,10.99,10.69,9.66,10.09,10.79,9.50"
        Dim sLabel() As String
        Dim sLegend() As String
        Dim sQuick As String
        Dim N%
        sLabel = Split(LABEL_LIST, ",")
        sLegend = Split(LEGEND_LIST, ",")
        sQuick = SET1_LIST & vbCrLf & SET2_LIST & vbCrLf & SET3_LIST & vbCrLf
        sQuick = Replace(sQuick, ",", vbTab)
        With Graph1
            .Left = 0
            .Top = 0
            .ZOrder 0
            .GraphType = 6 'Line Graph
            .LeftTitle = "USD per Million BTU"
            .GraphTitle = "ENERGY PRICE"
            .BottomTitle = "Average Annual Price per Million BTU"
            .AutoInc = 0
            .RandomData = 0
            .QuickData = sQuick 'Import Data
            For N% = 1 To .NumPoints 'Set X axis labels and legend text
                .ThisPoint = N%
                If N% <= .NumSets Then .LegendText = sLegend(N% - 1)
                .LabelText = sLabel(N% - 1)
            Next N%
            .Width = frmGraph.ScaleWidth
            .Height = lblRecords.Top
            lblRecords = "Total Records = " & CStr(.NumPoints)
            lblCount = "Total Count = " & CStr(.NumPoints * .NumSets)
            .Visible = True
        End With
    End Sub
    The graph is maintained as a small invisible control in the upper left corner, and the location parameters of this control are stored whenever the form is sized. When the graph control is clicked, the graph is restored to it's saved condition and made invisible again.

    Tested on Vista and Win 8.1.

    J.A. Coutts
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2015

    Re: Vb6 - graph32

    The updated VB6 "GRAPH32.OCX" is not installed by default, because MSCHART was intended to be it's replacement. I think it was only provided to make it easier for VB5 projects that depended on GRAPHS32.ocx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width