CodeBase - Generic File save as, save, and open commands--

Return to the CodeBase listing

Category: Complete Applications

Version: 1.1

0
0

Information

Uploaded: 20th Oct 2004 01:13

Modified: 1st Jan 1970 01:00

Author:  Three Score

Summary

rem these fuinctions do basic file i/o rem use them as you please rem for the read_file you must ahve txt declared global rem made by free-space.myftp.org rem leave the last paremeter on both of them blank if you do not want silent and want them to choose a file function file_saveas(what$,name$) if name$="" ret: print "so what do you want to save this file as" input file$ if file exist(file$)=1 print "that file exist's already do you want to over write y/n" input temp$ if temp$="y" delete file file$ else goto ret endif endif print "saving file" open to write 1,file$ write string 1,what$ cls else if file exist(name$)=1 then delete file name$ print "saving file" if file exist(name$)=1 then delete file name$ open to write 1,name$ write string 1,what$ cls endif if file open(1)=1 then close file 1 print "done" endfunction function read_file(num,fname$) if fname$="" ret2: print "what file do you want to open" input flname$ if file exist(flname$)=0 print "file does not exist" goto ret2 endif open to read 2,flname$ for i=1 to num+1 read string 2,temp$ if i=num-1 then read string 2,txt$ next i else if file exist(fname$)=0 print "error file don't exist" print "please report this to the maker of this program" txt$="error the file was not found" exitfunction else open to read 2,fname$ for i=1 to num+1 read string 2,temp$ if i=num-1 then read string 2,txt$ next i endif endif if file open(2)=1 then close file 2 endfunction

Full Description

rem these fuinctions do basic file i/o<br /> rem use them as you please<br /> rem for the read_file you must ahve txt declared global<br /> rem made by free-space.myftp.org<br /> rem leave the last paremeter on both of them blank if you do not want silent and want them to choose a file<br /> <br /> <br /> <br /> <br /> <br /> <br /> function file_saveas(what$,name$)<br /> if name$=&quot;&quot;<br /> ret:<br /> print &quot;so what do you want to save this file as&quot;<br /> input file$<br /> if file exist(file$)=1<br /> print &quot;that file exist's already do you want to over write y/n&quot;<br /> input temp$<br /> if temp$=&quot;y&quot;<br /> delete file file$<br /> else<br /> goto ret<br /> endif<br /> endif<br /> print &quot;saving file&quot;<br /> open to write 1,file$<br /> write string 1,what$<br /> cls<br /> else<br /> if file exist(name$)=1 then delete file name$<br /> print &quot;saving file&quot;<br /> if file exist(name$)=1 then delete file name$<br /> open to write 1,name$<br /> write string 1,what$<br /> cls<br /> endif<br /> if file open(1)=1 then close file 1<br /> print &quot;done&quot;<br /> endfunction<br /> <br /> <br /> <br /> <br /> <br /> <br /> function read_file(num,fname$)<br /> if fname$=&quot;&quot;<br /> ret2:<br /> print &quot;what file do you want to open&quot;<br /> input flname$<br /> if file exist(flname$)=0<br /> print &quot;file does not exist&quot;<br /> goto ret2<br /> endif<br /> open to read 2,flname$<br /> for i=1 to num+1<br /> read string 2,temp$<br /> if i=num-1 then read string 2,txt$<br /> next i<br /> else<br /> if file exist(fname$)=0<br /> print &quot;error file don't exist&quot;<br /> print &quot;please report this to the maker of this program&quot;<br /> txt$=&quot;error the file was not found&quot;<br /> exitfunction<br /> else<br /> open to read 2,fname$<br /> for i=1 to num+1<br /> read string 2,temp$<br /> if i=num-1 then read string 2,txt$<br /> next i<br /> endif<br /> endif<br /> if file open(2)=1 then close file 2<br /> endfunction

Comments

No comments yet.