IB Statements/InputFile and PrintFile

From CometWiki

< IB Statements(Difference between revisions)
Jump to: navigation, search
m (minor)
(InputFile and PrintFile Statements)
 
(6 intermediate revisions not shown)
Line 1: Line 1:
-
InputFile and PrintFile Statements
+
=InputFile and PrintFile Statements=
-
The Comet32 Compiler and Runtime support very long strings. These statements allow you to manipulate a whole text file with one string.
+
The Comet32 Compiler and Runtime support very long strings. These statements allow you to manipulate a whole text file with one string.  They both support syntax using either a LUN for an open Comet file or the full path to any file.
-
  PrintFile(LUN)string$  
+
  PrintFile(LUN)string$
 +
PrintFile TheFullPath$ string$
  InputFIle(LUN)string$  
  InputFIle(LUN)string$  
 +
TheFile$ = InputFile(TheFullPath$, excp=FileErr)
An Example:  
An Example:  
  ! Declare Function
  ! Declare Function
Line 12: Line 14:
     print(et)
     print(et)
   
   
-
close(1) & open(1)'ebcdic.txt'         ! Input file containing Ebcdic
+
    close(1) & open(1)'ebcdic.txt'             ! Input file containing Ebcdic
-
close(2) & open(2)'ascii.txt'           ! Output file for Ascii text
+
    close(2) & open(2)'ascii.txt'               ! Output file for Ascii text
   
   
-
InputFile(1)EbcdicString$               ! Read whole file into the string
+
    InputFile(1)EbcdicString$                   ! Read whole file into the string
-
      
+
     AsciiString$ = Ebcdic2Ascii(EbcdicString$) ! Translate it
-
    AsciiFile$ = Ebcdic2Ascii(EbcdicString$)     ! Translate it
+
     printfile(2)AsciiString$                   ! Write whole text file with one statement
-
     printfile(2)AsciiString$                     ! Write whole text file with one statement
+
  done:
  done:
     print 'done'
     print 'done'
Line 29: Line 31:
     length 256 & local table$
     length 256 & local table$
     length dynamic & local a$
     length dynamic & local a$
-
     length 5.0 & local i l
+
     length 5.0 & local I L
      
      
     table$ = _
     table$ = _
Line 48: Line 50:
   '@5C9F535455565758595AF4F5F6F7F8F9@'+_
   '@5C9F535455565758595AF4F5F6F7F8F9@'+_
   '@30313233343536373839FAFBFCFDFEFF@'
   '@30313233343536373839FAFBFCFDFEFF@'
-
     A$ = ''
+
     A$ = ""
-
     l = len(Instring$)
+
     L = len(Instring$)
-
     for i = 1 to l
+
     for I = 1 to L
         A$ = A$ + Sub(table$,asc(sub(Instring$,i,1))+1,1)
         A$ = A$ + Sub(table$,asc(sub(Instring$,i,1))+1,1)
-
     next i
+
     next I
     Procreturn a$
     Procreturn a$
     end
     end
 +
 +
Another example using the function:
 +
length dynamic & local TheFile$,TheFullPath$
 +
 +
clear
 +
TheFullPath$ = "c:\download\FileFromOutsideSource.txt"
 +
TheFile$ = InputFile(TheFullPath$)
 +
! TheFile$ now contains the contents of the entire file

Latest revision as of 22:34, 6 March 2013

InputFile and PrintFile Statements

The Comet32 Compiler and Runtime support very long strings. These statements allow you to manipulate a whole text file with one string. They both support syntax using either a LUN for an open Comet file or the full path to any file.

PrintFile(LUN)string$
PrintFile TheFullPath$ string$
InputFIle(LUN)string$ 
TheFile$ = InputFile(TheFullPath$, excp=FileErr)

An Example:

! Declare Function
String Ebcdic2Ascii(Instring$)
! Declare 2 Dynamic strings
length Dynamic & local EbcdicString$ AsciiString$
   clear
   print(et)

   close(1) & open(1)'ebcdic.txt'              ! Input file containing Ebcdic
   close(2) & open(2)'ascii.txt'               ! Output file for Ascii text
	 
   InputFile(1)EbcdicString$                   ! Read whole file into the string
   AsciiString$ = Ebcdic2Ascii(EbcdicString$)  ! Translate it
   printfile(2)AsciiString$                    ! Write whole text file with one statement

done:
   print 'done'
   wait
   stop			
   end
! This is a user defined string function        
String Ebcdic2Ascii(Instring$)    		 ! Instring is by reference since it is not declared in the function
   length 256 & local table$
   length dynamic & local a$
   length 5.0 & local I L
   
   table$ = _
  '@000102039C09867F978D8E0B0C0D0E0F@'+_
  '@101112139D8508871819928F1C1D1E1F@'+_
  '@80818283840A171B88898A8B8C050607@'+_
  '@909116939495960498999A9B14159E1A@'+_
  '@20A0A1A2A3A4A5A6A7A85B2E3C282B21@'+_
  '@26A9AAABACADAEAFB0B15D242A293B5E@'+_
  '@2D2FB2B3B4B5B6B7B8B97C2C255F3E3F@'+_
  '@BABBBCBDBEBFC0C1C2603A2340273D22@'+_
  '@C3616263646566676869C4C5C6C7C8C9@'+_
  '@CA6A6B6C6D6E6F707172CBCCCDCECFD0@'+_
  '@D17E737475767778797AD2D3D4D5D6D7@'+_
  '@D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7@'+_
  '@7B414243444546474849E8E9EAEBECED@'+_
  '@7D4A4B4C4D4E4F505152EEEFF0F1F2F3@'+_
  '@5C9F535455565758595AF4F5F6F7F8F9@'+_
  '@30313233343536373839FAFBFCFDFEFF@'
   A$ = ""
   L = len(Instring$)
   for I = 1 to L
       A$ = A$ + Sub(table$,asc(sub(Instring$,i,1))+1,1)
   next I
   Procreturn a$
   end

Another example using the function:

length dynamic & local TheFile$,TheFullPath$
clear
TheFullPath$ = "c:\download\FileFromOutsideSource.txt"
TheFile$ = InputFile(TheFullPath$)
! TheFile$ now contains the contents of the entire file
Personal tools