home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / CHRTDEMO.BA$ / CHRTDEMO.bin
Encoding:
Text File  |  1990-06-24  |  45.8 KB  |  1,315 lines

  1. '       CHRTDEMO.BAS - Main module of CHRTB demonstration program
  2. '
  3. '             Copyright (C) 1989-1990, Microsoft Corporation
  4. '
  5. '   This demo program uses the Presentation Graphics and User Interface
  6. '   toolboxes to implement a general purpose charting package.
  7. '   It consists of three modules (CHRTDEMO.BAS, CHRTDEM1.BAS and CHRTDEM2.BAS)
  8. '   and one include file (CHRTDEMO.BI).  It requires access to both the
  9. '   Presentation Graphics and User Interface toolboxes.
  10. '
  11. '   EMS is needed to load and run the demo under QBX.  If you do not
  12. '   have EMS, refer to the command line compile instructions below which
  13. '   will allow you to run the demo from the DOS prompt.  Running the
  14. '   demo under QBX requires access to the Presentation Graphics and User
  15. '   Interface toolboxes.  This can be done in one of two methods:
  16. '       1) One large QuickLib covering both toolboxes can be created.  The
  17. '          library "CHRTDEM.LIB" and QuickLib "CHRTDEM.QLB" are created
  18. '          as follows:
  19. '           BC /X/FS chrtb.bas;
  20. '           BC /X/FS fontb.bas;
  21. '           LIB chrtdem.lib + uitbefr.lib + fontasm + chrtasm + fontb + chrtb;
  22. '           LINK /Q chrtdem.lib, chrtdem.qlb,,qbxqlb.lib;
  23. '          Once created, just start QBX with this QuickLib and load the
  24. '          demo's modules (chrtdemo.bas, chrtdem1.bas and chrtdem2.bas).
  25. '
  26. '       2) Either the Presentation Graphics or User Interface QuickLib
  27. '          may be used alone provided the other's source code files
  28. '          are loaded into the QBX environment.  If CHRTBEFR.QLB is
  29. '          is used then WINDOW.BAS, GENERAL.BAS, MENU.BAS and MOUSE.BAS
  30. '          must be loaded.  If UITBEFR.QLB is used then CHRTB.BAS and
  31. '          FONTB.BAS must be loaded.  Once a QuickLib is specified and
  32. '          all necessary source files are loaded, load the program
  33. '          modules (chrtdemo.bas, chrtdem1.bas and chrtdem2.bas)
  34. '
  35. '   To create a compiled version of the chart demo program perform the
  36. '   following steps:
  37. '       BC /X/FS chrtb.bas;
  38. '       BC /X/FS fontb.bas;
  39. '       LIB chrtdem.lib + uitbefr.lib + fontasm + chrtasm + fontb + chrtb;
  40. '       BC /X/FS chrtdemo.bas;
  41. '       BC /FS chrtdem1.bas;
  42. '       BC /FS chrtdem2.bas;
  43. '       LINK /EX chrtdemo chrtdem1 chrtdem2, chrtdemo.exe,, chrtdem.lib;
  44. '   "CHRTDEMO" can now be run from the command line.
  45. '
  46. '
  47. DEFINT A-Z
  48.  
  49. '$INCLUDE: 'chrtdemo.bi'
  50.  
  51. ' local functions
  52. DECLARE FUNCTION GetLoadFile% (FileName$)
  53. DECLARE FUNCTION GetSaveFile% (FileName$)
  54. DECLARE FUNCTION GetFileCount% (fileSpec$)
  55.  
  56. ' local subs
  57. DECLARE SUB LoadChart (fileNum%)
  58. DECLARE SUB ShowError (errorNum%)
  59.  
  60.  
  61. ' necessary variables for the toolboxes
  62. DIM GloTitle(MAXMENU)           AS MenuTitleType
  63. DIM GloItem(MAXMENU, MAXITEM)   AS MenuItemType
  64. DIM GloWindow(MAXWINDOW)        AS windowType
  65. DIM GloButton(MAXBUTTON)        AS buttonType
  66. DIM GloEdit(MAXEDITFIELD)       AS EditFieldType
  67. DIM GloWindowStack(MAXWINDOW)   AS INTEGER
  68. DIM GloBuffer$(MAXWINDOW + 1, 2)
  69.  
  70. ' variables shared across modules
  71. DIM colors$(1 TO MAXCOLORS)                     'valid colors$
  72. DIM styles$(1 TO MAXSTYLES)                     'border style list
  73. DIM fonts$(1 TO MAXFONTS)                       'fonts list
  74. DIM Cat$(1 TO cMaxValues)                       'category names
  75. DIM setName$(1 TO cMaxSets)                     'set names
  76. DIM setLen(1 TO cMaxSets)   AS INTEGER          '# values per set
  77. DIM setVal!(1 TO cMaxValues, 1 TO cMaxSets)     ' actual values
  78. DIM mode$(1 TO 13)                              'list of modes
  79.  
  80.  
  81.     ' set up main error handler
  82.     ON ERROR GOTO ErrorHandle
  83.  
  84.     ' initialize the program
  85.     InitAll
  86.  
  87.     ' Main loop
  88.     WHILE NOT finished
  89.         kbd$ = MenuInkey$
  90.         WHILE MenuCheck(2)
  91.             HandleMenuEvent
  92.         WEND
  93.     WEND
  94.  
  95.     END
  96.  
  97. 'catch all error handler
  98. ErrorHandle:
  99.     ShowError ERR
  100.     WindowClose 1                               ' close any active windows
  101.     WindowClose 2
  102. RESUME NEXT
  103.  
  104. '
  105. ' Function Name: GetBestMode
  106. '
  107. ' Description: Creates a list of valid screen modes for use by charting functions
  108. '              and sets the initial screen mode to the highest resolution
  109. '              possible.  If no graphic screen modes are available then
  110. '              it causes the program to exit.
  111. '
  112. ' Arguments: screenMode
  113. '
  114. SUB GetBestMode (screenMode)
  115. SHARED mode$(), numModes AS INTEGER
  116.  
  117. ON LOCAL ERROR GOTO badmode                     ' trap screen mode errors
  118.  
  119.     ' test all possible screen modes creating a list of valid ones as we go
  120.     numModes = 0
  121.     FOR i = 13 TO 1 STEP -1
  122.         valid = TRUE
  123.         SCREEN i
  124.         IF valid THEN
  125.             numModes = numModes + 1
  126.             mode$(numModes) = LTRIM$(STR$(i))
  127.         END IF
  128.     NEXT i
  129.  
  130.     ' exit if no modes available
  131.     IF numModes = 0 THEN
  132.         screenMode = 0
  133.     ' set current screen mode to best possible
  134.     ELSEIF mode$(1) = "13" THEN
  135.         screenMode = VAL(mode$(2))
  136.     ELSE
  137.         screenMode = VAL(mode$(1))
  138.     END IF
  139.  
  140. EXIT SUB
  141.  
  142. badmode:
  143.     valid = FALSE
  144. RESUME NEXT
  145.  
  146. END SUB
  147.  
  148. '
  149. ' Func Name: GetFileCount
  150. '
  151. ' Description: Returns number of DOS files matching a given file spec
  152. '
  153. ' Arguments: fileSpec$ - DOS file spec  (i.e. "*.*")
  154. '
  155. FUNCTION GetFileCount% (fileSpec$)
  156.  
  157. ON LOCAL ERROR GOTO GetCountError
  158.  
  159.     count = 0
  160.  
  161.     FileName$ = DIR$(fileSpec$)             ' Get first match if any
  162.  
  163.     DO WHILE FileName$ <> ""                ' continue until no more matches
  164.         count = count + 1
  165.         FileName$ = DIR$
  166.     LOOP
  167.  
  168.     GetFileCount = count                    ' return count
  169.  
  170.     EXIT FUNCTION
  171.  
  172. GetCountError:
  173.  
  174.     ShowError ERR                               ' display error message
  175.  
  176. RESUME NEXT
  177.  
  178. END FUNCTION
  179.  
  180. '
  181. ' Func Name: GetLoadFile
  182. '
  183. ' Description: Called by OpenChart, this prompts the user for a
  184. '              DOS file to open.  It returns the file number of
  185. '              the chart file with the actual file name being
  186. '              passed back via the argument.
  187. '
  188. ' Arguments: FileName$ - name of file to open
  189. '
  190. FUNCTION GetLoadFile% (FileName$)
  191. DIM fileList$(1 TO 10)
  192. DIM fileBox AS ListBox
  193.  
  194. ON LOCAL ERROR GOTO GetLoadError                ' handle file opening errors
  195.  
  196.     fileSpec$ = "*.CHT"                         ' default file spec
  197.     origDir$ = CURDIR$
  198.     origPos = 0                                 ' no file list element selected
  199.  
  200.     ' get list of files matching spec
  201.     fileCount = GetFileCount(fileSpec$)
  202.     IF fileCount THEN
  203.         REDIM fileList$(fileCount)
  204.     END IF
  205.     fileList$(1) = DIR$(fileSpec$)
  206.     FOR i% = 2 TO fileCount
  207.         fileList$(i%) = DIR$
  208.     NEXT i%
  209.  
  210.     ' set up list box for file list
  211.     fileBox.scrollButton = 1
  212.     fileBox.areaButton = 2
  213.     fileBox.listLen = fileCount
  214.     fileBox.topRow = 8
  215.     fileBox.botRow = 14
  216.     fileBox.leftCol = 7
  217.     fileBox.rightCol = 22
  218.     fileBox.listPos = origPos
  219.  
  220.     ' create window for display
  221.     winRow = 6
  222.     winCol = 25
  223.     WindowOpen 1, winRow, winCol, 21, 52, 0, 7, 0, 7, 15, FALSE, FALSE, FALSE, TRUE, 2, "Open Chart"
  224.     WindowLocate 2, 2
  225.     WindowPrint 2, "File Name:"
  226.     WindowBox 1, 13, 3, 27
  227.     WindowLocate 5, 2
  228.     WindowPrint -1, origDir$
  229.     WindowLocate 7, 11
  230.     WindowPrint 2, "Files"
  231.     WindowLine 15
  232.  
  233.     ' create list box for file list
  234.     CreateListBox fileList$(), fileBox, 5
  235.  
  236.     ' open edit field for file spec
  237.     EditFieldOpen 1, fileSpec$, 2, 14, 0, 7, 13, 70
  238.  
  239.     ' open command buttons
  240.     ButtonOpen 3, 2, "OK", 16, 5, 0, 0, 1
  241.     ButtonOpen 4, 1, "Cancel", 16, 15, 0, 0, 1
  242.  
  243.     ' start with cursor in edit field
  244.     currButton = 0
  245.     currEditField = 1
  246.     pushButton = 3
  247.  
  248.     ' control loop
  249.     finished = FALSE
  250.     WHILE NOT finished
  251.         WindowDo currButton, currEditField              ' wait for event
  252.         SELECT CASE Dialog(0)
  253.             CASE 1                                      ' button pressed
  254.                 currButton = Dialog(1)
  255.                 SELECT CASE currButton
  256.                     CASE 1, 2: currEditField = 0
  257.                         ScrollList fileList$(), fileBox, currButton, 1, 0, winRow, winCol
  258.                         currButton = 2
  259.                     CASE 3, 4: pushButton = currButton
  260.                         finished = TRUE
  261.                 END SELECT
  262.             CASE 2                                      ' Edit Field
  263.                 currButton = 0
  264.                 currEditField = 1
  265.             CASE 6                                      ' enter
  266.                 IF INSTR(EditFieldInquire$(1), "*") = 0 THEN finished = TRUE
  267.             CASE 7                                      ' tab
  268.                 SELECT CASE currButton
  269.                     CASE 0: currButton = 2
  270.                         currEditField = 0
  271.                     CASE 1, 2:
  272.                         currButton = 3
  273.                         ButtonSetState 3, 2
  274.                         ButtonSetState 4, 1
  275.                         pushButton = 3
  276.                     CASE 3:
  277.                         currButton = 4
  278.                         ButtonSetState 3, 1
  279.                         ButtonSetState 4, 2
  280.                         pushButton = 4
  281.                     CASE 4:
  282.                         currButton = 0
  283.                         currEditField = 1
  284.                         ButtonSetState 3, 2
  285.                         ButtonSetState 4, 1
  286.                         pushButton = 3
  287.                 END SELECT
  288.             CASE 8                                      ' back tab
  289.                 SELECT CASE currButton
  290.                     CASE 0: currButton = 4
  291.                         currEditField = 0
  292.                         ButtonSetState 3, 1
  293.                         ButtonSetState 4, 2
  294.                         pushButton = 4
  295.                     CASE 1, 2:
  296.                         currButton = 0
  297.                         currEditField = 1
  298.                     CASE 3:
  299.                         currButton = 2
  300.                     CASE 4:
  301.                         currButton = 3
  302.                         ButtonSetState 3, 2
  303.                         ButtonSetState 4, 1
  304.                         pushButton = 3
  305.                 END SELECT
  306.             CASE 9                                      ' escape
  307.                 pushButton = 4
  308.                 finished = TRUE
  309.             CASE 10, 12                                 ' up, left arrow
  310.                 IF currButton = 1 OR currButton = 2 THEN ScrollList fileList$(), fileBox, currButton, 2, 0, winRow, winCol
  311.             CASE 11, 13                                 'down, right arrow
  312.                 IF currButton = 1 OR currButton = 2 THEN ScrollList fileList$(), fileBox, currButton, 3, 0, winRow, winCol
  313.             CASE 14                                     ' space bar
  314.                 IF currButton > 2 THEN
  315.                     pushButton = currButton
  316.                     finished = TRUE
  317.                 END IF
  318.         END SELECT
  319.  
  320.         temp$ = EditFieldInquire$(1)
  321.  
  322.         ' simple error checking before finishing
  323.         IF finished AND pushButton <> 4 THEN
  324.             ' invalid file specified
  325.             IF INSTR(temp$, "*") THEN
  326.                 PrintError "Invalid file specification."
  327.                 finished = FALSE
  328.             ELSEIF LEN(temp$) = 0 THEN
  329.                 PrintError "Must specify a name."
  330.                 finished = FALSE
  331.             ELSE
  332.                 fileSpec$ = temp$
  333.                 fileNum% = FREEFILE
  334.                 OPEN fileSpec$ FOR INPUT AS fileNum%
  335.  
  336.             END IF
  337.         END IF
  338.  
  339.         ' more processing to do
  340.         IF NOT finished THEN
  341.             ' update edit field display based on list box selection
  342.             IF fileBox.listPos <> origPos THEN
  343.                 fileSpec$ = fileList$(fileBox.listPos)
  344.                 origPos = fileBox.listPos
  345.                 EditFieldClose 1
  346.                 EditFieldOpen 1, fileSpec$, 2, 14, 0, 7, 13, 70
  347.             ' update list box contents based on new edit field contents
  348.             ELSEIF LTRIM$(RTRIM$(fileSpec$)) <> LTRIM$(RTRIM$(temp$)) THEN
  349.                 fileSpec$ = UCASE$(temp$)
  350.                 IF fileSpec$ <> "" THEN
  351.                     IF MID$(fileSpec$, 2, 1) = ":" THEN
  352.                         CHDRIVE MID$(fileSpec$, 1, 2)
  353.                         fileSpec$ = MID$(fileSpec$, 3, LEN(fileSpec$))
  354.                     END IF
  355.                     position = 0
  356.                     WHILE INSTR(position + 1, fileSpec$, "\") <> 0
  357.                         position = INSTR(position + 1, fileSpec$, "\")
  358.                     WEND
  359.                     IF position = 1 THEN
  360.                         CHDIR "\"
  361.                     ELSEIF position > 0 THEN
  362.                         CHDIR LEFT$(fileSpec$, position - 1)
  363.                     END IF
  364.                     fileSpec$ = MID$(fileSpec$, position + 1, LEN(fileSpec$))
  365.                     WindowLocate 5, 2
  366.                     IF LEN(CURDIR$) > 26 THEN
  367.                         direct$ = LEFT$(CURDIR$, 26)
  368.                     ELSE
  369.                         direct$ = CURDIR$
  370.                     END IF
  371.                     WindowPrint -1, direct$ + STRING$(26 - LEN(direct$), " ")
  372.  
  373.                     fileCount = GetFileCount(fileSpec$)
  374.                 ELSE
  375.                     fileCount = 0
  376.                 END IF
  377.  
  378.                 EditFieldClose 1
  379.                 EditFieldOpen 1, fileSpec$, 2, 14, 0, 7, 13, 70
  380.  
  381.                 fileBox.listLen = fileCount
  382.                 fileBox.maxLen = Min(fileCount, fileBox.boxLen)
  383.                 origPos = 0
  384.                 fileBox.listPos = origPos
  385.                 fileBox.currTop = 1
  386.                 fileBox.currPos = 0
  387.                 ' get new file list
  388.                 IF fileCount = 0 THEN
  389.                     REDIM fileList$(10)
  390.                 ELSE
  391.                     REDIM fileList$(fileCount)
  392.                     fileList$(1) = DIR$(fileSpec$)
  393.                     FOR i% = 2 TO fileCount
  394.                         fileList$(i%) = DIR$
  395.                     NEXT i%
  396.                 END IF
  397.  
  398.                 DrawList fileList$(), fileBox, 0   ' redraw file list
  399.             END IF
  400.         END IF
  401.     WEND
  402.  
  403.     ' if operation not canceled return file name and file number
  404.     IF pushButton = 3 THEN
  405.         FileName$ = fileSpec$
  406.         GetLoadFile% = fileNum%
  407.     ELSE
  408.         GetLoadFile% = 0
  409.  
  410.         CHDRIVE MID$(origDir$, 1, 2)
  411.         CHDIR MID$(origDir$, 3, LEN(origDir$))
  412.     END IF
  413.  
  414.     WindowClose 1
  415.  
  416.     EXIT FUNCTION
  417.  
  418. ' handle any file opening errors
  419. GetLoadError:
  420.     CLOSE fileNum%
  421.     finished = FALSE                            ' don't allow exit until valid file chosen
  422.  
  423.     ShowError ERR                               ' display error message
  424. RESUME NEXT
  425.  
  426. END FUNCTION
  427.  
  428. '
  429. ' Func Name: GetSaveFile
  430. '
  431. ' Description: Prompts the user for a DOS file to save the current
  432. '              chart data and settings in.  It returns the file number
  433. '              with the actual file name being passed back via the
  434. '              argument.
  435. '
  436. ' Arguments: fileName$ - name of save file
  437. '
  438. FUNCTION GetSaveFile% (FileName$)
  439.  
  440. ON LOCAL ERROR GOTO GetSaveError                    ' handle file open errors
  441.  
  442.     ' Open window for display
  443.     WindowOpen 1, 8, 20, 12, 58, 0, 7, 0, 7, 15, FALSE, FALSE, FALSE, TRUE, 1, "Save Chart As"
  444.     WindowLocate 2, 2
  445.     WindowPrint 2, "File Name:"
  446.     WindowBox 1, 13, 3, 38
  447.     WindowLine 4
  448.  
  449.     ' open edit field for file name
  450.     EditFieldOpen 1, RTRIM$(FileName$), 2, 14, 0, 7, 24, 70
  451.  
  452.     ' open command buttons
  453.     ButtonOpen 1, 2, "OK", 5, 6, 0, 0, 1
  454.     ButtonOpen 2, 1, "Cancel", 5, 25, 0, 0, 1
  455.  
  456.     ' start with cursor in edit field
  457.     currButton = 0
  458.     currEditField = 1
  459.     pushButton = 1
  460.  
  461.     ' control loop for window
  462.     finished = FALSE
  463.     WHILE NOT finished
  464.         WindowDo currButton, currEditField              ' wait for event
  465.         SELECT CASE Dialog(0)
  466.             CASE 1                                      ' Button pressed
  467.                 pushButton = Dialog(1)
  468.                 finished = TRUE
  469.             CASE 2                                      ' Edit Field
  470.                 currButton = 0
  471.                 currEditField = 1
  472.             CASE 6                                      ' enter
  473.                 finished = TRUE
  474.             CASE 7                                      ' tab
  475.                 SELECT CASE currButton
  476.                     CASE 0, 1:
  477.                         ButtonSetState currButton, 1
  478.                         currButton = currButton + 1
  479.                         pushButton = currButton
  480.                         ButtonSetState pushButton, 2
  481.                         currEditField = 0
  482.                     CASE 2
  483.                         currButton = 0
  484.                         pushButton = 1
  485.                         currEditField = 1
  486.                         ButtonSetState 1, 2
  487.                         ButtonSetState 2, 1
  488.                 END SELECT
  489.             CASE 8                                      ' back tab
  490.                 SELECT CASE currButton
  491.                     CASE 0:
  492.                         currButton = 2
  493.                         pushButton = 2
  494.                         currEditField = 0
  495.                         ButtonSetState 1, 1
  496.                         ButtonSetState 2, 2
  497.                     CASE 1
  498.                         currButton = 0
  499.                         currEditField = 1
  500.                     CASE 2
  501.                         currButton = 1
  502.                         pushButton = 1
  503.                         ButtonSetState 1, 2
  504.                         ButtonSetState 2, 1
  505.                 END SELECT
  506.             CASE 9                                      ' escape
  507.                 pushButton = 2
  508.                 finished = TRUE
  509.             CASE 14                                     ' space bar
  510.                 IF currButton <> 0 THEN
  511.                     finished = TRUE
  512.                 END IF
  513.         END SELECT
  514.  
  515.         ' simple error checking before finishing
  516.         IF finished = TRUE AND pushButton = 1 THEN
  517.             temp$ = EditFieldInquire$(1)
  518.             ' must specify a file
  519.             IF temp$ = "" THEN
  520.                 PrintError "Must specify a name."
  521.                 finished = FALSE
  522.             ' check if file is valid and can be opened
  523.             ELSE
  524.                 ' open file
  525.                 fileNum% = FREEFILE
  526.                 OPEN temp$ FOR OUTPUT AS fileNum%
  527.  
  528.             END IF
  529.         END IF
  530.     WEND
  531.  
  532.     ' if operation not canceled return file name and file number
  533.     IF pushButton = 1 THEN
  534.         FileName$ = EditFieldInquire$(1)
  535.         GetSaveFile% = fileNum%
  536.     ELSE
  537.         GetSaveFile% = 0
  538.     END IF
  539.  
  540.     WindowClose 1
  541.  
  542.     EXIT FUNCTION
  543.  
  544. ' local error handler
  545. GetSaveError:
  546.       finished = FALSE                              ' don't exit until valid file specified
  547.       CLOSE fileNum%
  548.  
  549.       ShowError ERR                                 ' display errors
  550. RESUME NEXT
  551.  
  552. END FUNCTION
  553.  
  554. '
  555. ' Sub Name: LoadChart
  556. '
  557. ' Description: Loads chart data and settings from the given file.
  558. '
  559. ' Arguments: fileNum%  - file number
  560. '
  561. SUB LoadChart (fileNum%)
  562. SHARED Cat$(), catLen AS INTEGER
  563. SHARED setLen() AS INTEGER, setName$(), setVal!()
  564. SHARED screenMode AS INTEGER, numModes AS INTEGER, mode$()
  565.  
  566. ON LOCAL ERROR GOTO LoadError                       ' handle file loading errors
  567.  
  568.     ' Read file until EOF is reached:
  569.     DO UNTIL EOF(fileNum%)
  570.         ' get data type from file (C=category, V=value, T=title, S=setting):
  571.         INPUT #fileNum%, type$
  572.  
  573.         ' category data
  574.         IF UCASE$(type$) = "C" THEN
  575.             INPUT #fileNum%, catLen
  576.             FOR i% = 1 TO catLen
  577.                 INPUT #fileNum%, Cat$(i%)
  578.             NEXT i%
  579.  
  580.         ' value data
  581.         ELSEIF UCASE$(type$) = "V" THEN
  582.             ' too many sets in file
  583.             IF setNum >= cMaxSets THEN
  584.                 PrintError "Too many data sets in file. Extra sets lost."
  585.                 EXIT DO
  586.             END IF
  587.  
  588.             setNum = setNum + 1
  589.             INPUT #fileNum%, setName$(setNum)         ' get set name
  590.             INPUT #fileNum%, setLen(setNum)           ' get set length
  591.             FOR i% = 1 TO setLen(setNum)
  592.                 INPUT #fileNum%, setVal!(i%, setNum)  ' get set values
  593.             NEXT i%
  594.  
  595.         ' title data
  596.         ELSEIF UCASE$(type$) = "T" THEN
  597.             INPUT #fileNum%, CEnv.MainTitle.title
  598.             INPUT #fileNum%, CEnv.SubTitle.title
  599.             INPUT #fileNum%, CEnv.XAxis.AxisTitle.title
  600.             INPUT #fileNum%, CEnv.YAxis.AxisTitle.title
  601.  
  602.         ' chart settings
  603.         ELSEIF UCASE$(type$) = "S" THEN
  604.             INPUT #fileNum%, screenMode
  605.             ' test for valid screen mode
  606.             valid = FALSE
  607.             FOR i = 1 TO numModes
  608.                 IF screenMode = VAL(mode$(i)) THEN valid = TRUE
  609.             NEXT i
  610.             IF NOT valid THEN
  611.                 IF mode$(1) = "13" THEN
  612.                     screenMode = VAL(mode$(2))
  613.                 ELSE
  614.                     screenMode = VAL(mode$(1))
  615.                 END IF
  616.             END IF
  617.  
  618.             INPUT #fileNum%, CEnv.ChartType, CEnv.ChartStyle, CEnv.DataFont
  619.  
  620.             INPUT #fileNum%, CEnv.ChartWindow.X1, CEnv.ChartWindow.Y1, CEnv.ChartWindow.X2, CEnv.ChartWindow.Y2
  621.             INPUT #fileNum%, CEnv.ChartWindow.Background, CEnv.ChartWindow.border, CEnv.ChartWindow.BorderStyle, CEnv.ChartWindow.BorderColor
  622.             INPUT #fileNum%, CEnv.DataWindow.X1, CEnv.DataWindow.Y1, CEnv.DataWindow.X2, CEnv.DataWindow.Y2
  623.             INPUT #fileNum%, CEnv.DataWindow.Background, CEnv.DataWindow.border, CEnv.DataWindow.BorderStyle, CEnv.DataWindow.BorderColor
  624.  
  625.             INPUT #fileNum%, CEnv.MainTitle.TitleFont, CEnv.MainTitle.TitleColor, CEnv.MainTitle.Justify
  626.             INPUT #fileNum%, CEnv.SubTitle.TitleFont, CEnv.SubTitle.TitleColor, CEnv.SubTitle.Justify
  627.  
  628.             INPUT #fileNum%, CEnv.XAxis.Grid, CEnv.XAxis.GridStyle, CEnv.XAxis.AxisColor, CEnv.XAxis.Labeled
  629.             INPUT #fileNum%, CEnv.XAxis.AxisTitle.TitleFont, CEnv.XAxis.AxisTitle.TitleColor, CEnv.XAxis.AxisTitle.Justify
  630.             INPUT #fileNum%, CEnv.XAxis.RangeType, CEnv.XAxis.LogBase, CEnv.XAxis.AutoScale, CEnv.XAxis.ScaleMin
  631.             INPUT #fileNum%, CEnv.XAxis.ScaleMax, CEnv.XAxis.ScaleFactor, CEnv.XAxis.TicFont, CEnv.XAxis.TicInterval, CEnv.XAxis.TicFormat, CEnv.XAxis.TicDecimals
  632.             INPUT #fileNum%, CEnv.XAxis.ScaleTitle.title
  633.             INPUT #fileNum%, CEnv.XAxis.ScaleTitle.TitleFont, CEnv.XAxis.ScaleTitle.TitleColor, CEnv.XAxis.ScaleTitle.Justify
  634.  
  635.             INPUT #fileNum%, CEnv.YAxis.Grid, CEnv.YAxis.GridStyle, CEnv.YAxis.AxisColor, CEnv.YAxis.Labeled
  636.             INPUT #fileNum%, CEnv.YAxis.AxisTitle.TitleFont, CEnv.YAxis.AxisTitle.TitleColor, CEnv.YAxis.AxisTitle.Justify
  637.             INPUT #fileNum%, CEnv.YAxis.RangeType, CEnv.YAxis.LogBase, CEnv.YAxis.AutoScale, CEnv.YAxis.ScaleMin
  638.             INPUT #fileNum%, CEnv.YAxis.ScaleMax, CEnv.YAxis.ScaleFactor, CEnv.YAxis.TicFont, CEnv.YAxis.TicInterval, CEnv.YAxis.TicFormat, CEnv.YAxis.TicDecimals
  639.             INPUT #fileNum%, CEnv.YAxis.ScaleTitle.title
  640.             INPUT #fileNum%, CEnv.YAxis.ScaleTitle.TitleFont, CEnv.YAxis.ScaleTitle.TitleColor, CEnv.YAxis.ScaleTitle.Justify
  641.  
  642.             INPUT #fileNum%, CEnv.Legend.Legend, CEnv.Legend.Place, CEnv.Legend.TextColor, CEnv.Legend.TextFont, CEnv.Legend.AutoSize
  643.             INPUT #fileNum%, CEnv.Legend.LegendWindow.X1, CEnv.Legend.LegendWindow.Y1, CEnv.Legend.LegendWindow.X2, CEnv.Legend.LegendWindow.Y2
  644.             INPUT #fileNum%, CEnv.Legend.LegendWindow.Background, CEnv.Legend.LegendWindow.border, CEnv.Legend.LegendWindow.BorderStyle, CEnv.Legend.LegendWindow.BorderColor
  645.         ELSE
  646.             GOSUB LoadError
  647.         END IF
  648.     LOOP
  649.  
  650.     ' close the file
  651.     CLOSE fileNum%
  652.  
  653.     ' clear any font pointers that don't map to current fonts
  654.     ClearFonts
  655.  
  656.     ' initialize color list depending on newly loaded screen mode
  657.     InitColors
  658.  
  659.     EXIT SUB
  660.  
  661. ' handle any file format errors
  662. LoadError:
  663.  
  664.     IF ERR THEN
  665.         ShowError ERR
  666.     ELSE
  667.         PrintError "Invalid file format.  Can't continue loading."
  668.     END IF
  669.  
  670.     CLOSE fileNum%                              ' close and exit
  671.     EXIT SUB
  672.  
  673. RESUME NEXT
  674.  
  675. END SUB
  676.  
  677. '
  678. ' Sub Name: OpenChart
  679. '
  680. ' Description: Handles both the "New" and "Open" operations from the
  681. '              "File" menu title.
  682. '
  683. ' Arguments: newFlag - flag for determining which operation (New or Open)
  684. '                      to perform.
  685. '
  686. SUB OpenChart (newFlag)
  687. SHARED saveFile$
  688.  
  689.     ' allow user to save current chart if necessary
  690.     IF chartChanged THEN
  691.         a$ = "|"
  692.         a$ = a$ + "Current chart has not been saved.  Save now?"
  693.  
  694.         status = Alert(4, a$, 8, 15, 12, 65, "Yes", "No", "Cancel")
  695.  
  696.         ' save current chart
  697.         IF status = OK THEN
  698.             status = SaveChart(saveFile$, FALSE)
  699.         END IF
  700.     ELSE
  701.         status = OK
  702.     END IF
  703.  
  704.     IF status <> CANCEL THEN
  705.         ' New option chosen so clear existing data, leave chart settings alone.
  706.         IF newFlag = TRUE THEN
  707.             MenuItemToggle GALLERYTITLE, CEnv.ChartType
  708.             IF CEnv.ChartType = cPie THEN
  709.                 MenuSetState CHARTTITLE, 4, 1
  710.                 MenuSetState CHARTTITLE, 5, 1
  711.                 MenuSetState TITLETITLE, 3, 1
  712.                 MenuSetState TITLETITLE, 4, 1
  713.             END IF
  714.             InitChart
  715.             saveFile$ = ""
  716.         ' Open operation chosen so get file and load data
  717.         ELSE
  718.             fileNum% = GetLoadFile(saveFile$)
  719.             ' if no errors opening file and operation not canceled then load data
  720.             IF fileNum <> 0 THEN
  721.                 ' reset menu bar to nothing selected
  722.                 MenuItemToggle GALLERYTITLE, CEnv.ChartType
  723.                 IF CEnv.ChartType = cPie THEN
  724.                     MenuSetState CHARTTITLE, 4, 1
  725.                     MenuSetState CHARTTITLE, 5, 1
  726.                     MenuSetState TITLETITLE, 3, 1
  727.                     MenuSetState TITLETITLE, 4, 1
  728.                 END IF
  729.  
  730.                 ClearData                       'clear current data
  731.  
  732.                 setNum = 0
  733.                 LoadChart fileNum%             ' load the data
  734.                 
  735.                 ' set menu bar according to new chart settings
  736.                 MenuItemToggle GALLERYTITLE, CEnv.ChartType
  737.                 IF CEnv.ChartType = cPie THEN
  738.                     MenuSetState CHARTTITLE, 4, 0
  739.                     MenuSetState CHARTTITLE, 5, 0
  740.                     MenuSetState TITLETITLE, 3, 0
  741.                     MenuSetState TITLETITLE, 4, 0
  742.                 END IF
  743.  
  744.                 ' new chart not changed
  745.                 chartChanged = FALSE
  746.  
  747.                 ' chart data exists so allow user to view chart
  748.                 IF setNum > 0 THEN
  749.                     MenuSetState VIEWTITLE, 2, 1
  750.                 END IF
  751.             END IF
  752.         END IF
  753.     END IF
  754.  
  755. END SUB
  756.  
  757. '
  758. ' Sub Name: PrintError
  759. '
  760. ' Description: Prints error messages on the screen in an Alert box.
  761. '
  762. ' Arguments: text$ - error message
  763. '
  764. SUB PrintError (text$)
  765.  
  766.     textLen = LEN(text$) + 2
  767.     lefCol = ((80 - textLen) / 2) - 1
  768.     a$ = "| " + text$
  769.     junk = Alert(4, a$, 8, lefCol, 12, textLen + lefCol, "", "", "")
  770.  
  771. END SUB
  772.  
  773. '
  774. ' Func Name: SaveChart
  775. '
  776. ' Description: Performs both the "Save" and "Save AS" operations from
  777. '              the "File" menu title.  If "Save As" was chosen or if
  778. '              "Save" was chosen and no save file has been previously
  779. '              specified, it prompts the user for a new file in
  780. '              which to save the current chart.  Also returns the status of
  781. '              save operation for use in other routines
  782. '
  783. ' Arguments: fileName$ - name of previously specified save file (may be nil)
  784. '            saveAsFlag - flag for invoking the "Save As" operation.
  785. '
  786. FUNCTION SaveChart% (FileName$, saveAsFlag)
  787. SHARED Cat$(), catLen AS INTEGER
  788. SHARED setLen() AS INTEGER, setName$(), setVal!()
  789. SHARED screenMode AS INTEGER
  790.  
  791. ON LOCAL ERROR GOTO SaveError                   ' handle file errors
  792.  
  793.     ' get new file name if necessary
  794.     IF FileName$ = "" OR saveAsFlag THEN
  795.         fileNum% = GetSaveFile(FileName$)
  796.     ' otherwise just open the file
  797.     ELSE
  798.         fileNum% = FREEFILE
  799.         OPEN FileName$ FOR OUTPUT AS fileNum%
  800.     END IF
  801.  
  802.     ' quit save if cancel chosen above or error occurred during open.
  803.     IF fileNum% = 0 THEN
  804.         SaveChart% = CANCEL                     ' return status
  805.         EXIT FUNCTION
  806.     END IF
  807.  
  808.     ' save category data
  809.     IF catLen > 0 THEN
  810.         PRINT #fileNum%, "C"
  811.         PRINT #fileNum%, catLen
  812.  
  813.         FOR i% = 1 TO catLen
  814.             PRINT #fileNum%, Cat$(i%)
  815.         NEXT i%
  816.     END IF
  817.  
  818.     ' save value data
  819.     IF setNum > 0 THEN
  820.         FOR j% = 1 TO setNum
  821.             PRINT #fileNum%, "V"
  822.             PRINT #fileNum%, setName$(j%)
  823.             PRINT #fileNum%, setLen(j%)
  824.  
  825.             FOR i% = 1 TO setLen(j%)
  826.                 PRINT #fileNum%, setVal!(i%, j%)
  827.             NEXT i%
  828.         NEXT j%
  829.     END IF
  830.  
  831.     ' save titles
  832.     PRINT #fileNum%, "T"
  833.     PRINT #fileNum%, CEnv.MainTitle.title
  834.     PRINT #fileNum%, CEnv.SubTitle.title
  835.     PRINT #fileNum%, CEnv.XAxis.AxisTitle.title
  836.     PRINT #fileNum%, CEnv.YAxis.AxisTitle.title
  837.  
  838.     'save chart settings
  839.     PRINT #fileNum%, "S"
  840.     PRINT #fileNum%, screenMode
  841.  
  842.     PRINT #fileNum%, CEnv.ChartType, CEnv.ChartStyle, CEnv.DataFont
  843.  
  844.     PRINT #fileNum%, CEnv.ChartWindow.X1, CEnv.ChartWindow.Y1, CEnv.ChartWindow.X2, CEnv.ChartWindow.Y2
  845.     PRINT #fileNum%, CEnv.ChartWindow.Background, CEnv.ChartWindow.border, CEnv.ChartWindow.BorderStyle, CEnv.ChartWindow.BorderColor
  846.     PRINT #fileNum%, CEnv.DataWindow.X1, CEnv.DataWindow.Y1, CEnv.DataWindow.X2, CEnv.DataWindow.Y2
  847.     PRINT #fileNum%, CEnv.DataWindow.Background, CEnv.DataWindow.border, CEnv.DataWindow.BorderStyle, CEnv.DataWindow.BorderColor
  848.  
  849.     PRINT #fileNum%, CEnv.MainTitle.TitleFont, CEnv.MainTitle.TitleColor, CEnv.MainTitle.Justify
  850.     PRINT #fileNum%, CEnv.SubTitle.TitleFont, CEnv.SubTitle.TitleColor, CEnv.SubTitle.Justify
  851.  
  852.     PRINT #fileNum%, CEnv.XAxis.Grid, CEnv.XAxis.GridStyle, CEnv.XAxis.AxisColor, CEnv.XAxis.Labeled
  853.     PRINT #fileNum%, CEnv.XAxis.AxisTitle.TitleFont, CEnv.XAxis.AxisTitle.TitleColor, CEnv.XAxis.AxisTitle.Justify
  854.     PRINT #fileNum%, CEnv.XAxis.RangeType, CEnv.XAxis.LogBase, CEnv.XAxis.AutoScale, CEnv.XAxis.ScaleMin
  855.     PRINT #fileNum%, CEnv.XAxis.ScaleMax, CEnv.XAxis.ScaleFactor, CEnv.XAxis.TicFont, CEnv.XAxis.TicInterval, CEnv.XAxis.TicFormat, CEnv.XAxis.TicDecimals
  856.     PRINT #fileNum%, CEnv.XAxis.ScaleTitle.title
  857.     PRINT #fileNum%, CEnv.XAxis.ScaleTitle.TitleFont, CEnv.XAxis.ScaleTitle.TitleColor, CEnv.XAxis.ScaleTitle.Justify
  858.  
  859.     PRINT #fileNum%, CEnv.YAxis.Grid, CEnv.YAxis.GridStyle, CEnv.YAxis.AxisColor, CEnv.YAxis.Labeled
  860.     PRINT #fileNum%, CEnv.YAxis.AxisTitle.TitleFont, CEnv.YAxis.AxisTitle.TitleColor, CEnv.YAxis.AxisTitle.Justify
  861.     PRINT #fileNum%, CEnv.YAxis.RangeType, CEnv.YAxis.LogBase, CEnv.YAxis.AutoScale, CEnv.YAxis.ScaleMin
  862.     PRINT #fileNum%, CEnv.YAxis.ScaleMax, CEnv.YAxis.ScaleFactor, CEnv.YAxis.TicFont, CEnv.YAxis.TicInterval, CEnv.YAxis.TicFormat, CEnv.YAxis.TicDecimals
  863.     PRINT #fileNum%, CEnv.YAxis.ScaleTitle.title
  864.     PRINT #fileNum%, CEnv.YAxis.ScaleTitle.TitleFont, CEnv.YAxis.ScaleTitle.TitleColor, CEnv.YAxis.ScaleTitle.Justify
  865.         
  866.     PRINT #fileNum%, CEnv.Legend.Legend, CEnv.Legend.Place, CEnv.Legend.TextColor, CEnv.Legend.TextFont, CEnv.Legend.AutoSize
  867.     PRINT #fileNum%, CEnv.Legend.LegendWindow.X1, CEnv.Legend.LegendWindow.Y1, CEnv.Legend.LegendWindow.X2, CEnv.Legend.LegendWindow.Y2
  868.     PRINT #fileNum%, CEnv.Legend.LegendWindow.Background, CEnv.Legend.LegendWindow.border, CEnv.Legend.LegendWindow.BorderStyle, CEnv.Legend.LegendWindow.BorderColor
  869.  
  870.     CLOSE fileNum%
  871.  
  872.     SaveChart% = OK                             ' return status
  873.  
  874.     chartChanged = FALSE                        ' reset global change flag
  875.  
  876.     EXIT FUNCTION
  877.  
  878. ' local error handler
  879. SaveError:
  880.       SaveChart% = CANCEL                       ' return cancel status
  881.       CLOSE fileNum%
  882.  
  883.       ShowError ERR                             ' display error message
  884.  
  885.       EXIT FUNCTION                             ' exit on error
  886. RESUME NEXT
  887.  
  888. END FUNCTION
  889.  
  890. '
  891. ' Sub Name: ShowError
  892. '
  893. ' Description: Displays an appropriate error message for the given error
  894. '
  895. ' Arguments: errorNum - error number
  896. '
  897. SUB ShowError (errorNum)
  898.       SELECT CASE errorNum
  899.         CASE 6:                                 ' overflow
  900.             PrintError "Overflow occurred."
  901.         CASE 14:                                ' out of space
  902.             PrintError "Out of string space.  Please restart."
  903.         CASE 53:                                ' file not found
  904.             PrintError "File not found."
  905.         CASE 62:                                ' input past end of file
  906.             PrintError "Invalid file format. Can't continue loading."
  907.         CASE 64:                                ' bad file name
  908.             PrintError "Invalid file name."
  909.         CASE 68:                                ' device unavailable
  910.             PrintError "Selected device unavailable."
  911.         CASE 71:                                ' disk not ready
  912.             PrintError "Disk not ready."
  913.         CASE 75:                                ' path access error
  914.             PrintError "Invalid path."
  915.         CASE 76:                                ' path not found
  916.             PrintError "Path not found."
  917.         CASE ELSE                               ' catch all
  918.             PrintError "BASIC error #" + LTRIM$(STR$(ERR)) + " occurred."
  919.      END SELECT
  920.  
  921.  
  922. END SUB
  923.  
  924. '
  925. ' Sub Name: ViewData
  926. '
  927. ' Description: Displays the current chart data and allows the user to
  928. '              modify, delete or add to that data.
  929. '
  930. ' Arguments: none
  931. '
  932. SUB ViewData
  933. SHARED setVal!(), setLen()  AS INTEGER, setName$()
  934. SHARED Cat$(), catLen AS INTEGER
  935. SHARED GloEdit() AS EditFieldType
  936.  
  937.     ' temporary data storage that allows user to cancel all changes and
  938.     ' restore original data
  939.     DIM tsetVal$(1 TO 15, 1 TO 15), tCat$(1 TO 15), tsetName$(1 TO 15)
  940.     DIM tsetNum AS INTEGER
  941.     DIM tsetLen(1 TO 15) AS INTEGER
  942.     DIM tcatLen  AS INTEGER
  943.  
  944.     ON LOCAL ERROR GOTO ViewDatError
  945.  
  946.     ' fill out temp data
  947.     FOR i = 1 TO cMaxSets
  948.         tsetName$(i) = setName$(i)
  949.         tCat$(i) = Cat$(i)
  950.         tsetLen(i) = setLen(i)
  951.         FOR j = 1 TO tsetLen(i)
  952.             tsetVal$(j, i) = LTRIM$(STR$(setVal!(j, i)))
  953.         NEXT j
  954.         FOR j = tsetLen(i) + 1 TO cMaxValues
  955.             tsetVal$(j, i) = ""
  956.         NEXT j
  957.     NEXT i
  958.     tsetNum = setNum
  959.     tcatLen = catLen
  960.  
  961.     ' set up window
  962.     winRow = 4
  963.     winCol = 8
  964.     WindowOpen 1, winRow, winCol, 23, 74, 0, 7, 0, 7, 15, FALSE, FALSE, FALSE, TRUE, 2, "Chart Data"
  965.     WindowLocate 1, 2
  966.     WindowPrint 2, "Series Name:"
  967.     WindowBox 2, 2, 18, 24
  968.     WindowLocate 1, 26
  969.     WindowPrint 2, "Categories:"
  970.     WindowBox 2, 26, 18, 48
  971.     WindowLocate 1, 50
  972.     WindowPrint 2, "Values:"
  973.     WindowBox 2, 50, 18, 66
  974.     WindowLine 19
  975.  
  976.     ' display chart data
  977.     FOR i = 1 TO 15
  978.         IF i < 10 THEN
  979.             a$ = " "
  980.         ELSE
  981.             a$ = ""
  982.         END IF
  983.         a$ = a$ + LTRIM$(STR$(i)) + ". "
  984.         WindowLocate i + 2, 3
  985.         WindowPrint 2, a$ + tsetName$(i)
  986.         WindowLocate i + 2, 27
  987.         WindowPrint 2, a$ + tCat$(i)
  988.         WindowLocate i + 2, 51
  989.         WindowPrint 2, a$ + MID$(tsetVal$(i, 1), 1, 10)
  990.     NEXT i
  991.     ' highlight first set name
  992.     EditFieldOpen 1, tsetName$(1), 3, 7, 7, 0, 17, 16
  993.  
  994.     IF tsetNum < cMaxSets THEN tsetNum = tsetNum + 1
  995.     IF tcatLen < cMaxValues THEN tcatLen = tcatLen + 1
  996.     IF tsetLen(1) < cMaxValues THEN tsetLen(1) = tsetLen(1) + 1
  997.  
  998.     ' area buttons
  999.     ButtonOpen 1, 1, "", 3, 3, 17, 23, 4
  1000.     ButtonOpen 2, 1, "", 3, 27, 17, 47, 4
  1001.     ButtonOpen 3, 1, "", 3, 51, 17, 65, 4
  1002.  
  1003.     ' command buttons
  1004.     ButtonOpen 4, 1, "OK", 20, 15, 0, 0, 1
  1005.     ButtonOpen 5, 1, "Cancel", 20, 45, 0, 0, 1
  1006.  
  1007.     ' start with cursor in first set name edit field
  1008.     currButton = 1
  1009.     prevButton = 1
  1010.     currRow = 1
  1011.     currEditField = 1
  1012.     currCat = 1
  1013.     currVal = 1
  1014.     currSet = 1
  1015.  
  1016.     IF CEnv.ChartType = cPie THEN
  1017.         a$ = " Pie chart information||"
  1018.         a$ = a$ + " Only data values from the first series are plotted in pie charts. |"
  1019.         a$ = a$ + " Data values from the second series are used in determining whether|"
  1020.         a$ = a$ + " or not pie pieces are exploded.  Non-zero values in this series   |"
  1021.         a$ = a$ + " will cause corresponding pie pieces to be exploded.  All other    |"
  1022.         a$ = a$ + "  series will be ignored.                                           "
  1023.  
  1024.         junk = Alert(4, a$, 8, 7, 17, 75, "", "", "")
  1025.     END IF
  1026.  
  1027.     ' window control loop
  1028.     finished = FALSE
  1029.     WHILE NOT finished
  1030.         WindowDo currButton, currEditField
  1031.  
  1032.         SELECT CASE Dialog(0)
  1033.             CASE 1                                      ' button pressed
  1034.                 currButton = Dialog(1)
  1035.                 SELECT CASE currButton
  1036.                     CASE 1, 2, 3
  1037.                         currRow = Dialog(17)
  1038.                     CASE 4, 5
  1039.                         finished = TRUE
  1040.                 END SELECT
  1041.                 GOSUB UpdateEdit
  1042.             CASE 2                                      ' Edit Field
  1043.                 currEditField = Dialog(2)
  1044.             CASE 6, 11                                  ' enter, down arrow
  1045.                 IF currButton > 3 AND Dialog(0) = 6 THEN
  1046.                     finished = TRUE
  1047.                 ELSE
  1048.                     currRow = currRow + 1
  1049.                     GOSUB UpdateEdit
  1050.                 END IF
  1051.             CASE 7                                      'tab
  1052.                 SELECT CASE currButton
  1053.                     CASE 1:
  1054.                         currButton = 2
  1055.                         currRow = currCat
  1056.                         GOSUB UpdateEdit
  1057.                     CASE 2:
  1058.                         currButton = 3
  1059.                         currRow = currVal
  1060.                         GOSUB UpdateEdit
  1061.                     CASE 3:
  1062.                         currButton = 4
  1063.                         ButtonToggle 4
  1064.                         GOSUB UpdateEdit
  1065.                     CASE 4:
  1066.                         currButton = 5
  1067.                         ButtonToggle 4
  1068.                         ButtonToggle 5
  1069.                     CASE 5:
  1070.                         currButton = 1
  1071.                         currRow = currSet
  1072.                         ButtonToggle 5
  1073.                         GOSUB UpdateEdit
  1074.                 END SELECT
  1075.             CASE 8                                      'back tab
  1076.                 SELECT CASE currButton
  1077.                     CASE 1:
  1078.                         currButton = 5
  1079.                         ButtonToggle 5
  1080.                         GOSUB UpdateEdit
  1081.                     CASE 2:
  1082.                         currButton = 1
  1083.                         currRow = currSet
  1084.                         GOSUB UpdateEdit
  1085.                     CASE 3:
  1086.                         currButton = 2
  1087.                         currRow = currCat
  1088.                         GOSUB UpdateEdit
  1089.                     CASE 4:
  1090.                         currButton = 3
  1091.                         currRow = currVal
  1092.                         ButtonToggle 4
  1093.                         GOSUB UpdateEdit
  1094.                     CASE 5:
  1095.                         currButton = 4
  1096.                         ButtonToggle 5
  1097.                         ButtonToggle 4
  1098.                 END SELECT
  1099.             CASE 9                                      'escape
  1100.                 currButton = 5
  1101.                 finished = TRUE
  1102.             CASE 10:                                    'up arrow
  1103.                 IF currButton < 4 THEN
  1104.                     currRow = currRow - 1
  1105.                     GOSUB UpdateEdit
  1106.                 END IF
  1107.             CASE 14                                     'space
  1108.                 IF currButton > 3 THEN finished = TRUE
  1109.         END SELECT
  1110.  
  1111.         ' give delete warning before exit
  1112.         IF finished = TRUE AND currButton = 4 THEN
  1113.             temp = FALSE
  1114.             FOR i = 1 TO tsetNum
  1115.                 IF tsetName$(i) = "" AND tsetLen(i) > 0 AND NOT (tsetLen(i) = 1 AND tsetVal$(1, i) = "") THEN temp = TRUE
  1116.             NEXT i
  1117.             IF temp = TRUE THEN
  1118.                 a$ = "|"
  1119.                 a$ = a$ + "Series without names will be deleted upon exit."
  1120.                 reply = Alert(4, a$, 8, 10, 12, 70, "OK", "Cancel", "")
  1121.                 IF reply <> 1 THEN finished = FALSE
  1122.             END IF
  1123.         END IF
  1124.     WEND
  1125.  
  1126.     ' finished so save new data
  1127.     IF currButton = 4 THEN
  1128.         ClearData                                       ' clear existing data
  1129.  
  1130.         ' copy temporary values to permanent locations
  1131.         indx = 0
  1132.         FOR i = 1 TO tsetNum
  1133.             IF tsetName$(i) <> "" THEN
  1134.                 indx = indx + 1
  1135.                 setName$(indx) = tsetName$(i)              ' store set names
  1136.                 indx2 = 0
  1137.                 FOR j = 1 TO tsetLen(i)
  1138.                     IF tsetVal$(j, i) <> "" THEN
  1139.                         indx2 = indx2 + 1
  1140.                         setVal!(indx2, i) = VAL(tsetVal$(j, i))   ' store set values
  1141.                     END IF
  1142.                 NEXT j
  1143.                 setLen(indx) = indx2                     ' get set lengths
  1144.             END IF
  1145.         NEXT i
  1146.         setNum = indx
  1147.  
  1148.         ' clear leftover names and set lengths
  1149.         FOR i = setNum + 1 TO cMaxSets
  1150.             setName$(i) = ""
  1151.             setLen(i) = 0
  1152.         NEXT i
  1153.  
  1154.         ' store category names
  1155.         FOR i = 1 TO tcatLen
  1156.             Cat$(i) = tCat$(i)
  1157.         NEXT i
  1158.         catLen = tcatLen
  1159.  
  1160.         FOR i = tcatLen TO 1 STEP -1
  1161.             IF Cat$(i) = "" THEN
  1162.                 catLen = catLen - 1
  1163.                 IF catLen <= 0 THEN EXIT FOR
  1164.             ELSE
  1165.                 EXIT FOR
  1166.             END IF
  1167.         NEXT i
  1168.  
  1169.         ' clear leftover category names
  1170.         FOR i = catLen + 1 TO cMaxValues
  1171.             Cat$(i) = ""
  1172.         NEXT i
  1173.  
  1174.         ' update active menu titles based on current data
  1175.         IF setNum > 0 THEN
  1176.             MenuSetState VIEWTITLE, 2, 1
  1177.             chartChanged = TRUE
  1178.         ELSE
  1179.             MenuSetState VIEWTITLE, 2, 0
  1180.         END IF
  1181.     END IF
  1182.     WindowClose 1
  1183.  
  1184.  
  1185.     EXIT SUB
  1186.  
  1187. ViewDatError:
  1188.     PrintError "BASIC error #" + LTRIM$(STR$(ERR)) + " occurred."
  1189. RESUME NEXT
  1190.  
  1191. ' redraws the value edit column so it displays the current set's values
  1192. ResetVal:
  1193.     ' display new values
  1194.     FOR i = 1 TO cMaxValues
  1195.         WindowLocate i + 2, 55
  1196.         WindowPrint 2, tsetVal$(i, currSet) + STRING$(10 - LEN(tsetVal$(i, currSet)), " ")
  1197.     NEXT i
  1198.  
  1199.     IF tsetLen(currSet) = 0 THEN
  1200.         tsetLen(currSet) = tsetLen(currSet) + 1
  1201.     ELSEIF tsetLen(currSet) < cMaxValues AND tsetVal$(tsetLen(currSet), currSet) <> "" THEN
  1202.         tsetLen(currSet) = tsetLen(currSet) + 1
  1203.     END IF
  1204.  
  1205.     currVal = 31
  1206.  
  1207. RETURN
  1208.  
  1209. UpdateEdit:
  1210.     IF prevButton < 4 THEN GOSUB ClosePrevEdit
  1211.  
  1212.     SELECT CASE currButton
  1213.         CASE 1:
  1214.             IF currRow <= 0 THEN
  1215.                 currRow = tsetNum
  1216.             ELSEIF currRow > 15 THEN
  1217.                 currRow = 1
  1218.             ELSEIF currRow = tsetNum + 1 AND tsetName$(tsetNum) <> "" THEN
  1219.                 tsetNum = tsetNum + 1
  1220.             ELSEIF currRow > tsetNum THEN
  1221.                 currRow = 1
  1222.             END IF
  1223.             WindowColor 0, 7
  1224.             WindowLocate currSet + 2, 7
  1225.             WindowPrint 2, tsetName$(currSet) + STRING$(17 - LEN(tsetName$(currSet)), " ")
  1226.  
  1227.             FG = 7
  1228.             BG = 0
  1229.             vislen = 17
  1230.             totlen = 16
  1231.             currSet = currRow
  1232.             currCol = 7
  1233.             temp$ = tsetName$(currSet)
  1234.             IF prevButton = 1 THEN GOSUB ResetVal
  1235.         CASE 2:
  1236.             IF currRow <= 0 THEN
  1237.                 currRow = tcatLen
  1238.             ELSEIF currRow > 15 THEN
  1239.                 currRow = 1
  1240.             ELSEIF currRow > tcatLen THEN
  1241.                 tcatLen = currRow
  1242.             END IF
  1243.             FG = 0
  1244.             BG = 7
  1245.             vislen = 17
  1246.             totlen = 16
  1247.             currCat = currRow
  1248.             currCol = 31
  1249.             temp$ = tCat$(currCat)
  1250.         CASE 3:
  1251.             IF currRow <= 0 THEN
  1252.                 currRow = tsetLen(currSet)
  1253.             ELSEIF currRow > 15 THEN
  1254.                 currRow = 1
  1255.             ELSEIF currRow = tsetLen(currSet) + 1 AND tsetVal$(tsetLen(currSet), currSet) <> "" AND currRow THEN
  1256.                 tsetLen(currSet) = tsetLen(currSet) + 1
  1257.             ELSEIF currRow > tsetLen(currSet) THEN
  1258.                 currRow = 1
  1259.             END IF
  1260.             FG = 0
  1261.             BG = 7
  1262.             vislen = 11
  1263.             totlen = 20
  1264.             currVal = currRow
  1265.             currCol = 55
  1266.             temp$ = tsetVal$(currVal, currSet)
  1267.         CASE ELSE
  1268.             prevButton = currButton
  1269.             RETURN
  1270.     END SELECT
  1271.  
  1272.     EditFieldOpen 1, temp$, currRow + 2, currCol, FG, BG, vislen, totlen
  1273.     currEditField = 1
  1274.     prevButton = currButton
  1275. RETURN
  1276.  
  1277. ClosePrevEdit:
  1278.     temp$ = RTRIM$(EditFieldInquire$(1))
  1279.     EditFieldClose 1
  1280.     currEditField = 0
  1281.     IF prevButton = 1 THEN
  1282.         WindowColor 7, 0
  1283.     ELSE
  1284.         WindowColor 0, 7
  1285.     END IF
  1286.  
  1287.     SELECT CASE prevButton
  1288.         CASE 1:
  1289.             tsetName$(currSet) = temp$
  1290.             temp$ = temp$ + STRING$(17 - LEN(temp$), " ")
  1291.             editRow = currSet + 2
  1292.             editCol = 7
  1293.         CASE 2:
  1294.             tCat$(currCat) = temp$
  1295.             editRow = currCat + 2
  1296.             editCol = 31
  1297.         CASE 3:
  1298.             tsetVal$(currVal, currSet) = temp$
  1299.             tval# = VAL(temp$)
  1300.             IF tval# = 0 AND temp$ <> "0" AND LEN(RTRIM$(temp$)) <> 0 THEN
  1301.                 PrintError "Warning: Non-numeric values will default to zero for charting."
  1302.             END IF
  1303.             temp$ = MID$(temp$, 1, 10)
  1304.             editRow = currVal + 2
  1305.             editCol = 55
  1306.     END SELECT
  1307.  
  1308.     WindowLocate editRow, editCol
  1309.     WindowPrint 2, temp$
  1310.     WindowColor 0, 7
  1311. RETURN
  1312.  
  1313. END SUB
  1314.  
  1315.