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

  1. ' ------------------------------------------------------------------------
  2. ' Visual Basic for MS-DOS Presentation Graphics Toolkit
  3. ' Pie 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. ' $INCLUDE: 'FONT.BI'
  23.  
  24. DECLARE FUNCTION BestMode ()
  25.  
  26. CONST FALSE = 0
  27. CONST TRUE = NOT FALSE
  28. CONST MONTHS = 12
  29. CONST HIGHESTMODE = 13
  30.  
  31. DIM Env AS ChartEnvironment                 ' Variable to hold environment structure
  32. DIM MonthCategories(1 TO MONTHS) AS STRING  ' Array for categories
  33. DIM OJvalues(1 TO MONTHS) AS SINGLE         ' Array for data series
  34. DIM Exploded(1 TO MONTHS) AS INTEGER        ' "Explode" flags array (specifies which pie slices are separated)
  35.  
  36. ' Initialize the data arrays
  37. FOR index = 1 TO MONTHS: READ OJvalues(index): NEXT index
  38. FOR index = 1 TO MONTHS: READ MonthCategories$(index): NEXT index
  39.  
  40. ' Set the elements of the array that determines separation of the pie slices
  41. FOR Flags = 1 TO MONTHS                        ' If value of OJvalues(Flags)
  42.     Exploded(Flags) = (OJvalues(Flags) >= 100) ' >= 100 the corresponding flag
  43. NEXT Flags                                     ' is set true, separating slices
  44.  
  45. ' Pass the value returned by the BestMode function to the Presentation
  46. ' Graphics routine ChartScreen to set the graphics mode for charting
  47. ChartScreen (BestMode)      ' Even if SCREEN is already set to an acceptable
  48.                             ' mode, you still have to set it with ChartScreen
  49.  
  50. IF ChartErr = cBadScreen THEN   ' Check to make sure ChartScreen succeeded
  51.     PRINT "Cannot switch to a graphics screen mode."
  52.     END
  53. END IF
  54.  
  55. ' Initialize a default pie chart
  56. DefaultChart Env, cPie, cPercent    ' the constant cPie (for Pie Chart) and cPercent (label slices with percentage)
  57.  
  58. ' Add Titles and some chart options. These assignments modify some default
  59. ' values set in the variable Env (of type ChartEnvironment) by DefaultChart
  60. Env.MainTitle.Title = "Good Neighbor Grocery" ' Specifies text of chart title
  61. Env.MainTitle.TitleColor = 15                 ' Specifies color of title text
  62. Env.MainTitle.Justify = cCenter               ' How to align of title text
  63. Env.SubTitle.Title = "Orange Juice Sales"     ' Text of chart subtitle
  64. Env.SubTitle.TitleColor = 11                  ' Color of subtitle text
  65. Env.SubTitle.Justify = cCenter                ' How to align of subtitle text
  66. Env.ChartWindow.Border = cYes                 ' Specifies chart has no border
  67.  
  68. ' Call the pie-charting routine --- Arguments for call to ChartPie are:
  69. ' Env                 - Environment variable
  70. ' MonthCategories()   - Array containing Category labels
  71. ' OJvalues()          - Array containing Data values to chart
  72. ' Exploded()          - Integer array tells which pieces of the pie should
  73. '                       be separated (non-zero=exploded, 0=not exploded)
  74. ' MONTHS              - Tells number of data values to chart
  75. ChartPie Env, MonthCategories(), OJvalues(), Exploded(), MONTHS
  76.  
  77. SLEEP
  78.  
  79. END
  80.  
  81. ' Simulate data generation for chart values and category labels
  82. DATA 33,27,42,64,106,157,182,217,128,62,43,36
  83. DATA "Jan","Feb","Mar","Apr","May","Jun","Jly","Aug","Sep","Oct","Nov","Dec"
  84.  
  85. ' Best graphics screenmode retrieval routine.
  86. '
  87. ' Determines the best graphics screenmode available
  88. ' for displaying the chart.
  89. '
  90. FUNCTION BestMode ()
  91.     ' Set error trap for determining supported screenmodes.
  92.     ON LOCAL ERROR GOTO ScreenError
  93.  
  94.     FOR TestValue = HIGHESTMODE TO 0 STEP -1
  95.         DisplayError = FALSE
  96.         SCREEN TestValue
  97.         IF DisplayError = FALSE THEN
  98.             SELECT CASE TestValue
  99.                 CASE 12, 13
  100.                     BestMode = 12
  101.                 CASE 9, 10, 11
  102.                     BestMode = 9
  103.                 CASE 8, 4, 3
  104.                     BestMode = TestValue
  105.                 CASE 2, 7
  106.                     BestMode = 2
  107.                 CASE 1
  108.                     BestMode = 1
  109.                 CASE ELSE
  110.                     PRINT "Graphics screenmode required to display charts."
  111.                     END
  112.             END SELECT
  113.             EXIT FUNCTION
  114.         END IF
  115.     NEXT TestValue
  116.  
  117.  
  118.     EXIT FUNCTION
  119.  
  120. ' Screenmode error trap
  121. ' Handles invalid SCREEN values.
  122. ScreenError:
  123.     IF ERR = 5 THEN
  124.         DisplayError = TRUE
  125.         RESUME NEXT
  126.     ELSE
  127.         ERROR ERR
  128.     END IF
  129. END FUNCTION
  130.  
  131.