Reading File
Reading File
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?
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!
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!

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/
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/
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
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.
Now change the path in this code to match your .txt file

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
PB 5.21 LTS (x86) - Windows 8.1