home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Ocx / VCFIMP / VCIMPRES.Z / scroll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-01  |  9.3 KB  |  262 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Scrolling Chart Demo"
  4.    ClientHeight    =   6735
  5.    ClientLeft      =   1035
  6.    ClientTop       =   1710
  7.    ClientWidth     =   7035
  8.    Height          =   7425
  9.    Icon            =   "scroll.frx":0000
  10.    Left            =   975
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6735
  13.    ScaleWidth      =   7035
  14.    Top             =   1080
  15.    Width           =   7155
  16.    Begin VB.HScrollBar HScroll1 
  17.       Height          =   255
  18.       Left            =   60
  19.       TabIndex        =   1
  20.       Top             =   6420
  21.       Width           =   6915
  22.    End
  23.    Begin VB.Label lblTitle 
  24.       Alignment       =   2  'Center
  25.       Caption         =   "Dow Jones Average"
  26.       BeginProperty Font 
  27.          name            =   "Times New Roman"
  28.          charset         =   0
  29.          weight          =   400
  30.          size            =   24
  31.          underline       =   0   'False
  32.          italic          =   0   'False
  33.          strikethrough   =   0   'False
  34.       EndProperty
  35.       Height          =   615
  36.       Left            =   60
  37.       TabIndex        =   3
  38.       Top             =   60
  39.       Width           =   6915
  40.    End
  41.    Begin VB.Label lblinfo 
  42.       Alignment       =   2  'Center
  43.       Appearance      =   0  'Flat
  44.       BackColor       =   &H80000005&
  45.       BackStyle       =   0  'Transparent
  46.       Caption         =   "Information"
  47.       ForeColor       =   &H80000008&
  48.       Height          =   255
  49.       Left            =   60
  50.       TabIndex        =   2
  51.       Top             =   720
  52.       Width           =   6915
  53.    End
  54.    Begin VCIFiLib.VtChart VtChart1 
  55.       Height          =   5355
  56.       Left            =   60
  57.       TabIndex        =   0
  58.       Top             =   1020
  59.       Width           =   6915
  60.       _version        =   65536
  61.       _extentx        =   12197
  62.       _extenty        =   9446
  63.       _stockprops     =   96
  64.       borderstyle     =   1
  65.       filename        =   "scroll.frx":030A
  66.    End
  67.    Begin VB.Menu mnuChartTypeHead 
  68.       Caption         =   "&Chart Type"
  69.       Begin VB.Menu mnuChartType 
  70.          Caption         =   "2D Line"
  71.          Index           =   0
  72.       End
  73.       Begin VB.Menu mnuChartType 
  74.          Caption         =   "2D Area"
  75.          Index           =   1
  76.       End
  77.       Begin VB.Menu mnuChartType 
  78.          Caption         =   "3D Line"
  79.          Checked         =   -1  'True
  80.          Index           =   2
  81.       End
  82.       Begin VB.Menu mnuChartType 
  83.          Caption         =   "3D Area"
  84.          Index           =   3
  85.       End
  86.       Begin VB.Menu mnuChartType 
  87.          Caption         =   "3D Step"
  88.          Index           =   4
  89.       End
  90.    End
  91.    Begin VB.Menu mnuSetDaysVisible 
  92.       Caption         =   "&Set Days Visible!"
  93.    End
  94. Attribute VB_Name = "Form1"
  95. Attribute VB_Creatable = False
  96. Attribute VB_Exposed = False
  97. Option Explicit
  98. Option Base 1
  99. Dim DJData() As Double
  100. Dim gNumDataRows%
  101. Sub SetInfoLabel(offset%)
  102.    lblInfo.Caption = " Dow Jones Average on " & _
  103.       Format(DJData(HScroll1.value + offset, 1), "d mmmm yyyy") & _
  104.       " was " & DJData(HScroll1.value + offset, 2)
  105. End Sub
  106. Sub ShowView(startingAt%)
  107.    Dim i%, numRows%, min!, max!, temp#
  108.    Dim numLabels%, label$
  109.    numRows = HScroll1.LargeChange
  110.    '' If the user has scrolled to the end of the data, change
  111.    '' the startingAt value so the entire chart can be viewed.
  112.    '' This catches the case where the user has large window
  113.    '' and wants to scroll to the end.
  114.    If startingAt > 1 And startingAt > gNumDataRows - numRows Then
  115.       startingAt = gNumDataRows - numRows
  116.    End If
  117.    VtChart1.RowCount = numRows
  118.    '' The dimmensions of the array must match the dimmensions
  119.    '' of the chart you want to fill. You must always use a 2D
  120.    '' array even if you are copying in one row of data.
  121.    ReDim theData(numRows, 1) As Double
  122.    max = 0
  123.    min = 10000
  124.    For i = 1 To numRows
  125.       temp = DJData(i + startingAt, 2)
  126.       theData(i, 1) = temp
  127.       max = IIf(temp > max, temp, max)
  128.       min = IIf(temp < min, temp, min)
  129.    Next i
  130.    VtChart1.CopyDataFromArray 1, 1, numRows, 1, theData
  131.    '' AutoScale will have a minimum at zero. We set min
  132.    '' and max manually here
  133.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Int((max + 20) / 10) * 10
  134.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Int((min - 20) / 10) * 10
  135.    '' Clear any old datapoint labels
  136.    Dim DataPoint As Object
  137.    With VtChart1.Plot.SeriesCollection.Item(1)
  138.       For Each DataPoint In .DataPoints
  139.          DataPoint.DataPointLabel.ResetCustomLabel
  140.       Next DataPoint
  141.    End With
  142.    '' Set a new label for only the last datapoint
  143.    With VtChart1.Plot.SeriesCollection.Item(1).DataPoints.Item(numRows).DataPointLabel
  144.       .LocationType = VtChLabelLocationTypeCenter
  145.       .Text = Format(DJData(startingAt + numRows, 1), "m/d/yy")
  146.       .LineStyle = VtChLabelLineStyleStraight
  147.    End With
  148.    SetInfoLabel IIf(startingAt + numRows + 1 > gNumDataRows, gNumDataRows - HScroll1.value, numRows)
  149. End Sub
  150. Sub Form_Load()
  151.    Dim numRows%, numCols%, col1Text$, col2Text$
  152.    Dim i%, j%, junk&
  153.    Open App.Path & "\djave.txt" For Input As #1
  154.    Input #1, numRows, numCols, col1Text, col2Text
  155.    ReDim DJData(numRows, numCols) As Double
  156.    For i = 1 To numRows
  157.       Input #1, DJData(i, 1), DJData(i, 2)
  158.    Next i
  159.    Close #1
  160.    '' Size the scrollbar and the chart
  161.    gNumDataRows = numRows
  162.    HScroll1.Left = 60
  163.    HScroll1.min = 1
  164.    HScroll1.max = numRows
  165.    HScroll1.LargeChange = 20
  166.    VtChart1.Left = 60
  167.    VtChart1.RowCount = 20
  168.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
  169.    VtChart1.Plot.Axis(VtChAxisIdY).Labels.Item(1).Format = "#,##0"
  170.    ShowView HScroll1.value
  171. End Sub
  172. Private Sub Form_Resize()
  173.    VtChart1.Repaint = False
  174.    lblTitle.Width = ScaleWidth
  175.    lblInfo.Width = ScaleWidth
  176.    VtChart1.Width = ScaleWidth - 120
  177.    VtChart1.Height = ScaleHeight - HScroll1.Height _
  178.       - lblInfo.Height - lblTitle.Height - 210
  179.    HScroll1.Width = ScaleWidth - 120
  180.    HScroll1.Top = ScaleHeight - HScroll1.Height - 60
  181.    VtChart1.Repaint = True
  182. End Sub
  183. Private Sub HScroll1_Change()
  184.    '' This prevents the user from scrolling into a dead area
  185.    '' where a change in scrollbar produces no change in the chart.
  186.    '' This can happen if the scrollbar is dragged to the end of
  187.    '' the chart and the user clicks on the arrow towards the
  188.    '' beginning of the chart.
  189.    If HScroll1.value + HScroll1.LargeChange > HScroll1.max Then
  190.       HScroll1.value = HScroll1.max - HScroll1.LargeChange
  191.    Else
  192.       ShowView HScroll1.value
  193.    End If
  194. End Sub
  195. Private Sub mnuChartType_Click(Index As Integer)
  196.    Dim i%
  197.    For i = 0 To 4
  198.       mnuChartType(i).Checked = False
  199.    Next i
  200.    mnuChartType(Index).Checked = True
  201.    VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 2
  202.    Select Case Index
  203.       Case 0
  204.          VtChart1.ChartType = VtChChartType2dLine
  205.          VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 0
  206.       Case 1
  207.          VtChart1.ChartType = VtChChartType2dArea
  208.       Case 2
  209.          VtChart1.ChartType = VtChChartType3dLine
  210.       Case 3
  211.          VtChart1.ChartType = VtChChartType3dArea
  212.       Case 4
  213.          VtChart1.ChartType = VtChChartType3dStep
  214.    End Select
  215. End Sub
  216. Private Sub mnuSetDaysVisible_Click()
  217.    Dim title$, msg$, retval$, default$, result$
  218.    Let title = "Number of Days in Plot"
  219.    Let msg = "Enter a number between 10 and " & gNumDataRows
  220.    default = Str(VtChart1.RowCount)
  221.    result = InputBox(msg, title, default)
  222.    While StrComp(result, "") <> 0 And (Val(result) < 10 Or Val(result) > gNumDataRows)
  223.       MsgBox "Value must be between 10 and " & gNumDataRows
  224.       result = InputBox(msg, title, default)
  225.    Wend
  226.    If StrComp(result, "") <> 0 Then
  227.       HScroll1.LargeChange = Val(result)
  228.       ShowView HScroll1.value
  229.    End If
  230. End Sub
  231. Private Sub VtChart1_AxisLabelSelected(AxisId As Integer, AxisIndex As Integer, labelSetIndex As Integer, LabelIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  232.    Cancel = True
  233. End Sub
  234. Private Sub VtChart1_AxisSelected(AxisId As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  235.    Cancel = True
  236. End Sub
  237. Private Sub VtChart1_AxisTitleSelected(AxisId As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  238.    Cancel = True
  239. End Sub
  240. Private Sub VtChart1_ChartSelected(MouseFlags As Integer, Cancel As Integer)
  241.    Cancel = True
  242. End Sub
  243. Private Sub VtChart1_FootnoteSelected(MouseFlags As Integer, Cancel As Integer)
  244.    Cancel = True
  245. End Sub
  246. Private Sub VtChart1_LegendSelected(MouseFlags As Integer, Cancel As Integer)
  247.    Cancel = True
  248. End Sub
  249. Private Sub VtChart1_PlotSelected(MouseFlags As Integer, Cancel As Integer)
  250.    Cancel = True
  251. End Sub
  252. Private Sub VtChart1_PointSelected(Series As Integer, DataPoint As Integer, MouseFlags As Integer, Cancel As Integer)
  253.    SetInfoLabel DataPoint
  254.       
  255. End Sub
  256. Private Sub VtChart1_SeriesLabelSelected(Series As Integer, MouseFlags As Integer, Cancel As Integer)
  257.    Cancel = True
  258. End Sub
  259. Private Sub VtChart1_TitleSelected(MouseFlags As Integer, Cancel As Integer)
  260.    Cancel = True
  261. End Sub
  262.