Reading File

Just starting out? Need help? Post your questions and find answers here.
NewMan
User
User
Posts: 11
Joined: Sun Jul 25, 2004 9:54 am

Reading File

Post by NewMan »

i was trying this lately, is it possible to execute a command written in text file? for example text.txt file containts the text "Messagerequester("HI","BYE",0)", i want purebasic to read that and execute the command or any other command written. can neone give an eg?
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

I'm not sure it is possible because your file won't be compile. The command write in the file cannot be translate. It is possible if you write the PureBasic code, and run the compiler for create executable with this file.
May be it is possible but I have just this solution for you sory.
But if someone has a solution, it will be good for me! :-)
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

NewMan,

The problem is that PB is a compiled language, which means that this sort of thing just isn't possible.

If you do want to create something with a scripting engine, why not try embedding LUA in your PB app?

http://www.florian-s.com/PBLua/
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Maybe you could try using .pb files instead then using the include command when you've read the file....
~I see one problem with your reasoning: the fact is thats not a chicken~
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

hmm i would recommend to use lua, or make your own interprettor/script or compiler
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

thefool wrote:hmm i would recommend to use lua, or make your own interprettor/script or compiler
I'm agree with him... I think it's the best solution.

Sory for my bad english :-).
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This is not going to be as efficient or practical as the other recommended solutions, but depending on your needs, maybe you can find some use for it. ;)

Create a .txt file with these 2 lines and save it.

Code: Select all

MessageRequester,Hello,Welcome to PureBasic,0
MessageRequester,Goodbye,Thank you for using PureBasic,0

Now change the path in this code to match your .txt file

Code: Select all

ReadFile(0, "pb.txt") ; <-- change to path of your text file

Repeat

  my$ = ReadString()
  pbCommand$ = StringField(my$,1, ",")
  pbCommandArg1$ = StringField(my$,2, ",")
  pbCommandArg2$ = StringField(my$,3, ",")
  pbCommandArg3$ = StringField(my$, 4, ",")

  Select LCase(pbCommand$) ; well use lowercase to avoid typo's
    Case "messagerequester"
      MessageRequester(pbCommandArg1$, pbCommandArg2$, Val(pbCommandArg3$))
  EndSelect

Until eof

CloseFile(0)
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply