A Question

 BBS: Inland Empire Archive
Date: 04-26-92 (10:43)             Number: 122
From: TOM GRIFFIN                  Refer#: 34
  To: SCOTT GREEN                   Recvd: NO  
Subj: A Question                     Conf: (2) Quik_Bas
SG>     I wanted to back up a random access file before I used it.  I couldn't
SG> figure out how to copy the file to another file with a
SG> new name.  At first I
SG> tried to come up with a copy like command from basic,
SG> but couldn't find any.
SG> Then I tried to load it as a sequential file, but realized, it would still
SG> only write over the file already on the hard drive.
SG> Then I thought with the
SG> system command I might be able to write a "mini batch"
SG> command to hide withi
SG> my program.

SG>     I do not want to have to write an exterior batch command.  It's not
SG> important enough for me to write a whole routine dedicated to copying the
SG> file.  But I am wondering if there was just stuff I
SG> didn't know.  Are there
SG> such commands in basic?  Can you have batch like
SG> commands after calling the
SG> system in basic?  How do you do it?

Two approaches come into mind.  The first is simple and crude.  The second
has no error detection or correction.

First Example:
SHELL "COPY infile.dat outfile.dat"

Second Example:



DECLARE SUB CopyFile (InFile$, OutFile$, FileType, RecLen)



Main:
  PRINT "File Copy"
  PRINT
  PRINT "Enter Source File: ";
  LINE INPUT InFile$
  PRINT
  PRINT "Enter Destination File: ";
  LINE INPUT OutFile$
  PRINT
  PRINT "Select File Type:"
  PRINT "  1).  Sequential"
  PRINT "  2).  Random/Binary"
  PRINT "  Q).  Quit this abomination of programming"
  PRINT "  "
  PRINT "  Selection (1/2/Q): ";
  LINE INPUT Temp$
  SELECT CASE Temp$
    CASE "1"
      FileType = 1
      RecLen = 0
      CALL CopyFile(InFile$, OutFile$, FileType, RecLen)
    CASE "2"
      PRINT
      PRINT "Enter Record Length (<32767): ";
      LINE INPUT Temp$
      RecLen = VAL(Temp$)
      FileType = 2
      CALL CopyFile(InFile$, OutFile$, FileType, RecLen)

    CASE "Q", "q"
      END
  END SELECT
END
'End of main module


SUB CopyFile (InFile$, OutFile$, FileType, RecLen)
  SELECT CASE FileType
    CASE 1                      'Sequential Stuff
      InFileHandle = FREEFILE
      OPEN InFile$ FOR INPUT AS InFileHandle
      OutFileHandle = FREEFILE
      OPEN OutFile$ FOR OUTPUT AS OutFileHandle
      WHILE NOT EOF(1)
        INPUT #InFileHandle, Temp$
        PRINT #OutFileHandle, Temp$
      WEND
      CLOSE
    CASE 2
      InFileHandle = FREEFILE
      OPEN InFile$ FOR RANDOM AS InFileHandle LEN = RecLen
      OutFileHandle = FREEFILE
      OPEN OutFile$ FOR RANDOM AS OutFileHandle LEN = RecLen
      FIELD #OutFileHandle, RecLen AS Temporary$
      FOR Temp = 1 TO LOF(1) / RecLen
        GET InFileHandle, Temp, Temporary$
        PUT OutFileHandle, Temp, Temporary$
      NEXT Temp
      CLOSE
    CASE ELSE
      PRINT "Error in parameter passing.  Check FileType variable."
      CLOSE
  END SELECT
END SUB

--- GEcho/beta
 * Origin: Trinity ]I[ BBS  RemoteAccess v1.11+ Node #@  (1:147/2777)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET