Page 1 of 1

CatchFile for Ascii included file

Posted: Sat Nov 22, 2008 1:35 pm
by flaith
hi

i had a large text file to include to a project (must be included inside the executable). The only way was to make a little code to read the file, export it as a pb file (with datasection, Data.s ...) and put it inside my project.

maybe that way will be better :wink:

Code: Select all

#file_open_inside = 0

Global NewList liste_txt.s()

Filename$ = CatchFile(?Txt_File,#PB_Ascii)

If ReadFile(#file_open_inside,Filename$)
  While Eof(#file_open_inside) = 0
    AddElement(list_txt())
      list_txt() = ReadString(#file_open_inside)
  Wend
Else
  MessageRequester("Information","Impossible d'ouvrir le fichier!")
EndIf

End

DataSection

  Txt_File: IncludeAscii "liste_file.txt"
EndDataSection
Thanks :D

Posted: Sat Nov 22, 2008 1:46 pm
by Fred
Why IncludeBinary doesn't do the job here ?

Posted: Sat Nov 22, 2008 2:57 pm
by flaith
Hey Fred, thanks for answering :D
Why IncludeBinary doesn't do the job here ?
well, yes it does, but my aim is to use the 970 lines of words inside the text file :?
So, you're right, the request is not for "IncludeAscii" but for a "CatchFile(file$,type.l)" instead

Posted: Sat Nov 22, 2008 3:57 pm
by djes
PeekS() should do easily the trick.

Posted: Sat Nov 22, 2008 4:05 pm
by flaith
djes wrote:PeekS() should do easily the trick.
I know, but doing a PeekS(?included_file, ?end-?included_file) gives a var containing 970 lines of text i need to explode to an array of string :?

Posted: Sat Nov 22, 2008 4:54 pm
by Rescator
You need to make a simple data format in this case: 4bytelen,nbytestring
Make a small tool that does this, then simply use includebinary.
The included datafile will have the len infront of each string so it's easy to calculate where the next start.

Alternatively include a text file, build this data at startup and parse for end of line.

In both cases the best is to put the date into a dim array of strings, or a dim array of pointers to the data.

There is no "easy" way to do this. Just search the forum, I think there should be a handfull of example code for something similar to the last case.

Posted: Sat Nov 22, 2008 6:16 pm
by flaith
Thanks for your answers
Rescator wrote:There is no "easy" way to do this
That's why i'm making a wish to Santa fred :D