64 <P1
<p#10
<L2
<POJL
Wolstrup article: Soccer SecretaryPage ###
<PEJL
Wolstrup article: Soccer SecretaryPage ###
<jC
Items of interest to programmers:
<JB

Line 5 loads A$ with the code for the pointing finger, usingspecial characters. We use CHR$(21) to toggle on the specialcharacter mode. (line 10). As soon as we have printed A$, we goahead and toggle the mode off, otherwise next time we reach line10, the mode would be toggled off, producing space compression codes in A$, and we would have a very messy screen display.
The default of the Model 4 cursor is ON. This can be very irritating, especially when erasing lines. Therefore we use the cursor OFF, CHR$(15) as the normal mode in the program. (Line 15). Only when a keyboard INPUT is needed, do we toggle the cursor ON, using CHR$(14).
Lines 4-110: Housekeeping and main menu.
200-240: Subroutines.
Note that Soccer Secretary uses a formatted screen input instead of scrolling, leaving the display clean and crisp. Doingso entails erasure and overwrites of particular lines on the screen. Lines 220 and 230 takes care of the erasing of those lines.
1000-1220: Option 1 from menu. Organize divisions.
1005: Activate error trap to spot file written to a drive without a disk.
1010: Input filename. If no data, go back to menu. If data, make sure filename is 8 characters or less.
1015: Check if filename has extension. Check if 1st characteris lower than upper case A or larger than lower case z. Disallowif any of these 3 conditions occur.
1016: Check if 1st character of filename is CHR$(91) to CHR$(96). Disallow if true.
1050: Prompt for amount of teams in division. If no data, erase line and go back and prompt for filename.
1060 Check if amount of teams is 2 or more and does not exceed the maximum of 10.
Note that all numeric inputs are handled by using string variables and then converted to a numeric. This is done to make sure faulty input will not display the computer generated error message 'Redo' on the screen.
1080: Loop to input team names one at a time. If any input contain no data, set up escape routine so we can leave the loop naturally.
Note, that in the newer versions of Microsoft Basic, only oneNEXT is allowed for each FOR. Therefore we set a flag (FL) to 1 so we can make a decision in the next line. Also, to make sure that we leave the loop naturally, we fool the computer into thinking we have completed the loop by loading the end value (N)into the loopcounter (X).
1090: If the flag is set (1), we are now out of the loop and the rest of the line is read, and we go back and prompt for the amount of teams in the division.
If the flag is not set (0), we did not try to escape, so we merely do a NEXT X.
1110: Editing of team names.
Display the teams vertically on the screen starting at LOcation 320.
Note that when the loop counter (X) is done, the value is 1 more than the amount of teams. Therefore incrementing X by 1 again (X=X+1) makes X two larger than the amount of teams. This is done so that in the next line the prompt will be printed 2 lines down from the last team.
1120: Prompt for team number to edit. If input contains no data, escape to beginning of module.
1130: Check if input is string value "0". If so, everything is correct and proceed to line 1200. If not "0" convert input toa numeric.
1140: Check if numeric is within the legal range. If so, proceed with editing, then go back to beginning of edit routine.If not, go back to line 1120.
1210: Save team names and beginning stats to disk, using filename chosen earlier.
Note that the first value we save to the file is the amount of teams (N). This way we can let the file take care of itself rather than use EOF.
1220: Close file. Create another file to hold scores. Filename will be same as team name/stat file, but with /DAT added. This is why an extension was not allowed earlier. Close file and disable errortrap. Then go back to main menu.
Note that the only thing we save to this file is the number 0. Again, the first data we save to this file, is the amount of scores in the file. Upon creation of the file, obvously no scores are saved, therefore the number 0.
2000: Option 2 from the menu. Enter scores routine.
2005: Set up error trap for nonexisting files.
2010: If input contains no data, escape to menu.
2040: RE is the number of scores. At this point we have no scores in memory, thus RE=0.
2050: Load team names and stats into memory.
2055: Open the score file. Read the number of scores into RE.Check if maximum number of scores (200) is stored in file. If sodo not allow any more to be entered, instead CLOSE file, deactivate error trap and return to menu.
2060: Check if 0 scores in file. If so, CLOSE file and jump to line 2065. If number is larger than 0 and smaller than 200, then we have that many scores. Read Hometeam name into HT$(X), Hometeam goals into HG(X), Awayteam name into AT$(X) and Away team goals into AG(X). Loop until all have been read, then CLOSEfile.
2065: Deactivate error trap.
2070: The array PO(X) is the pointer to the position of the team names and their related stats in the file. PO(X) will be used later on to point to the sorted order, and saved to the disk according to the value of PO(X).
2080: Display team names on screen.
2090: If input to prompt 'number of hometeam' contains no data, escape to beginning of module (2000). If data, convert it to an integer numeric. If it is not within the legal range, go back and prompt again (2090).
2100: Display the hometeam selected.
2110: Set Flag (FL) to 0. If input to prompt 'number of visiting team' contains no data, escape to line 2090. If data, check that visiting team is not the same as the hometeam. If so,go back to 2010.
2115: Check if XX or xx has been entered. If so, awayteam is not listed on screen. It is an out of division/conference team. Set VT$="11" and set flag (FL) to 1. Skip line 2116 by jumping to line 2120.
2116: Check if number of visiting team is within the legal range. If not, go back to line 2090.
2120: Convert VT$ into a numeric. Check if VT is 11. If so, make TM$(11) equal to 'Non-divisional opponent', then prompt forthe teams name. Make VT$(11) equal to *** + team name and display on screen. If VT is not 11, simply display team name on screen.
2125: Check if no data was entered to the Non-divisional input. If so, jump back to line 2090.
2130: Prompt for goals scored by hometeam.
2140: Allow input 2 spaces after the team name. If input contain no data jump back to 2090.
2145: Convert string input into a numeric. Redisplay team name. Check if numeric is smaller than 0. If so, jump back to line 2140.
2147: Display goals 4 spaces to the right of team name.
2150: Prompt for goals scored by visiting team. Allow input 2spaces to the right of the team name. If input contains no data jump back to line 2090.
2160: Convert string input into a numeric. Redisplay team name. Display goals 4 spaces to the right of team name.
2170: Prompt if score is correct.
2180: If not correct, redisplay team names and go back to line 2130.
2190: If input is illegal, jump back to line 2180, otherwise increment RE by 1 so array value is correct. Then transfer data into team name and score array.
2195: If flag (FL) is set (1), hometeam played an out of division/conference team. Therefore only hometeam's stats will be updated. Increment Games Played,GP(HT) by 1. Increment Goals For, GF(HT) by the amount of goals scored by hometeam. IncrementGoals Against, GA(HT) by the amount of goals the visiting team scored against the hometeam.
Now we have 3 possibilities: If G(1) is larger than G(2), thehometeam won the game. Therefore increment Games Won, GW(HT) by 1. Increment Point, PT(HT) by 2.
If G(1) is equal to G(2) then the game was a tie. Therefore increment Games Tied, GT(HT) by 1. Increment Points, PT(HT) by 1.
If G(1) is smaller than G(2), the hometeam lost. Therefore increment Games Lost, GL(HT) by 1. No need to update PT(HT) as no points are awarded for a game lost.
Remember this line is only active when hometeam plays an out of division/conference opponent. This opponent's stats are not updated, as it is of no importance to the standings.
2197: If flag (FL) is set (1), reset it (0) and jump to line 2240.
2200: This line is active when both teams are from within thedivision.
Increment Games Played by hometeam, GP(HT) by 1. Increment games played by visiting team, GP(VT) by 1. Increment Goals For hometeam, GF(HT) by the amount of goals they scored. Increment hometeam's Goals Against, GA(HT) by the amount of goals the visiting teams scored against them. Increment Goals For visitingteam, GF(VT) by the amount of goals they scored. Increment GoalsAgainst visiting team, GA(VT) by the amount of goals the hometeam scored against them.
2210: If G(1) is larger than G(2) then the hometeam won the game. Therefore increment Games Won hometeam, GW(HT) by 1. Increment Games Lost visiting team, GL(VT) by 1. Increment Points hometeam, PT(HT) by 2. Then jump to line 2240.
2220: If G(1) is equal to G(2) then the game was a tie. Therefore increment Games Tied hometeam, GT(HT) by 1. Increment Games Tied visiting team, GT(VT) by 1. Increment Points hometeam, PT(HT) by 1. Increment Points visiting team, PT(VT) by1. Then jump to line 2240.
2230: If G(1) is smaller than G(2) then the hometeam lost thegame. Therefore increment Games Lost, GL(HT) by 1. Increment Games Won visiting team, GW(VT) by 1. Increment Points visiting team, PT(VT) by 1.
2240: Prompt for score of another game.
2300: Sorting on points routine.
Loop through all the teams and store their points in TP(Y) and their goal difference in DG(Y).
2310: Set Y to 1.
2320: Start loop at team Y to last team. If Y is equal to Z then in line 2330 a team would be compared to itself. Avoid thisby jumping to line 2340 and increment Z.
2330: If Points, TP(Y) is smaller than Points, TP(Z) then we swap the points, swap the pointers, PO(Y) and PO(Z) and also thegoal difference, DG(Y) and DG(Z). Notice that we are not changing the arrays holding the team names and the stats. Our purpose is to get PO(Z) to point to the teams in order accordingthe how many points they have. However, because we also are going to sort on Goal difference later, we also have to swap DG(Y) and DG(Z).
2340: Increment Z and return to line 2320 if not done.
2350: If Y is smaller than the last team number in the array,then increment Y by 1 and go back to line 2320.
2360: At this point the point sort is done.
2400: Sorting by goal difference routine. Set Y equal to 1.
2410: Loop from team Y to last team. If Y is equal to Z then in line 2420 team Y would be compared to itself. Avoid this by jumping to line 2430.
2420: This time we want to swap the goal difference, DG(Y) and DG(Z), and the pointers, PO(Y) and PO(Z) ONLY if the teams are even on points.
2430: Increment Z and jump back to line 2410 if not done.
2440: If Y is smaller than the last team number in the array,then increment Y by 1 and go back to line 2410.
Note: The sort is now completed. We can discard DG( ) and TP(). The only important sort array is PO( ). This array now holds the pointer to the standings in descending order.
2490: Display stat headings on screen.
2500: Erase as many lines as needed from location 400.
2510-2530: Display team names and stats according to the pointer array PO( ).
2550-2610: Save sorted team names and stats to disk using pointer array PO( ). Prompt for 1 or more print-outs. Return to menu.
3000: Option 3 from menu. Print standings.
3005: Set error trap to catch non-existant filenames.
3020: Escape to menu if input to filename prompt has no data.
3030: Open file and read team names and stats into arrays. Close file.
3035: Deactivate error trap.
3040: Printer ready prompt.
3050: If {ENTER} was pressed, loop through pointers, PO( ) and set them in ascending order.
3060: Algorithm to find the tab position that will center thefilename. (80 column paper). Number is stored in CT.
3070: Print 2 blank lines. Print centered filename. Print blank line.
3080: Print stat headings.
3090-3120: Print team names and stats.
3125: If flag (FL) was set (1) in line 2590 then reset (0) and return to caller.
3130-3150: Prompt for additional print-outs. Return to menu when none wanted.
3500: Option 4 from menu. Print scores.
3505: Activate error trap to catch non-existant files.
3510: Escape to menu if input to the filename prompt has no data.
3540: Add /DAT extension to filename.
3550: Open file and put number of scores in RE: If RE=0 then we have no scores to print, therefore return to menu.
3560: Loop to read hometeam name, HT$(X), home goals, HG(X), awayteam name, AT$(X), away goals, AG(X) into arrays. Close file.
3565: Deactivate error trap.
3570: Printer prompt.
3580: Check if {ENTER} was pressed. If not, go back to 3580.
3590: Remove extension from filename. Find tab position to center filename.
3600: Print 2 blank lines. Print centered filename. Print blank line.
3610-3630: Loop to print team names and scores.
3640-3660: Prompt for additional copies. When none wanted, return to menu.
4000: Option 6 from menu. View filenames.
Get directory from BASIC using the SYSTEM cmd. When read, return to menu by pressing any key. (Line 4010).
5000: Option 5 from menu. Edit scores module.
5005: Activate error trap to catch non-existant files.
5015: Escape to menu if input to filename prompt has no data.
5040: Add /DAT extension to filename.
5050: Open file and read number of scores into RE. If RE=0, we have no scores to edit. Therefore we go back to menu.
5060-5070: Loop to read hometeam, home goals, away team and away goals into arrays. Close file.
5080: Deactivate error trap.
5100: Loop to erase 10 lines starting at position 400.
5110: If we have less than 11 scores then display them and jump to line 5200.
5120: Set Y=0. Y is the score counter by tens.
5130: XX is the multiplier of 80 to determine the screen position in the next lines. ZZ is the last score of the current screen of scores. Loop to find first score of current screen to 10th score of current screen.
5140: Check if loop counter (X) has exceeded the total numberof scores. If so, to exit loop naturally, set X to end value, then jump to line 5160.
5150-5160: Erase lines, then display screenful of 10 games.
5200: Game edit prompt.
5210: Check for input "0". If so, display next screenful of games. If no more jump to line 5500.
5220: Convert string input to a numeric and check if it is within the legal range.
5230: Change or Delete prompt.
5240: Process "D" input.
5250: Chech for input other than "C".
5270: Change routine. Escape to line 5200 if input to hometeam change prompt contains no data, otherwise load HT$(I) with input.
5280: Escape to line 5200 if input to hometeam's goals scoredcontains no data.
5290 Escape to line 5200 if input to visiting team change contains no data, otherwise load AT$(I) with input.
5300: Escape to line 5200 if input to visiting team's goals contains no data, otherwise load AG(I) with the numeric value ofEX$(2), load HG(I) with the numeric value of EX$(1).
5310: Display teams and score.
5320: Prompt for correct.
5330: Check for not correct.
5340: Check for input other than Y.
5350: Game is correct. End of routine. Jump to 5130 and startover.
5400: Delete record prompt.
5410: Abort if input is other than Y.
5420: If there is only 1 score in RE or if we chose the last score in the file, then simply shorten the file by 1 record and jump to line 5130 to start over.
5430: We chose to delete, and the game is neither the only record in the file nor the last record in the file. Therefore weswap the last record in the file with the record to delete and make the file 1 record shorter. Then we jump to line 5130 to start over.
5500: All changing and deleting is now done. Remove /DAT extension from filename. Open team name/stat file and read into arrays. Close file.
5505: Zero out old stats.
5510: Loop through all scores.
5520: Loop through team names.
5530: Compare to find hometeam. Jump to subroutine in 5900 when found.
5535: Compare to find away team. Jump to subroutine in 5950 if found. Note that if away team is out of division/conference it will not be found and therefore not sent to subroutine to be updated.
5540: End of both loops.
5550: Open filename/DAT file and save games to disk. Close file.
5560: Jump to sort routine in line 2270.
5900: Subroutine to create stats for hometeam. Update Games Played, Goals For and Goals Against for hometeam.
5910: If hometeam scored more goals than away team then hometeam won the game. Therefore update Games Won and Points forhometeam, then return to caller.
5920: If hometeam and away team scored the same amount of goals then the game was a tie. Therefore update Games Tied and Points for hometeam and return to caller.
5930: By default, the hometeam scored less goals than the away team and therefore lost the game. Update Games Lost and return to caller.
5950: Subroutine to create stats for away team. Update Games Played, Goals For and Goals Against for the away team.
5960: If hometeam scored more goals than away team, then awayteam lost. Therefore update Games Lost for away team and return to caller.
5970: If hometeam and away team scored the same amount of goals, the game is a tie. Therefore update Games Tied and Pointsfor away team and return to caller.
5980: If the hometeam scored less goals than the away team, away team won the game. We update the Games Won and Points for the away team, then return to caller.
6000-6040: ON ERROR routines.
7000: Option 7 from menu. Exit program. Erase screen. Enable cursor. End program.
 