WriteNewFile
ChannelIndex = WriteNewFile(Filename$)
 
Parameters:

    Filename$ = The name of the file you wish to write data to
Returns:

    ChannelIndex = Index of the file channel to use
 

      WriteNewFile opens a file for write access only. The command requires the filename to create for writing. WriteNewFile will return file channel index for use with subsequent writing commands to you.

      Files can be accessed both sequentially and randomly. However, a file can NOT be read, when opened with WriteNewFile

Sequential Access

      Sequential file access, is when you step through the file in order. In other words, you start writing at the start of the file, and continue writing data to it from start until your finnished. Never stepping backward or skipping forward.

Random Access

      Random file access, is where you can jump around through the file, writing one section, then perhaps jumping back or skipping forward. So your randomly buildingg parts of file. This is often invaluable when you need to write data sections out of order.




FACTS:


      * Files Opened with WriteNewFile can not be read.

      * WriteNewFile will overwrite a file if it already exists.




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
  MyFile=WriteNewFile(File$)
  
; Write a Byte to myfile of value 200
  WriteByte MyFile,200
  
; Write a Word to myfile of value 64000
  WriteWord MyFile,64000
  
; Write a INTEGER to myfile of value 123456
  WriteInt MyFile,123456
  
; Write a FLOAT to myfile of value 123.456
  WriteFloat MyFile,123.456
  
; Write a String to myfile  of value Hello World
  WriteString MyFile,"Hello World"
  
; Close this file channel
  CloseFile MyFile
  
  
  Print "============================"
  Print "Reading File:"+File$
  Print "============================"
  
  
; Open a file to READ with ReadNEwFile
  MyFile=ReadNewFile(File$)
  
; Read and display the byte value
  Print "   Byte Data:"+Str$(ReadByte(MyFile))
  
; Read and display the word value
  Print "   Word Data:"+Str$(ReadWord(MyFile))
  
; Read and display the Integer value
  Print "Integer Data:"+Str$(ReadInt(MyFile))
  
; Read and display the Float value
  Print "  Float Data:"+Str$(ReadFloat(MyFile))
  
; Read and display the String value
  Print "  String Data:"+ReadString$(MyFile)
  
; Close this file channel
  CloseFile MyFile
  
  
  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: CloseFile | EndofFIle | GetFreeFile | OpenFile | OpenNewFile | ReadFile | WriteByte | WriteByteAt | WriteChr | WriteChrAt | WriteFile | WriteFloat | WriteFloatAt | WriteInt | WriteIntAt | WriteMemory | WriteString | WriteStringAt | WriteWord | WriteWordAt :
 


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