Author Topic: Text Files[BB2D]  (Read 8277 times)

0 Members and 1 Guest are viewing this topic.

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Text Files[BB2D]
« on: June 05, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Text Files
« Reply #1 on: June 05, 2006 »
In your code that reads in the data you'd usually do something along the lines of using a Dim VariableName(xamount,yamount) or however many slots, and not in the text file matey.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #2 on: June 06, 2006 »
I'll knock something up for you in a little while today mate.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #3 on: June 06, 2006 »
Ok, here's something very quick for you but it should be what you need;

Code: [Select]
;
; Simple file IO Example. By Shockwave^DBF
;
;------------------------------------------
Graphics 800,600,0,2

Dim STORE (4); space to read some data into
Dim FROMFILE (4); space to read a file into

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
;read the data from data statements;
For A=1 To 4
Read STORE(A)
Next

;CREATE A FILE
FILE_OUT = WriteFile("DATA.DAT")

;write the data into the file;
For A=1 To 4
WriteInt (FILE_OUT , STORE(A)); NB THIS COULD ALSO BE WRITEBYTE AND WRITESTRING TOO, ALL IN THE SAME FILE
Next

; ****ALWAYS CLOSE THE FILE WHEN YOU'VE FINISHED WITH IT!****
CloseFile(FILE_OUT)

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

;OPEN THE FILE AGAIN FOR READING;
FILE_IN = ReadFile ("DATA.DAT")

;Read the data from the file;

For A=1 To 4
FROMFILE(A)=ReadInt(FILE_IN) ; COULD ALSO BE READBYTE OR READSTRING
Next

; ****AGAIN MAKE SURE YOU CLOSE THE FILE WHEN YOU'VE FINISHED WITH IT****
CloseFile (FILE_IN)

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


;OUTPUT THE RESULT;

Text 0,0,"ESCAPE TO EXIT, DATA READ FROM FILE IS BELOW;"
For A=1 To 4
Text 0,A*10,FROMFILE(A)
Next

While Not KeyDown(1)
Wend

Data 23,24,2000,100

Nb. You don't need to worry about the file pointer, it is managed by Blitz for you in a pretty similar way to data statements. If you think of it like that then you won't go far wrong. You do have more control over it than that if you want, but for your purposes this source should be enough information for now.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Text Files
« Reply #4 on: June 06, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #5 on: June 06, 2006 »
No worries, post back if you get stuck again.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Text Files
« Reply #6 on: June 06, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #7 on: June 07, 2006 »
You're very welcome Mark :) Glad I could help.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Text Files
« Reply #8 on: June 08, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #9 on: June 09, 2006 »
You need to use the seekfile command, basically you use it like this;

seekfile ( FILE_HANDLE , POSITION )

FILE_HANDLE is the variable of the file, eg;

FILE_HANDLE = openfile ("file.dat")

FILEPOS doesn't actually reset the file for you, it returns the position of the file pointer in bytes in the file.

If you want to reset the file pointer then you'll need to use Searchfile or something like that to find the location in the file that you want to reset to and then use Seekfile to reset the file pointer.

Hope that helps :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #10 on: June 09, 2006 »
Nb, just realised that that's probably not too clear, so just to add;

Seekfile ( FILE_HANDLE , POSITION )

You know about the file handle, position is the number of bytes into the file to offset.

You were probably getting a MAV because you may have been outside the boundaries of the file.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Text Files
« Reply #11 on: June 09, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #12 on: June 09, 2006 »
Searchfile will look for something in the file so you could write a 1 byte number somewhere you want to reset to, something like $ff (as long as it ain't anywhere else in the file) as this will make it easier. then you can use searchfile to find that place in the file and then add 1 to the result and use seekfile to move to the location in the file. Clear as mud?
Give it a go and if it doesn't work I'll help you some more.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Text Files
« Reply #13 on: June 09, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Text Files
« Reply #14 on: June 09, 2006 »
Well done :)
Shockwave ^ Codigos
Challenge Trophies Won: