Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Dynamic functions


  • Please log in to reply
14 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 07 November 2005 - 08:45 AM

Dynamics Functions

This is an example of a dynamic function.

You can use any AutoIT, Math, Date&Time, String, Variables, Macros, etc, or any combination of it.
Making it possible to change functions interactively with changing the hardcoded data.

And pass that result on to another function if needed.


AutoIt         
; ; PTREX dd 06/11/05 ; Dynamics Functions ; You can use any AutoIT, Math, Date&Time, String, Variables, Macros, etc, or any combination of it. ; Making it possible to change functions interactively with changing the hardcoded data. ; #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 $Form1 = GUICreate("Dynamic functions", 622, 441, 192, 113) $Edit1 = GUICtrlCreateEdit("", 48, 40, 553, 217, -1, $WS_EX_CLIENTEDGE) GUICtrlSetData($Edit1, "@ComputerName &chr(32) &stringRight(@OSVersion,2) &chr(32) &_Now() &chr(32)& $Var &chr(32) & sqrt(2) &chr(32) &_Calc()/2") $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


Thanks to Valik to put me on the right track.

Edited by ptrex, 14 September 2012 - 09:19 AM.








#2 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 07 November 2005 - 09:29 AM

There seems to be 1 limitation.

Calling a the _Calc (User Defined functions) return a 0 instead of 53.

This means that only External UDF's can be used, or Internal Variables.

This might be by design of the Excecute() function.

Maybe the developers can explain the behaviour ?

#3 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 07 November 2005 - 10:56 PM

its designd so that we cant "exploit" it.

to say it short: IMO its useless.

Edited by w0uter, 07 November 2005 - 10:57 PM.

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#4 Klaatu

Klaatu

    Prodigy

  • Active Members
  • PipPipPip
  • 198 posts

Posted 07 November 2005 - 11:28 PM

Yes, basically it's a gun with a trigger lock.
My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

#5 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 08 November 2005 - 11:17 AM

Thanks for the feedback.

Can you give me an example when it is exploited or dangerous to use an Internal defined function.

Just for my understanding.

Thanks

#6 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 08 November 2005 - 01:30 PM

when you use an encrypted filedelete string.
(not that you can encrypt the dos command DEL or something B))

atleast that was the example given to us.
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#7 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 08 November 2005 - 01:38 PM

OK clear.

Thanks

#8 Oldschool

Oldschool

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 254 posts

Posted 17 February 2008 - 09:35 AM

Hey Ptrex,

Have you ever been able to get a dynamic function to return something?

AutoIt         
;testingDynFuncs #Include <File.au3> #Include <Array.au3> Global $DynamicFuncs If Not _FileReadToArray(@ScriptDir & "\testing.au3", $DynamicFuncs) Then    MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)    Exit EndIf ;_ArrayDisplay($DynamicFuncs) Local $start Local $end For $i = 1 To $DynamicFuncs[0]     If StringInStr($DynamicFuncs[$i], "Func _CatchAReturn") Then $start = $i+1     If StringInStr($DynamicFuncs[$i], "EndFunc  ;<===_CatchAReturn") Then $end = $i-1 Next MsgBox(0, "",_CatchAReturn("25")) Func _CatchAReturn($number)     For $j = $start To $end         Execute($DynamicFuncs[$j])     Next EndFunc  ;<===_CatchAReturnƒo݊÷ Ù8b²+0…«b·l–†Šx®‰­zËbž®Ý«­¢+ÙÕ¹Œ} …э¡I•ÑÕɸ ˜ŒÀÌØí¹Õµ‰•È¤(€€€€€€€€€5͝   ½à À°€™ÅÕ½Ðì™ÅÕ½Ð찀˜ŒÀÌØí¹Õµ‰•È€¬€Ô¤(€€€€€€€€€5͝ ½à À°€™ÅÕ½Ðì™ÅÕ½Ð찀˜ŒÀÌØí¹Õµ‰•È€¬€Ð¤)¹‘Õ¹Œ€€ì™±Ðìôôõ} …э¡I•ÑÕɸƒo݊÷ Ù8^/{ +’ËaŠÇhzÉ赫­¢+ÙÕ¹Œ} …э¡I•ÑÕɸ ˜ŒÀÌØí¹Õµ‰•È¤(€€€%˜€˜ŒÀÌØí¹Õµ‰•È€™±Ðì€ÌÀQ¡•¸I•ÑÕɸ€˜ŒÀÌØí¹Õµ‰•È€¬ô€Ô(€€€%˜€˜ŒÀÌØí¹Õµ‰•È€™Ðì€ÌÀQ¡•¸I•ÑÕɸ€˜ŒÀÌØí¹Õµ‰•È€´ô€Ô)¹‘Õ¹Œ€€ì™±Ðìôôõ} …э¡I•ÑÕɸ



Any ideas?

EDIT: In other words I'm trying to execute an IF statement dynamically...

Edited by Oldschool, 17 February 2008 - 11:22 AM.


#9 Oldschool

Oldschool

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 254 posts

Posted 17 February 2008 - 11:34 AM

Or here is another example:

AutoIt         
#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) Local $start Local $end For $i = 1 To $DynamicFuncs[0]     If StringInStr($DynamicFuncs[$i], "Func _CatchAReturn") Then $start = $i+1     If StringInStr($DynamicFuncs[$i], "EndFunc  ;<===_CatchAReturn") Then $end = $i-1 Next MsgBox(0, "",_CatchAReturn("25")) Func _CatchAReturn($n)     Local $number = $n     For $j = $start To $end         $FuncString = $FuncString & $DynamicFuncs[$j]     Next     MsgBox(0, "", $FuncString)     Execute($FuncString)     Return $number EndFunc  ;<===_CatchAReturnƒo݊÷ Ø Ý¶­zËbž   h¢K%ŠG­†+ºÚ"µÍ‘[˜ÈÐØ]ÚT™]›Š ˆÌ ͎۝[X™ŠB‚UÚ[H BˆYˆ ˆÌ ͎۝[X™ˆ ›È Ì[ˆ    ˆÌ ͎۝[X™ˆ ÏH B‚HYˆ  ˆÌ ͎۝[X™ˆ ™ÝÈ Ì[ˆ   ˆÌ ͎۝[X™ˆ OH B‚H^]ÛÜ‚UÑ[™‘[™[˜ÈɛÏOOWÐØ]ÚT™]


There is no error when the script is executed, but the $number returned does not change...

#10 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,730 posts

Posted 17 February 2008 - 02:20 PM

This is simply a support question, there was no need to bring up a 2+ year old topic.

Edit:
Even I was confused on what you are asking.

Edit2:
Now I don't even know if I was confused :)
$nTest = 4 _ByRefFunc($nTest) MsgBox(0, 0, $nTest) Func _ByRefFunc(ByRef $nNum)     If $nNum <= 3 Then         $nNum += 2     Else         $nNum -= 2     EndIf     Return EndFunc
Is what I was assuming you were trying to do.

Edited by SmOke_N, 17 February 2008 - 02:26 PM.

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.


#11 James

James

    Universalist

  • MVPs
  • 10,222 posts

Posted 17 February 2008 - 07:16 PM

There was a syntax error?

#12 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 17 February 2008 - 07:31 PM

@All

What can I add more ?!

regards

ptrex

#13 James

James

    Universalist

  • MVPs
  • 10,222 posts

Posted 17 February 2008 - 07:35 PM

A nice new GUI would be good :)

#14 Oldschool

Oldschool

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 254 posts

Posted 18 February 2008 - 08:20 AM

This is simply a support question, there was no need to bring up a 2+ year old topic.

Edit:
Even I was confused on what you are asking.

Edit2:
Now I don't even know if I was confused :)
Is what I was assuming you were trying to do.


Guy, there is as much logic in my example as there is in a "Hello World!" script. In other words it's simply a proof of concept...

What's not to understand?
[testing] 0=MsgBox(0, "", "Hello World!")

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


#15 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 18 February 2008 - 08:26 AM

$return = Execute ("IsNumber ('abc')") MsgBox (0, "", $return)

Will fail, whereas,
$return = Execute ("IsNumber (10)") MsgBox (0, "", $return)

works... :)

Edited by Bert, 18 February 2008 - 08:26 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users