Sign in to follow this  
Followers 0
ElBarteros

Run Code from Text.txt File

5 posts in this topic

Hello iam new at AutoIt and sorry for my bad english.

I search for a solution to run code from a text file. For example in the Textfile is this: MsgBox(0, "Hello World")

i hope here is any body how can help me.

here my first try:

CODE

$file = FileOpen("Test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

; here is my code, but how can i run it as real code

$line

Wend

FileClose($file)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use the execute command. But keep in mind execute is ver limited and i don't think it can run Msgbox.

Edited by sccrstvn93

Share this post


Link to post
Share on other sites

Thx it works perfekt. I have try the Execute($line) command also before but only with the MsgBox for Testing ;-)

Thx for you fast reply

Share this post


Link to post
Share on other sites

Hello iam new at AutoIt and sorry for my bad english.

I search for a solution to run code from a text file. For example in the Textfile is this: MsgBox(0, "Hello World")

i hope here is any body how can help me.

Welcome,

Try this example:

FileWrite('Test.txt', 'MsgBox(0, "title1", "Hello World")' & @CRLF & 'MsgBox(0, "title2", "Hello World")')
RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript Test.txt')
FileDelete('Test.txt')

:)

Share this post


Link to post
Share on other sites

Welcome,

Try this example:

FileWrite('Test.txt', 'MsgBox(0, "title1", "Hello World")' & @CRLF & 'MsgBox(0, "title2", "Hello World")')
RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript Test.txt')
FileDelete('Test.txt')

:)

Yeah thats great. It is much better. And the MsgBox ... works too.

big thx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0