CloseFile
CloseFile ChannelIndex
 
Parameters:

    ChannelIndex = Index of the file channel to close
Returns: NONE
 

      CloseFile closes a previously openned file channel.



FACTS:


      * CloseFile can close files openned with either READFILE,OPENFILE or WRITEFILE.

      * Failing a close file that your writing data to can have undesired results on the written data.




Mini Tutorial:


      This example creates a file, stores various types of data in it, then reads it back again.


  
  File$=TempDir$()+"PB_TestFile.txt"
  
; CReate a File for writing data to
  WriteFile File$,1
  
; Write a Byte to file channel 1, of value 200
  WriteByte 1,200
  
; Write a Word to file channel 1, of value 64000
  WriteWord 1,64000
  
; Write a INTEGER to file channel 1, of value 123456
  WriteInt 1,123456
  
; Write a FLOAT to file channel 1, of value 123.456
  WriteFloat 1,123.456
  
; Write a String to file channel 1, of value Hello World
  WriteString 1,"Hello Word"
  
; Close this file channel
  CloseFile 1
  
  
  Print "============================"
  Print "Reading File:"+File$
  Print "============================"
  
  
; Open a file to READ with READFILE
  ReadFile File$,1
  
; Read and display the byte value
  Print "   Byte Data:"+Str$(ReadByte(1))
  
; Read and display the word value
  Print "   Word Data:"+Str$(ReadWord(1))
  
; Read and display the Integer value
  Print "Integer Data:"+Str$(ReadInt(1))
  
; Read and display the Float value
  Print "  Float Data:"+Str$(ReadFloat(1))
  
; Read and display the String value
  Print "  String Data:"+ReadString$(1)
  
; 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
  ============================
  Byte Data:200
  Word Data:64000
  Integer Data:123456
  Float Data:123.456
  String Data:Hello World
  

 
Related Info: ReadFile | ReadFloat | ReadInt | WriteFile | WriteFloat | WriteInt :
 


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