More than one file at the same time...

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andy.

Hi,

I'm relatively new at PureBASIC.

I need to work with 2 files simultaneously... One for input and one for processed output.

The help files indicate that I can work with several files at the same time, but after spending some time with this, I am still nowhere.

I would appreciate it, if someone could write a couple of lines of code that I can learn from... Just something like open file a, open file b, read from a, write to b, close both files.

Sorry for asking this, but I must be slow!

Andy
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by BalrogSoft.


Hi Andy, and welcome to this forum...

I post here a code that i think that solve your problem:

Code: Select all

If CreateFile(0,"Test1.txt")        ; Create a text file for the test
  WriteString("Test 1")
  CloseFile(0)
EndIf 

If OpenFile(0,"Test1.txt")           ; Open file 0 to read
  If CreateFile(1,"Test2.txt")      ; Open file 1 to write
    UseFile(0)                      ; Use file 0 to operations
    String1$=ReadString()           ; Read String from file 0
    UseFile(1)                      ; Use file 1 to operations
    WriteStringN(String1$)          ; Write string from file 0 to file 1
    CloseFile(1)                    ; Close file 1
  EndIf
  CloseFile(0)                      ; Close file 2
EndIf
Bye, Balrog Soft

Balrog Soft
Amiga and PC Coder
http://www.balrogsoftware.com
[url]mailto:balrog@balrogsoftware.com[/url]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andy.

Ahaaaa...

I need to use "UseFile()"...

Thanks Balrog, that's absolutely cool mate.

Andy
Post Reply