home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY1 / EXAMP1.ZIP / UMEX262.BAS < prev    next >
BASIC Source File  |  1990-05-18  |  2KB  |  62 lines

  1. 'User's Manual Example, Page 262.
  2. CLS
  3.  
  4. DEFINT a-z                        'integer variables are smaller and faster
  5. $COM 1024
  6. OPEN "COM1: 1200,N,8,1" AS #1 LEN = 1024
  7. echo = 1
  8. WHILE (1)                         'loop forever
  9.   WHILE NOT INSTAT                'as long as no key has been pressed
  10.     IF LOC(1) > 0 THEN
  11.       stuff$ = INPUT$(LOC(1),#1)  'read incoming characters
  12.       PRINT stuff$;               'no carriage returns
  13.                   'unless sent by transmitter
  14.       If already THEN PRINT #3, stuff$;  'save to disk file
  15.     END IF
  16.   WEND
  17.   WHILE INSTAT                    'while there are characters at the keyboard
  18.     myinput$ = INKEY$             'get them
  19.     IF myinput$ = CHR$(20) THEN GOSUB ReadDiskFile                '^T
  20.     IF myinput$ = CHR$(18) THEN GOSUB WriteDiskFile               '^R
  21.     IF myinput$ = CHR$(3)  THEN CLOSE : END                       '^C
  22.     IF myinput$ = CHR$(5)  THEN echo = ABS(echo-1):myinput$ = ""  '^T
  23.     PRINT #1, myinput$;           'send typed characters
  24.     IF echo THEN PRINT myinput$;  'display them--maybe unnecessary
  25.   WEND
  26. WEND                              'check for more incoming characters
  27.  
  28. ReadDiskFile:
  29.   'a subroutine to read a disk file and transmit it
  30.   LINE INPUT "Name of the disk file: ";f$
  31.   OPEN "r", 2, f$, 1024
  32.   FIELD #2, 1024 AS disk$
  33.   r& = LOC(2)
  34.   rec = r&\1024
  35.  
  36.   FOR i = 1 to rec
  37.     GET 2,i
  38.     PRINT #1, disk$;
  39.   NEXT i
  40.  
  41.   IF r& MOD 1024 <> 0 THEN
  42.     GET 2, rec+1
  43.     PRINT #1, LEFT$(disk$,r& MOD 1024 );
  44.   END IF
  45.   CLOSE 2
  46.   myinput$ = ""
  47. RETURN
  48.  
  49. WriteDiskFile:
  50.   'subroutine to write received information to disk file
  51.   'or stop that process
  52.   myinput$ = ""
  53.   IF already THEN
  54.     already = 0
  55.     CLOSE 3
  56.     RETURN
  57.   END IF
  58.  
  59.   already = 1
  60.   LINE INPUT "Output file name: ";f$
  61.   OPEN f$ FOR APPEND AS #3
  62. RETURN