WriteChr
WriteChr ChannelIndex, String$, Length
 
Parameters:

    ChannelIndex = Index of the file channel your writing to
    String$ = The String the characters you'll be writing
    Length = The number of characters to write. Use Length of zero to write null terminated string
Returns: NONE
 

      The WriteChr command will write a fixed number of characters to an open file channel. You can make it write a zero terminated string, by setting the Length parameter to zero.




FACTS:


      * WriteChr only works with files opened with WriteFile command.

      * Setting the Length parameter to zero, will make WriteChr write a Zero terminated string. These are strings that have a 0 Byte saved at the end.



Mini Tutorial:


      This example creates a simple file with some various bits of data store in it, then read it's back again.


  
  File$=TempDir$()+"PB_TestFile.txt"
  
; CReate a File for writing data to
  WriteFile File$,1
  
; Write a String to file channel 1, of the word
; "Play Basic"
  WriteChr 1,"Play Basic",10
  
; Close this file channel
  CloseFile 1
  
  
  Print "============================"
  Print "Reading File:"+File$
  Print "============================"
  
  
; Open a file to READ with READFILE
  ReadFile File$,1
  
; Start a For/Next loop for the length of this file
  For lp=1 To FileSize(file$)
   ; read and Display 1 character from this
   ; file channel per loop
     Print ReadChr$(1,1)
  Next
  
; Close this file channel
  CloseFile 1
  
  If FileExist(file$) Then DeleteFile file$
  
; Display the screen and wait for a key press
  Sync
  WaitKey
  



This example would output.

  
  ============================
  Reading File:C:Windows\temp\Pb_TestFile.txt
  ============================
  P
  l
  a
  y
  
  B
  a
  s
  i
  c
  

 
Related Info: CloseFile | ReadFile | WriteByte | WriteChrAt | WriteFloat | WriteInt | WriteString | WriteWord :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com