home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l391_1 / 2.ddi / PGSCAT.BA$ / PGSCAT.bin
Encoding:
Text File  |  1992-08-19  |  4.1 KB  |  126 lines

  1. ' ------------------------------------------------------------------------
  2. ' Visual Basic for MS-DOS Presentation Graphics Toolkit
  3. ' Scatter Chart Example
  4. '
  5. ' The Presentation Graphics Toolkit must be loaded to run
  6. ' this example (VBDOS /L CHART).
  7. '
  8. ' Copyright (C) 1982-1992 Microsoft Corporation
  9. '
  10. ' You have a royalty-free right to use, modify, reproduce
  11. ' and distribute the sample applications and toolkits provided with
  12. ' Visual Basic for MS-DOS (and/or any modified version)
  13. ' in any way you find useful, provided that you agree that
  14. ' Microsoft has no warranty, obligations or liability for
  15. ' any of the sample applications or toolkits.
  16. ' ------------------------------------------------------------------------
  17.  
  18. DEFINT A-Z
  19.  
  20. ' Include files containing declarations for called procedures.
  21. ' $INCLUDE: 'CHART.BI'
  22.  
  23. DECLARE FUNCTION BestMode ()
  24.  
  25. CONST FALSE = 0
  26. CONST TRUE = NOT FALSE
  27. CONST MONTHS = 12
  28. CONST HIGHESTMODE = 13
  29.  
  30. DIM Env AS ChartEnvironment                 ' Variable to hold environment structure
  31. DIM OJvalues(1 TO MONTHS) AS SINGLE         ' Array for 1st data series
  32. DIM HCvalues(1 TO MONTHS) AS SINGLE         ' Array for 2nd data series
  33.  
  34. ' Initialize the data arrays
  35. FOR index = 1 TO MONTHS: READ OJvalues(index): NEXT index
  36. FOR index = 1 TO MONTHS: READ HCvalues(index): NEXT index
  37.  
  38. ' Pass the value returned by the BestMode function to the Presentation
  39. ' Graphics routine ChartScreen to set the graphics mode for charting
  40. ChartScreen (BestMode)      ' Even if SCREEN is already set to an acceptable
  41.                             ' mode, you still have to set it with ChartScreen
  42.  
  43. IF ChartErr = cBadScreen THEN   ' Check to make sure ChartScreen succeeded
  44.     PRINT "Cannot switch to a graphics screen mode."
  45.     END
  46. END IF
  47.  
  48. ' Initialize a default pie chart
  49. DefaultChart Env, cScatter, cNoLines  ' Constant cScatter (for Scatter Chart), cNoLines (unjoined points)
  50.  
  51. ' Add Titles and some chart options. These assignments modify some default
  52. ' values set in the variable Env (of type ChartEnvironment) by DefaultChart
  53. Env.MainTitle.Title = "Good Neighbor Grocery" ' Specifies text of chart title
  54. Env.MainTitle.TitleColor = 11                 ' Specifies color of title text
  55. Env.MainTitle.Justify = cRight                ' How to align of title text
  56. Env.SubTitle.Title = "OJ vs. Hot Chocolate"   ' Text of chart subtitle
  57. Env.SubTitle.TitleColor = 15                  ' Color of subtitle text
  58. Env.SubTitle.Justify = cRight                 ' How to align of subtitle text
  59. Env.ChartWindow.Border = cNo                  ' Specifies chart has no border
  60.  
  61. ' Label the x and y axes of the chart
  62. Env.XAxis.AxisTitle.Title = "Orange Juice Sales"
  63. Env.YAxis.AxisTitle.Title = "Hot Chocolate Sales"
  64.  
  65. ' Call the pie-charting routine --- Arguments for call to ChartPie are:
  66. ' Env                 - Environment variable
  67. ' OJvalues            - Array containing orange-juice sales values to chart
  68. ' HCvalues            - Array containing hot-chocolate sales values to chart
  69. ' MONTHS              - Tells number of data values to chart
  70. ChartScatter Env, OJvalues(), HCvalues(), MONTHS
  71.  
  72. SLEEP
  73.  
  74. END
  75.  
  76. ' Simulate data generation for chart values and category labels
  77. DATA 33,27,42,64,106,157,182,217,128,62,43,36
  78. DATA 37,37,30,19,10,5,2,1,7,15,28,39     
  79.  
  80. ' Best graphics screenmode retrieval routine.
  81. '
  82. ' Determines the best graphics screenmode available
  83. ' for displaying the chart.
  84. '
  85. FUNCTION BestMode ()
  86.     ' Set error trap for determining supported screenmodes.
  87.     ON LOCAL ERROR GOTO ScreenError
  88.  
  89.     FOR TestValue = HIGHESTMODE TO 0 STEP -1
  90.         DisplayError = FALSE
  91.         SCREEN TestValue
  92.         IF DisplayError = FALSE THEN
  93.             SELECT CASE TestValue
  94.                 CASE 12, 13
  95.                     BestMode = 12
  96.                 CASE 9, 10, 11
  97.                     BestMode = 9
  98.                 CASE 8, 4, 3
  99.                     BestMode = TestValue
  100.                 CASE 2, 7
  101.                     BestMode = 2
  102.                 CASE 1
  103.                     BestMode = 1
  104.                 CASE ELSE
  105.                     PRINT "Graphics screenmode required to display charts."
  106.                     END
  107.             END SELECT
  108.             EXIT FUNCTION
  109.         END IF
  110.     NEXT TestValue
  111.  
  112.  
  113.     EXIT FUNCTION
  114.  
  115. ' Screenmode error trap
  116. ' Handles invalid SCREEN values.
  117. ScreenError:
  118.     IF ERR = 5 THEN
  119.         DisplayError = TRUE
  120.         RESUME NEXT
  121.     ELSE
  122.         ERROR ERR
  123.     END IF
  124. END FUNCTION
  125.  
  126.