Sign in to follow this  
Followers 0
ptrex

Dynamical functions

17 posts in this topic

Let' s say you make a script with all the availabel #includes in it. And a small GUI with a Control on it.

When this is compiled, does AutoIT incorporate all the functions defined in the #Includes. Even if they are not called the script elsewhere ?

If not, my question stops here.

If yes. Then it gets interesting.

When all the functions are incorporated, would it not be very interesting to be able to access (call) these functions. In a kind of special Function Control (and or syntax). Because then these functions would become dynamically.

Let me try to give some example:

Lets suppose that this Special function control is the Quote, and that in the script I have a $var = "1".

I could define a dynamic function like this.

$var &= 10

Where the result would be "111". This is dynamically because I can change the string "10" in the control without having to change it hard coded and recompile it again.

This is of course a very simplistic example.

But it can be very interesting if this Special Function Control recognizes all the functions in the #includes.

Maybe it doesn't not need to be a special control, but rather a special syntax like this,

#StringMid( "string", 2, 3) #& "Just an example"

Everything that starts with a # is recognised as function, instead of just normal text.

Even better is when the outcome of this special control is stored in a variable, Like

$Function = GUICtrlCreateFunction

If that GUICtrlFunction contains something like : #Sqrt(2) + 1, $Function would be 2.4142135623731

But you could change this dynamically in the GUI to #Sqrt(20) + 15 and use the $Funtion variable somewhere in the script.

All the date, time, math, string, ... functions woud be available.

Of course the example are symplistic, but it' s just to illustrate the concept.

I' ll hear from you all wether this is day dreaming or realistic B)

Share this post


Link to post
Share on other sites



of course you could do it by now as well

you just have to know all the functions then you can programm your code around it

while 1
if guigetmsg() = $button then
if stringleft(guictrlread($input), 11) = "#stringleft" then
$replace = stringreplace(guictrlread($input), "#stringleft(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringleft ($split[1], $split[2])
msgbox (0, "test", $function)
endif
endif
wend

should be possible, but needs loads of programming (by now)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

well, you just need to do the programming once

for each function about 5 lines

should be possible to do this in about 1 or 2 days B), but as i don't need it i'm not so foolish doing the job :o

maybe i do 1 function a day, but that will take for ages till i'm finished

we could do the programming in a group if someone needs it

Share this post


Link to post
Share on other sites

while 1
if guigetmsg() = $button then
select
case stringleft(guictrlread($input), 11) = "#stringleft"
$replace = stringreplace(guictrlread($input), "#stringleft(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringleft ($split[1], $split[2])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 12) = "#stringright"
$replace = stringreplace(guictrlread($input), "#stringright(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringright ($split[1], $split[2])
msgbox (0, "test", $function)
endselect
endif
wend

added stringright B)

Share this post


Link to post
Share on other sites

ok here is some more

#include <guiconstants.au3>
#include <string.au3>
GUICreate("Main", 300, 200)
$input = GUICtrlCreateInput ("", 10, 10, 200)
$button = GUICtrlCreateButton ("BUtton", 10, 40)
GUISetState()
while 1
if guigetmsg() = $GUI_EVENT_CLOSE then Exit
if guigetmsg() = $button then
select
case stringleft(guictrlread($input), 11) = "#stringleft"
$replace = stringreplace(guictrlread($input), "#stringleft(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringleft ($split[1], $split[2])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 12) = "#stringright"
$replace = stringreplace(guictrlread($input), "#stringright(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringright ($split[1], $split[2])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 14) = "#stringencrypt"
$replace = stringreplace(guictrlread($input), "#stringencrypt(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = _stringencrypt ($split[1], $split[2], $split[3])
msgbox (0, "test", $function)
endselect
endif
wend

+_stringencrypt B)

omg am i bored

Share this post


Link to post
Share on other sites

@Nuffilein805

Thanks for the effort, but this is not the correct approach.

Because specifying #include ... in the beginning of every script means that everything is INCLUDED.

So no need to reprogram araound it.

Only find a way to access it.

Don' t work hard be smart is what goes here.

The only thing is, is it technically possible to access it ?

Not without the help of the developers, that's for sure.

Because there is no function control that exists yet, or no syntax is available to recognize the included functions.

Share this post


Link to post
Share on other sites

hm, ok, but it's funny to write these little 5-liners B)

one more :graduated:

#include <guiconstants.au3>
#include <string.au3>
GUICreate("Main", 300, 200)
$input = GUICtrlCreateInput ("", 10, 10, 200)
$button = GUICtrlCreateButton ("BUtton", 10, 40)
GUISetState()
while 1
if guigetmsg() = $GUI_EVENT_CLOSE then Exit
if guigetmsg() = $button then
select
case stringleft(guictrlread($input), 11) = "#stringleft"
$replace = stringreplace(guictrlread($input), "#stringleft(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringleft ($split[1], $split[2])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 12) = "#stringright"
$replace = stringreplace(guictrlread($input), "#stringright(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = stringright ($split[1], $split[2])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 14) = "#stringencrypt"
$replace = stringreplace(guictrlread($input), "#stringencrypt(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
if $split[0] = 3 then $function = _stringencrypt ($split[1], $split[2], $split[3])
if $split[0] = 4 then $function = _stringencrypt ($split[1], $split[2], $split[3], $split[4])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 10) = "#stringlen"
$replace = stringreplace(guictrlread($input), "#stringlen(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = StringLen ($split[1])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 12) = "#stringlower"
$replace = stringreplace(guictrlread($input), "#stringlower(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
$function = StringLower ($split[1])
msgbox (0, "test", $function)
case stringleft(guictrlread($input), 10) = "#stringmid"
$replace = stringreplace(guictrlread($input), "#stringmid(", "")
$replace = stringreplace($replace, ")", "")
$split = stringsplit($replace, ",")
if $split[0] = 3 Then $function = StringMid ($split[1], $split[2], $split[3])
if $split[0] = 2 then $function = StringMid ($split[1], $split[2])
msgbox (0, "test", $function)
endselect
endif
wend

you gotta know all the functions

and you're not allowed to use "

but its a funny thing to do :o

maybe i do all the functions 1 day

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

The example works only for 1 function, like

#stringmid("testitagain,6,2) #& "test"

Retuns "it" but it should read all the way down and return "ittest"

Ofcourse I understand your Gui was just an example, and doesn't include all the functions yet.

But I mean coding it like this might make it hard to proceed, when using combination of functions in 1 Control.

Isn' t it ?

Share this post


Link to post
Share on other sites

Am I missing something? Aren't you just making a poor implementation of the Execute() function?

Share this post


Link to post
Share on other sites

@Valik

Hi.

I looked in the helpfile for the function execute(). And indead it goes in that direction;

But how do you see that in combination with a Gui control like shown in Nuffilein805 example ?

Than again I could not read from the helpfile if the execute() understands all the math, date, time, .. functions and or combinations of it.

But it sure goes in that direction, good noticing of you !!

Share this post


Link to post
Share on other sites

First of all, the code as posted above is retarded. Calling GUIGetMsg() twice like that will cause messages to be lost. Call it once and store the return value, then do conditional checks on that value. If you do not believe me, open the GUI and then immediately press the close button. If it closes, congratulations, try again. I had to click it 3 times at one point because the message kept getting lost.

Execute() is limited. You can talk to JP about why that is. However, it looks to me like using Execute() instead of the Case structure will work. The best way is to just play with the function.

<rant>

I do not condone the use of Execute(). Executing dynamic code, particularly from user input is a bad idea. "Dynamic Code" sounds cool on paper but it is almost always a sign of a poor idea or a poor solution to a problem.

>/rant>

Share this post


Link to post
Share on other sites

@Valik

I agree that the sample code provided isn' t working perfectly. But it's rather the concept what is important.

I don' t agree with your last statement

Executing dynamic code, particularly from user input is a bad idea ...

almost always a sign of a poor idea or a poor solution to a problem

Because this is what Excel is about. Excel is 1 container full of dynamic functions, like

=CHAR(35) returns "#"

I think that it opens more possibilties for creative usaged and less coding.

There are a lot of applications and programming languages which support dynamic functions.

I would say that all Excel users show a sign of poor ideas or solutions !!

Share this post


Link to post
Share on other sites

Because this is what Excel is about. Excel is 1 container full of dynamic functions, like

=CHAR(35) returns "#"

The last time I checked, Excel wasn't a language. I see no relevance to Excel and the discussion of dynamically generated code.

I think that it opens more possibilties for creative usaged and less coding.

No, understanding the language you are using and how to use its conventional features open the door for creative usage and less coding. There are small, niche uses for functions like Execute(), however, those are few and far between. Execute() will be used incorrectly a significant number of times more than it will be used correctly because people are looking for what they perceive to be the cheap, easy solution instead of trying to find a more correct solution. Look at Call() for example. It allows for the execution of run-time determined user-defined functions. However, in its current incarnation, its about 99% useless but people are posting scripts using it (incorrectly) at least twice a month.

There are a lot of applications and programming languages which support dynamic functions.

Supporting them and having a genuine, legitimate use for them are two entirely different things. There are very few uses for dynamic code in a language as structured as AutoIt.

Share this post


Link to post
Share on other sites

@Valik

I don' t think we are talking the same language here.

I am not going to arm wrestle with you, about wether Excel is a language are not.

It was not the point anyway.

Here is a working example of what I meant.

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

But I can't still agree why this is a bad idea or poor solution.

Executing dynamic code, particularly from user input is a bad idea ...

almost always a sign of a poor idea or a poor solution to a problem

Thanks anyjow to put me on the right track.

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