Page 1 of 1

Reading File

Posted: Thu Oct 21, 2004 4:20 pm
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?

Posted: Thu Oct 21, 2004 4:30 pm
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! :-)

Posted: Thu Oct 21, 2004 5:01 pm
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/

Posted: Thu Oct 21, 2004 5:02 pm
by Killswitch
Maybe you could try using .pb files instead then using the include command when you've read the file....

Posted: Thu Oct 21, 2004 5:11 pm
by thefool
hmm i would recommend to use lua, or make your own interprettor/script or compiler

Posted: Thu Oct 21, 2004 5:17 pm
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 :-).

Posted: Thu Oct 21, 2004 7:57 pm
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