IB Statements/InputFile and PrintFile

From CometWiki

(Difference between revisions)
Jump to: navigation, search
m
m
Line 4: Line 4:
  PrintFile(LUN)string$  
  PrintFile(LUN)string$  
  InputFIle(LUN)string$  
  InputFIle(LUN)string$  
-
An Example:
+
An Example:  
-
 
+
-
+
  ! Declare Function
  ! Declare Function
  String Ebcdic2Ascii(Instring$)
  String Ebcdic2Ascii(Instring$)

Revision as of 00:06, 15 January 2010

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.

PrintFile(LUN)string$ 
InputFIle(LUN)string$ 

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
   
   AsciiFile$ = Ebcdic2Ascii(EbcdicString$)					! Translate it
   printfile(2)AsciiString$
done:
   print 'done'
   wait
   stop							! Write whole text file with one statement
   end
! This is a user defined string function        
String Ebcdic2Ascii(Instring$)    						! Instring is by reference
   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
Personal tools