Jump to content

Dynamically loading function content


Recommended Posts

We got your code man, and I'm learning writing it:

$var = IniRead(@ScriptDir & "\jack.ini", "testing", "0", "")
Test()
Func Test()
    Execute($var)
EndFunc

I can't believe this actually works, AutoIt is amazing. :)

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

We got your code man, and I'm learning writing it:

$var = IniRead(@ScriptDir & "\jack.ini", "testing", "0", "")
Test()
Func Test()
    Execute($var)
EndFunc

I can't believe this actually works, AutoIt is amazing. :)

Ahahaha, Execute, brilliant!

This is awesome :)

Link to comment
Share on other sites

  • 2 weeks later...

Hey Pt,

I had a question about your DynFunc I posted in that thread, but I guess I'll post this here too, maybe someone else knows something as well.

Seems to be a confusing question, so I'll try to be as plain as possible. I'm trying to load an if statement into my function dynamically. The if statement is in an external file called testing.au3. That file looks like this:

If $number < 30 Then $number += 5
If $number > 30 Then $number -= 5

This script is supposed to read those if statements and augment the outcome of the function _CatchAReturn($n)

#Include <File.au3>
#Include <Array.au3>
Global $DynamicFuncs
Global $FuncString
If Not _FileReadToArray(@ScriptDir & "\testing.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf
;_ArrayDisplay($DynamicFuncs)

MsgBox(0, "",_CatchAReturn("25"))

Func _CatchAReturn($n)
    Local $number = $n
    For $j = 1 To $DynamicFuncs[0]
        $FuncString = $FuncString & $DynamicFuncs[$j]
    Next
    ;MsgBox(0, "", $FuncString)
    Execute($FuncString)
    Return $number
EndFunc  ;<===_CatchAReturn

My question is why does it not work? There is no error on execution.

Link to comment
Share on other sites

Or here is your function with a similar problem:

#include <GUIConstants.au3>
#include <Date.au3>
#include <String.au3>
#include <Math.au3>
#NoTrayIcon

Dim $Var = 52; Just a number to demonstrate that Vars are precessed correctly.

;Generated with Form Designer preview
$b = True
$Form1 = GUICreate("Dynamic functions", 622, 441, 192, 113)
$Edit1 = GUICtrlCreateEdit("", 48, 40, 553, 217, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetData($Edit1, "If NOT $b = False Then MsgBox(0,"", 'It Works !', 1)")
$Label1 = GUICtrlCreateLabel("", 48, 288, 430, 25, $SS_SUNKEN)
$Button1 = GUICtrlCreateButton("Execute", 500, 288, 89, 25)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button1
        _Dynamic_Functions()
        _Calc()
    EndSelect
WEnd
Exit

Func _Dynamic_Functions()
    $a=GUICtrlRead($Edit1)
$v=Execute($a)    
If @error=1 Then
    Msgbox(0,"Error","There is a syntax Error, Please correct.")
Else
GUICtrlSetData($Label1,$v)
EndIf
EndFunc

Func _Calc()
    $var=$var+1
EndFunc
Link to comment
Share on other sites

  • Moderators

You're trying to execute an autoit script in this manner?

Here's a question for you:

You are making the au3 script 1 long string with your For/Next loop. What exactly makes you think this would work with Execute?

Example of how your array is being read to a string:

MsgBox(64, "Info", "1")

MsgBox(64, "Info", "2")

The way you are passing it to the Execute Function is:

Execute(MsgBox(64, "Info", "1")MsgBox(64, "Info", "2"))

Now I know that Execute doesn't work on some functions (Like the msgbox example above), but this was just an example to show you the error in your logic.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You're trying to execute an autoit script in this manner?

Here's a question for you:

You are making the au3 script 1 long string with your For/Next loop. What exactly makes you think this would work with Execute?

Just trying things out...The example I posted is screwed up with that string, you are right.

Here is a better example that actually works:

Opt("WinDetectHiddenText", 1)
    Opt("WinTitleMatchMode", 2)
    ControlClick("WindowName","","Button19")
    ControlClick("WindowName","", "Edit2")
    ControlCommand("WindowName","","Edit2","Editpaste", $text)
    Sleep(300)
    ControlClick("WindowName","","Button16")
    ControlGetText("WindowName","","Edit12")

Global $DynamicFuncs
If Not _FileReadToArray(@ScriptDir & "\testing.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf
$text = 'Sometext'
MsgBox(0, "",_DynamicFunc())

Func _DynamicFunc()
    For $j = 1 To $DynamicFuncs[0]
        Execute($DynamicFuncs[$j])
    Next
    Return Execute($DynamicFuncs[$j])
EndFunc  ;<===_DynamicFuncoÝ÷ Ù8^r¦jwl~º&µë-x»w±yË­yܧjhjYr¢{ayªi#fÂäx0ØSç±jjey¦è½æ¶æ¥*Þ¶êç²Ø^µìm#f¶n)àÂ+a¶v¥r¦jwB¢{k¢Qµ7±¶«¨µh§v
jgªºjºjºjºDv+uÚ«¨´­¶~ËZµéÛ¢}ýµì^^Z¡ë-+j)ZºÚ"µÍÌÍØUYBÌÍÝI][ÝÒYÕ ÌÍØQ[ÙHÙÐÞ
    ][ÝÉ][ÝË    ÌÎNÒ]ÛÜÜÉÌÎNÊI][ÝÂ^XÝ]J    ÌÍÝ
Edited by Oldschool
Link to comment
Share on other sites

  • Moderators

It executes an expression, not a conditional statement.

You may want to look at AutoIt3ExecuteLine or AutoIt3ExecuteScript for the tasks you are actually trying to accomplish (since it seems you are more trying to use this similar to a DLL than an actual script file).

Edit:

Plus... FYI, your conditional statement is incorrect.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It executes an expression, not a conditional statement.

You may want to look at AutoIt3ExecuteLine or AutoIt3ExecuteScript for the tasks you are actually trying to accomplish (since it seems you are more trying to use this similar to a DLL than an actual script file).

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')oÝ÷ Ùhbëay¦è½ì(®K-æÞ)®nqëêë¢

Also, when using /AutoIt3ExecuteScript, is there an accepted way of getting a return from that script, if that is even an option..?

Link to comment
Share on other sites

  • Moderators

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')oÝ÷ Ùhbëay¦è½ì(®K-æÞ)®nqëêë¢

Also, when using /AutoIt3ExecuteScript, is there an accepted way of getting a return from that script, if that is even an option..?

Think about your logic here.

How does the script know what $b equal?

I really don't understand what you're doing... and can't for the life of me follow any logic trail what so ever. Because what you seem to be wanting to do is have the non-ran script contain variable data already. Sorry, the logic just doesn't flow for me... so good luck.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

$b=True
Run(@AutoItExe & ' /AutoIt3ExecuteLine "If NOT $b = False Then MsgBox(0, ''Hello World!'', ''Hi!'')"')oÝ÷ Ûú®¢×y«(r¶­v¬mÂäËajÛayÊz+z)à®éâÜ(v'ßz·§·^ø«¢yÛ7õ«­¢+ØÀÌØíõQÉÕoÝ÷ Ú+z)à®éâ)íçâ®Ë^ö§u«­¢+ÙIÕ¸¡Õѽ%ÑáµÀìÌäì½Õѽ%ÐÍáÕÑ1¥¹ÅÕ½Ðí%9=PÀÌØíô±ÍQ¡¸5Í ½à À°ÌäìÌäí!±±¼]½É±ÌÌìÌäìÌäì°ÌäìÌäí!¤ÌÌìÌäìÌäì¤ÅÕ½ÐìÌäì¤oÝ÷ Ú+z)à®éâØ^±ç(ק½8Z·l)¢¶¯zƧzºè­¦èºÝ7é¹èµ·¢^rV«yÒ-ßÛ%G«ºyâaÇ(uèh¦)à~â¶Ú0¢¹ºÚ"µÍÙÐÞ
    ][ÝÖ[ÝÛ^Ý[XXHÎ][ÝË  ÌÍÓ^TÝoÝ÷ Øò¢ìÛh­ën®v«zË¥µúèØ^r^m觻§Â§ºÈ§Ø^ü­ wº×w¦èiÈH笳*.Â¥v¯yè­êí£
âµëaz·¬º[m¡§âæ§v·v+_®­ézk¢
Úî±æôÖ©¦ºr¥ÛezÞ®H¥Øhºh®«ªli Ë^¬Ç¬±¨IéÝ1ë,j¦èiÈb²ønW«"uéèµâ-)䶫y«(»§)àr^)¶¬v¬mÂäÆÞq«¬xL^rë^q©÷ö×±yË­yÊ'v+b¢v¥²Ö­zg§¶È­ßÛ+mæ庺ò{ej)Þu¼5«­¢+ØÀÌØíôQÉÕ)áÕÑ ÅÕ½Ðí%ÀÌØíQ¡¸5ͽà À°ÌäíåäÌäì°ÌäíQ½Ñ°Ý¥¸ÌÌìÌäì¤ÅÕ½Ðì

Good Luck. :)

Edit:

Fixed typo.

This bugged post edit function is annoying. :)

Edited by FreeFry
Link to comment
Share on other sites

@SmOke_N

First I tell you I want to dynamically load an If statement into my function and you tell me this:

It executes an expression, not a conditional statement.

You may want to look at AutoIt3ExecuteLine or AutoIt3ExecuteScript for the tasks you are actually trying to accomplish (since it seems you are more trying to use this similar to a DLL than an actual script file).

Then I go try it and you tell me this:

Think about your logic here.

How does the script know what $b equal?

I really don't understand what you're doing... and can't for the life of me follow any logic trail what so ever. Because what you seem to be wanting to do is have the non-ran script contain variable data already. Sorry, the logic just doesn't flow for me... so good luck.

I think it's a bit ironic. You are of course right , what was I thinking....

Link to comment
Share on other sites

If you want to return a result from the code being run when using the /AutoIt3ExecuteLine approach I guess you would have either to write the result to a file and read it from the main program, or use a TCPSend approach(a little overkill though), or perhaps a RegisterMessage, _SendMessage approach is viable.

Thanks...

I'll be looking into that as soon as I wake up manjana.../AutoIt3ExecuteScript by the looks of it.

Looks like someone is having similar problems too:

http://www.autoitscript.com/forum/index.php?showtopic=63528

Link to comment
Share on other sites

  • Moderators

@SmOke_N

First I tell you I want to dynamically load an If statement into my function and you tell me this:

Then I go try it and you tell me this:

I think it's a bit ironic. You are of course right , what was I thinking....

Yeah? You're talking about two different things there... 1. Execute, which is the first quote you quoted from me... and 2. AutoIt3ExecuteLine which is the 2nd quote you quoted from me... How in the hell is that ironic?

I think the irony is apparent, but don't "think" it's with anything I stated.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yeah? You're talking about two different things there... 1. Execute, which is the first quote you quoted from me... and 2. AutoIt3ExecuteLine which is the 2nd quote you quoted from me... How in the hell is that ironic?

I think the irony is apparent, but don't "think" it's with anything I stated.

Look man, the examples from Post#4 and Post#9 in this thread actually work. When you get off that high horse you are riding, and get it through your head that there is no logic behind them and they are simply proofs of concept, and actually have some related code to contribute...I will be thrilled to hear back from you.

Link to comment
Share on other sites

  • Moderators

Look man, the examples from Post#4 and Post#9 in this thread actually work. When you get off that high horse you are riding, and get it through your head that there is no logic behind them and they are simply proofs of concept, and actually have some related code to contribute...I will be thrilled to hear back from you.

When you post the "supporting" code, so someone actually can decipher what the hell you are doing... You may be able to dismount me from this horse above... But until then, enjoy the ride.

It should be abundantly apparent that you make no sense, you've had two people try to write/decipher what they thought you were doing... and yet you still don't have/get it. I'm beginning to think it's one of those "Ancient Chinese Secret" (Play on an old Tide commercial) scripts... If that's the case, step up and write a recreation script for heavens sake.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

When you post the "supporting" code, so someone actually can decipher what the hell you are doing... You may be able to dismount me from this horse above... But until then, enjoy the ride.

It should be abundantly apparent that you make no sense....

You don't know what you are talking about, and since you have nothing to offer in terms of advice you go flooding in peoples topics trying to make people feel bad about what they are trying to do. That should explain clearly why you have so many freaking posts. How many times did you post in this topic with nothing useful to say?

And just to make you feel more stupid, here is my function executing a dynamically loaded conditional statement:

;testingDynFuncs
#Include <File.au3>
#Include <Array.au3>
Global $DynamicFuncs
Global $FuncString
If Not _FileReadToArray(@ScriptDir & "\testing2.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf
_ArrayDisplay($DynamicFuncs)

MsgBox(0, "",_CatchAReturn("31"))
Func _CatchAReturn($number)
    For $i = 1 To $DynamicFuncs[0]
        $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
        $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
        MsgBox(0, "",$var[0]&' - '&$var1[0])
        If Execute($var[0]) Then Return Execute($var1[0])
    Next
EndFunc  ;<===_CatchAReturn

testing2.au3

If $number < 30 Then Return $number + 5
If $number > 30 Then Return $number - 5

The above function returns number 26, so eat bs.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...