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

  1. ' ------------------------------------------------------------------------
  2. ' Visual Basic for MS-DOS Presentation Graphics Toolkit
  3. ' Bar Chart Example
  4. '
  5. ' The Presentation Graphics Toolkit must be loaded to run
  6. ' this example (VBDOS /L CHART.QLB)
  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 MonthCategories(1 TO MONTHS) AS STRING  ' Array for categories
  32. DIM OJvalues(1 TO MONTHS) AS SINGLE         ' Array for data series
  33.  
  34.  
  35. ' Initialize the data arrays
  36. FOR index = 1 TO MONTHS: READ OJvalues(index): NEXT index
  37. FOR index = 1 TO MONTHS: READ MonthCategories$(index): NEXT index
  38.  
  39. ' Pass the value returned by the BestMode function to the Presentation
  40. ' Graphics routine ChartScreen to set the graphics mode for charting
  41. ChartScreen (BestMode)      ' Even if SCREEN is already set to an acceptable
  42.                             ' mode, you still have to set it with ChartScreen
  43.  
  44. IF ChartErr = cBadScreen THEN   ' Check to make sure ChartScreen succeeded
  45.     PRINT "Cannot switch to a graphics screen mode."
  46.     END
  47. END IF
  48.  
  49. ' Initialize a default pie chart
  50. DefaultChart Env, cBar, cPlain      ' The constant cBar (for Bar Chart) and cPlain
  51.  
  52. ' Add Titles and some chart options. These assignments modify some default
  53. ' values set in the variable Env (of type ChartEnvironment) by DefaultChart
  54. Env.MainTitle.Title = "Good Neighbor Grocery" ' Specifies text of chart title
  55. Env.MainTitle.TitleColor = 15                 ' Specifies color of title text
  56. Env.MainTitle.Justify = cRight                ' How to align of title text
  57. Env.SubTitle.Title = "Orange Juice Sales"     ' Text of chart subtitle
  58. Env.SubTitle.TitleColor = 15                  ' Color of subtitle text
  59. Env.SubTitle.Justify = cRight                 ' How to align of subtitle text
  60. Env.ChartWindow.Border = cNo                  ' Specifies chart has no border
  61.  
  62. ' Label the x-axis and y-axis
  63. Env.XAxis.AxisTitle.Title = "Quantity (cases)"
  64. Env.YAxis.AxisTitle.Title = "Months"
  65.  
  66. ' Call the bar-charting routine --- Arguments for call to Chart are:
  67. ' Env                 - Environment variable
  68. ' MonthCategories()   - Array containing Category labels
  69. ' OJvalues()          - Array containing Data values to chart
  70. ' MONTHS              - Tells number of data values to chart
  71. Chart Env, MonthCategories(), OJvalues(), MONTHS
  72.  
  73. SLEEP
  74.  
  75. END
  76.  
  77.  
  78. ' Simulate data generation for chart values and category labels
  79. DATA 33,27,42,64,106,157,182,217,128,62,43,36
  80. DATA "Jan","Feb","Mar","Apr","May","Jun","Jly","Aug","Sep","Oct","Nov","Dec",
  81.  
  82. ' Best graphics screenmode retrieval routine.
  83. '
  84. ' Determines the best graphics screenmode available
  85. ' for displaying the chart.
  86. '
  87. FUNCTION BestMode ()
  88.  
  89. ' Set error trap for determining supported screenmodes.
  90. ON LOCAL ERROR GOTO ScreenError
  91.  
  92. FOR TestValue = HIGHESTMODE TO 0 STEP -1
  93.     DisplayError = FALSE
  94.     SCREEN TestValue
  95.     IF DisplayError = FALSE THEN
  96.         SELECT CASE TestValue
  97.             CASE 12, 13
  98.                 BestMode = 12
  99.             CASE 9, 10, 11
  100.                 BestMode = 9
  101.             CASE 8, 4, 3
  102.                 BestMode = TestValue
  103.             CASE 2, 7
  104.                 BestMode = 2
  105.             CASE 1
  106.                 BestMode = 1
  107.             CASE ELSE
  108.                 PRINT "Graphics screenmode required to display charts."
  109.                 END
  110.         END SELECT
  111.         EXIT FUNCTION
  112.     END IF
  113. NEXT TestValue
  114.  
  115.  
  116. EXIT FUNCTION
  117.  
  118. ' Screenmode error trap
  119. ' Handles invalid SCREEN values.
  120. ScreenError:
  121.     IF ERR = 5 THEN
  122.         DisplayError = TRUE
  123.         RESUME NEXT
  124.     ELSE
  125.         ERROR ERR
  126.     END IF
  127. END FUNCTION
  128.  
  129.