- email: russellM_98@yahoo.com
name: Russell Meyers
Comments: Hi Pete,
Here is some code that I copied from a book and for some reason it doesn't work. You have to have ISALES.TXT in the root directory which I pasted below the code. It keeps coming up an error. Maybe you can see something which I've done wrong. Thx.
Here is the code:Code: Select all
' Sales Graph program, ASCII version (SGRAPHA.BAS) ' Displays an ASCII graph of the international ' sales data stored in the ISALES.TXT file. DECLARE SUB Pause () DECLARE SUB ShowGraph () DECLARE SUB ShowData () DECLARE SUB ReadRegionNames () DECLARE SUB ReadSalesFile () DECLARE FUNCTION CountYears% () ' Global constants CONST MaxYears = 5 ' The maximum years in the graph. CONST Regions = 4 ' The number of sales regions. CONST T = 13 ' The tab setting in screen output. ' The global variable recCount represents ' the number of lines of data in ISALES.TXT. DIM SHARED recCount AS INTEGER ' Count the lines, but don't allow ' a greater number than MaxYears. recCount = CountYears% IF recCount > MaxYears THEN recCount = MaxYears ' Global arrays for the data and the graph. DIM SHARED RegionNames(Regions) AS STRING DIM SHARED RegionSymbols(Regions) AS STRING DIM SHARED Years(recCount) AS STRING DIM SHARED Sales(recCount, Regions) AS DOUBLE DIM SHARED Totals(recCount) AS DOUBLE ReadRegionNames ' Read the DATA lines. ReadSalesFile ' Read the ISALES.TXT file. ShowData ' Display the sales data. ShowGraph ' Display the sales graph. END ' SGRAPHA.BAS ' DATA lines contain the names of the four ' regions and the ASCII graphics characters ' that will represent them in the graph. DATA American, 176, European, 177 DATA Asian, 178, Other, 219 ' Error routine. ' Displays a message if the ' data file is missing. NoDataFile: CLS PRINT "Can't find \ISALES.TXT." PRINT "Run the INTRSAL2.BAS program" PRINT "to generate the sales data." END FUNCTION CountYears% ' Count the number of lines in the ' ISALES.TXT file. lCount% = 0 ' Set up an error trap to ' take over in the event of ' a missing file. ON ERROR GOTO NoDataFile OPEN "\ISALES.TXT" FOR INPUT AS #1 ON ERROR GOTO 0 DO WHILE NOT EOF(1) LINE INPUT #1, s$ ' lCount% is the line count. lCount% = lCount% + 1 LOOP CLOSE #1 CountYears% = lCount% END FUNCTION ' CountYears% SUB Pause ' Hold the output on the ' screen until the user ' presses the spacebar. DO i$ = INKEY$ LOOP UNTIL i$ = " " CLS END SUB ' Pause SUB ReadRegionNames ' Read the four region names and the ' ASCII characters that will represent ' them in the graph--all are stored in the ' DATA lines in the program's main module. FOR i% = 1 TO Regions READ RegionNames(i%) READ symbol% RegionSymbols(i%) = STRING$(8, symbol%) NEXT i% END SUB ' ReadRegionNames SUB ReadSalesFile ' Read the ISALES.TXT file into ' the Sales array. OPEN "\ISALES.TXT" FOR INPUT AS #1 FOR i% = 1 TO recCount ' Read the years. INPUT #1, Years(i%) Totals(i%) = 0 FOR j% = 1 TO Regions ' Read the sales data. INPUT #1, Sales(i%, j%) Totals(i%) = Totals(i%) + Sales(i%, j%) NEXT j% NEXT i% CLOSE #1 END SUB ' ReadSalesFile SUB ShowData ' Display the data table at ' the top of the screen. ' The PRINT USING template. template$ = " $$#,######" CLS PRINT "INTERNATIONAL SALES" ' Display the row of years. FOR i% = 1 TO recCount PRINT TAB(T * i% + 8); Years(i%); NEXT i% PRINT ' Display the sales data. FOR i% = 1 TO Regions ' Create a key for the graph. PRINT LEFT$(RegionSymbols(i%), 2); " "; PRINT RegionNames(i%); TAB(T); FOR j% = 1 TO recCount PRINT USING template$; Sales(j%, i%); NEXT j% PRINT NEXT i% ' Display the row of totals. PRINT PRINT "TOTALS"; TAB(T); FOR i% = 1 TO recCount PRINT USING template$; Totals(i%); NEXT i% END SUB ' ShowData SUB ShowGraph ' Create a graph of ASCII characters ' for the sales data. ' VertField is the number of text ' rows available for the graph. CONST VertField = 16 ' Find the largest annual total sales. maxTotal = 0 FOR i% = 1 TO recCount IF Totals(i%) > maxTotal THEN maxTotal = Totals(i%) END IF NEXT i% ' Calculate the conversion factor ' for drawing column graphs within ' the available vertical space. convFactor = VertField / maxTotal ' Create the columns of the graph. FOR i% = 1 TO recCount col% = i% * T + 6 row% = 24 ' Create the "stacks" of each column. FOR j% = Regions TO 1 STEP -1 height% = Sales(i%, j%) * convFactor ' Determine the height of each stack. FOR k% = 1 TO height% LOCATE row%, col% PRINT RegionSymbols(j%); row% = row% - 1 NEXT k% NEXT j% NEXT i% ' Draw the horizontal axis. LOCATE 25, T PRINT STRING$(60, 205); ' Display labels for the columns. FOR i% = 1 TO recCount LOCATE 25, T * i% + 8 PRINT " "; Years(i%); " "; NEXT i% ' Draw the vertical axis. FOR i% = 10 TO 24 LOCATE i%, T PRINT CHR$(186); NEXT i% ' Display the "origin" of the graph. LOCATE 25, T PRINT CHR$(200); ' Keep the graph on the screen ' until the user presses the spacebar. Pause END SUB ' ShowGraph
Here is the text file to open, your going to have to paste it somehow in a Windows environment editor:
This data below has to be saved as ISALES.TXT.
Thx much. It could be just the smallest thing that I've been missing.Code: Select all
"1990",12866,9335,10673,7593 "1991",15790,13118,14789,9772 "1992",17855,16093,15863,13121 "1993",20760,19814,18534,15032
Russ :-)Happy Programming!
Sales Graph Program Question
Sales Graph Program Question
Hey guys... I'm at work, but maybe you guys can help Russell out:
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
Right now, the two OPEN "\ISALES.TXT" should get rid of the \ and just be
OPEN "ISALES.TXT" that just worked fine for me by just removing those and of course making sure ISALES.TXT is in the same folder as the .bas file.
OPEN "ISALES.TXT" that just worked fine for me by just removing those and of course making sure ISALES.TXT is in the same folder as the .bas file.
Code: Select all
INTERNATIONAL SALES
1990 1991 1992 1993
░░ American $12,866 $15,790 $17,855 $20,760
▒▒ European $9,335 $13,118 $16,093 $19,814
▓▓ Asian $10,673 $14,789 $15,863 $18,534
██ Other $7,593 $9,772 $13,121 $15,032
TOTALS $40,467 $53,469 $62,932 $74,140
║ ░░░░░░░░
║ ░░░░░░░░
║ ░░░░░░░░ ░░░░░░░░
║ ░░░░░░░░ ░░░░░░░░
║ ░░░░░░░░ ░░░░░░░░ ▒▒▒▒▒▒▒▒
║ ░░░░░░░░ ░░░░░░░░ ▒▒▒▒▒▒▒▒
║ ░░░░░░░░ ░░░░░░░░ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒
║ ░░░░░░░░ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒
║ ░░░░░░░░ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▓▓▓▓▓▓▓▓
║ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓
║ ▒▒▒▒▒▒▒▒ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓
║ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓
║ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ████████ ████████
║ ████████ ████████ ████████ ████████
║ ████████ ████████ ████████ ████████
╚═══════ 1990 ═══════ 1991 ═══════ 1992 ═══════ 1993 ═══════
Last edited by MystikShadows on Thu Feb 02, 2006 5:40 pm, edited 2 times in total.
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
email: russellM_98@yahoo.com
name: Russell Meyers
Comments: Hi Pete,
Never mind about the previous message I sent you in regards to the program I sent you. I finally figured it out. I actually had to create the ISALES.TXT file over again in order for the SGRAPHA.BAS program to work. Thx anyway.
Russ![]()