home *** CD-ROM | disk | FTP | other *** search
/ Futura 10 / Futura_Issue_10_1993_11_NOSAUG_Side_B_BASIC.atr / flyer.doc < prev    next >
Text File  |  2023-02-26  |  10KB  |  1 lines

  1. ¢*************************¢* THE TURBO BASIC FLYER *¢* by Ron Fetzer, OHAUG  *¢*************************¢¢¢PROGRAMMING MADE EASY - PART II(i)¢by Ron Fetzer, OHAUG.¢¢     In the first part of this article I showed how to write a BLOCK DIAGRAM and the SKELETON PROGRAM. In this section we will flesh out the SKELETON  PROGRAM and write the actual code for each module.¢¢     The most general module is the CONTROL MODULE. It is like the brain on the program. It directs the execution of the program. Whenever a module is finished it will return to the CONTROL MODULE¢¢     There is no set way of which module to write first. But you generally follow the logical sequence of the program.¢¢¢THE CONTROL MODULE¢¢  10 REM DISK SECRETARY BY RON FETZER¢  20 ------------------------------¢  30 EXEC SCRN_CL¢  40 EXEC DIM_SEC¢  50 EXEC DENST¢  60 EXEC MENU¢  70 GOTO 60¢ 490 ------------------------------¢¢     The modules that are needed every time the program is run are coded with the EXEC command. Every module will return to line 70 via the MENU MODULE. In this way we always go back to the MENU. Please note I use module names that are descriptive of their function. The (_) underscore lets you combine realistic names. Each module is separated with the -- command.¢¢¢SCREEN COLORS MODULE(SCRN_CL)¢¢     This sub module will let you select a screen color of your choice. NOTE line 500. Next to the command of   PROC I put 'CLS" and I initialized the variable Q.¢¢     CONSISTENCY is a mark of a good program.¢¢     I will do this in the same place on every module. In line 560 and 565 I do ERROR TRAPPING. Your program should have extensive error trapping routines. There are several ways of error trapping. I will always do it the same way.¢¢500 PROC SCRN_CL:CLS :Q=0¢510   POSITION 6,6:? "WHAT SCREEN COLOR¢      DO YOU WANT?"¢520   POSITION 14,10:? "1: NORMAL"¢530   POSITION 14,11:? "2: AMBER"¢540   POSITION 14,12:? "3: GREEN"¢550   POSITION 14,13:? "4: GREY"¢560   TRAP 560:POSITION 10,17:INPUT¢      "SELECT A NUMBER >>",Q:TRAP 40000¢565   IF Q<1 OR Q>4 OR Q<>INT(Q) THEN¢      ? :? "ERROR: SELECT A NUMBER FROM¢      1 TO 4":GOTO 560¢570   ON Q GOTO 580,590,600,610¢580   POKE 710,148:POKE 709,13:GOTO 980¢590   POKE 710,58:POKE 709,0:GOTO 980¢600   POKE 710,234:POKE 709,0:GOTO 980¢610   POKE 710,12:POKE 709,0:GOTO 980¢980 ENDPROC ¢990 ------------------------------¢¢¢THE DIM MODULE(DIM_SEC)¢¢     All strings and arrays have to be DIMmed. Enter your variables into this section as they are needed by the program. In this way you will know if the variable is in the beginning, the middle or the end of the program.¢¢1000 PROC DIM_SEC¢1010   DIM FILE$(25),KEY$(2),SECT$(25)¢       R$(10),D$(25),K$(25),YN$(1)¢       F$(25),FZ$(25),X$(50),¢       FILE1$(25),TL$(30)¢1480 ENDPROC ¢1490 ------------------------------¢¢¢THE DENSITY MODULE(DENST)¢¢     In the DENSITY MODULE I have 2 BLOCKS. The first block is the density information. The 2nd block is the disk drive number. I put in a REM in line 1575 to indicate that I have a new block.¢¢     Note line 1590. I had to use an IF-THEN-ELSE command to ERROR TRAP. Again in line 1500 next to PROC I use a 'CLS' and initialized the variables in this module.¢¢1500 PROC DENST:CLS :DN=0:DR=0¢1510   POSITION 14,7:? "DISK DENSITY"¢1520   POSITION 14,8:? "---- -------"¢1530   POSITION 12,10:? "1. SINGLE¢       DENSITY"¢1540   POSITION 12,11:? "2. 1050¢       DENSITY"¢1550   POSITION 12,12:? "3: DOUBLE¢       DENSITY"¢1560   TRAP 1560:POSITION 12,14:INPUT¢       "SELECT A NUMBER >>",DN¢       :TRAP 40000¢1570   IF DN<1 OR DN>3 OR DN<>INT(DN)¢       THEN ? :? "ERROR: SELECT A¢       NUMBER FROM 1 TO 3":GOTO 1560¢1575   REM ***  DIRVE INFORMATION   ***¢1580   CLS :TRAP 1580:POSITION 8,11¢       :INPUT "DRIVE NUMBER 1,2 OR 8¢       >>",DR:TRAP 40000¢1590   IF DR=1 OR DR=2 OR DR=8:¢       GOTO 1980¢1600   ELSE ¢1610   ? :? "    ERROR: USE A NUMBER¢       1, 2 OR 8":PAUSE 120¢       :GOTO 1580¢1620   ENDIF ¢1980 ENDPROC ¢1990 ------------------------------¢¢¢THE MENU MODULE(MENU)¢¢     In the MENU MODULE you get a choice of what module you want to select. When the module you have selected is finished it will return to line 2480 ENDROPC and this in turn will return you to line 70 GOTO 60. In this way every module returns to the CONTROL MODULE.¢¢     Rather than using the POSITION command for the menu items I used R$(line 2005) to create 8 spaces in front of each item.¢¢2000 PROC MENU:CLS :NUM=0¢2005   R$="       "¢2010   POSITION 18,5:? "MENU"¢2015   POSITION 18,6:? "----":? ¢2020   ? R$;"1. DISK INFORMATION"¢2030   ? R$;"2. PRINT TO SCREEN"¢2040   ? R$;"3. PRINTER"¢2050   ? R$;"4. LOCK A FILE"¢2060   ? R$;"5. UNLOCK A FILE"¢2070   ? R$;"6. RENAME A FILE"¢2080   ? R$;"7. DELETE A FILE"¢2090   ? R$;"8. FORMAT A DISK"¢2100   ? R$;"9. END"¢2110   TRAP 2110:POSITION 9,18¢       :INPUT "SELECT A NUMBER>>"¢       ,NUM:TRAP 40000¢2115   IF NUM<1 OR NUM>9 OR¢       NUM<>INT(NUM) THEN¢       ? :? "ERROR: USE A NUMBER¢       FROM 1 TO 9":GOTO 2110¢2120   ON NUM EXEC DENST,SCRN,PRNT,LOK,¢       UNLOK,RENAM,DELET,FORMT,FINI¢2480 ENDPROC ¢2490 ------------------------------¢¢¢CONVERT MODULE(CONVRT)¢¢     This sub sub module is used by the SCREEN MODULE and the PRINT MODULE. What it does is convert the FREE SECTORS of your disk into K-BYTES. I take the first 3 characters(number of free bytes) and change them into numeric value( line 6510)¢¢     Single density and 1050 density disk have 125 bytes per sector. In line 6520 I multiply the free bytes by 125 and divide by 1000 to get K-Bytes. I then round it of to the nearest 10th¢¢     Double density disks have 256 bytes per sector. I do the same thing in line 6530 for double density¢¢6500 PROC CONVRT:SECT$="":E=0:D=0¢6510   SECT$=FILE$(1,3):D=VAL(SECT$)¢6520   IF DN=1 OR DN=2 THEN¢       E=INT(D*125)/1000:¢       E=INT(E*10+0.5)/10¢6530   IF DN=3 THEN¢       E=INT(D*256)/1000:¢       E=INT(E*10+0.5)/10¢6540   ? :? "YOU HAVE ";E;" K. BYTES¢       OF SPACE LEFT"¢6550   CLOSE ¢6980 ENDPROC ¢6990 ------------------------------¢¢¢THE SCREEN MODULE(SCRN)¢¢     In this module I open drives 1,2,8 in lines 2510-2530. If the first character is bigger than ASCII 47( a number) than I call the CONVERT routine to change it into K-Bytes in line 2550. If the ASCII is less then 47 than I go back to the INPUT line 2550 again¢¢     I have to put a STOP on this module so the directory stays on the screen. I used the INKEY$ function to wait for the SPACE BAR to be pressed (CHR$(32)). POKE 752,1 and POKE 752,0 turn the cursor off and on. I usually put this POKE also on the line with the command PROC.¢¢2500 PROC SCRN:CLS :POKE 752,1¢2510   IF DR=1 THEN CLOSE:¢       OPEN #2,6,0,"D1:*.*"¢2520   IF DR=2 THEN CLOSE:¢       OPEN #2,6,0,"D2:*.*"¢2530   IF DR=8 THEN CLOSE:¢       OPEN #2,6,0,"D8:*.*"¢2540   ? "           FILES ON DISK ";DR¢2545   ? "           ----- -- ---- -":?¢2550   INPUT #2,FILE$:¢       IF ASC(FILE$(1,1))>47¢       THEN 2570¢2560   ? FILE$;:INPUT #2,FILE$:¢       ? " ";FILE$:IF ASC(FILE$(1,1))¢       <47 THEN 2550¢2570   EXEC CONVRT¢2580   ? "    PRESS צסIJבדáאIJפ TO¢       CONTINUE"¢2590   KEY$=INKEY$¢2600   IF KEY$=CHR$(32):GOTO 2610:ELSE¢       :GOTO 2590:ENDIF ¢2610   CLOSE :POKE 752,0¢2980 ENDPROC ¢2990 ------------------------------¢¢¢THE PRINT MODULE(PRNT)¢¢     I first call the SCREEN MODULE to display the directory on the screen in line 3050. The PRINT MODULE is done the same way as the SCREEN MODULE. In line 3070 and 3080 I use FILE$ AND FILE1$ in order to get 2 columns printed. No printer control codes are used so this program will work with every printer.¢¢3000 PROC PRNT:CLS :YN$=""¢3010   EXEC SCRN¢3015   ? :INPUT "SHALL I PRINT THIS¢       DIRECTORY(Y/N)>>",YN$¢3030   IF YN$(1,1)="N" THEN 3480¢3032   ? :INPUT "TITLE OF THE¢       DISK>>",TL$¢3035   LPRINT "                 "¢       ;TL$:LPRINT ¢3040   IF DR=1 THEN CLOSE:¢       OPEN #2,6,0,"D1:*.*"¢3050   IF DR=2 THEN CLOSE:¢       OPEN #2,6,0,"D2:*.*"¢3060   IF DR=8 THEN CLOSE:¢       OPEN #2,6,0,"D8:*.*"¢3070   INPUT #2,FILE$:IF ASC(FILE$¢       (1,1))>47 THEN 3100¢3080   INPUT #2,FILE1$¢3085   LPRINT "    ";FILE$;"   ";FILE1$¢3088   IF ASC(FILE1$(1,1))<47 THEN 3070¢3100   LPRINT :LPRINT "      YOU HAVE¢       ";E;" K. BYTES OF SPACE LEFT"¢3105   LPRINT :LPRINT :LPRINT ¢3110   YN$="":? :INPUT "GO¢       AGAIN(Y/N)>>",YN$¢3120   IF YN$(1,1)="Y" THEN ? :INPUT¢       "DID YOU INSERT A NEW DISK¢       IN THE DISK DRIVE(Y/N)>>",YN$¢3130   IF YN$(1,1)="Y":GOTO 3010¢       :ELSE :GOTO 3470:ENDIF ¢3470   CLOSE ¢3480 ENDPROC ¢3490 ------------------------------¢¢¢THE FILE NAME MODULE(FILE)¢¢     The FILE NAME MODULE is a sub sub module used by LOCK A FILE, UNLOCK A FILE and DELETE A FILE MODULES.¢¢     In this module I concatenate 2 strings, the drive string and the file name string into one string.¢¢     There are several ways of concatenation. I always use the same method. "OLD$(LEN(OLD$)+1)=NEW$"¢¢7000 PROC FILE:K$="":D$=""¢7010   ? :INPUT "FILE NAME>>",K$¢7030   IF DR=1 THEN D$="D1:":¢       D$(LEN(D$)+1)=K$:K$=D$¢7040   IF DR=2 THEN D$="D2:":¢       D$(LEN(D$)+1)=K$:K$=D$¢7050   IF DR=8 THEN D$="D8:":¢       D$(LEN(D$)+1)=K$:K$=D$¢7480 ENDPROC ¢7490 ------------------------------¢¢¢¢************************************¢¢¢Ed: In the next Turbo BASIC Flyer, we continue with "Programming Made Easy (Part II)".  Ron completes his detailed examination of the modules and concludes with the whole fleshed out program.¢¢    I have placed the Disk Secretary program (SECRTARY.TUR) on Side B of this Futura disk.  Before examining the program yourself, I suggest you create a boot disk.  Follow these steps:¢¢1. Format a disk with DOS 2.5.¢2. Write DOS files to the disk (DOS Option H).¢3. Transfer the AUTORUN.SYS and SECRTARY.TUR files to your new disk (use DOS Option O).¢4. Rename the SECRTARY.TUR file AUTORUN.BAS (use DOS Option E).¢5. Boot disk without BASIC.¢¢    Enjoy!  Extra special thanks to Ron Fetzer and the Ol' Hackers for allowing publication of The Turbo BASIC Flyer in Futura!¢¢    Until next time...¢¢                KEEP PROGRAMMING!!!¢