Sign in to follow this  
Followers 0
juk

Using Call to call a function with parameters?

14 posts in this topic

I have a master script that has a for-next loop in which it calls other functions in other files (files are #included of course). I need to call ProgressBar and LogToFile functions in every loop also. Like so:

$length=UBound($files)-1
for $j=0 to $length Step +1
    ProgressBar($files[$j])
    Sleep($sleep)
    $p = Call($files[$j])
    LogToFile($files[$j], $p)
Next
I have an array ($files) that has the function calls as strings. Now I found out that Call function doesn't support calling a function with parameters. Is there another way I could keep the simple loop and call the functions with parameters?

-juk

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have a master script that has a for-next loop in which it calls other functions in other files (files are #included of course). I need to call ProgressBar and LogToFile functions in every loop also. Like so:

$length=UBound($files)-1
for $j=0 to $length Step +1
    ProgressBar($files[$j])
    Sleep($sleep)
    $p = Call($files[$j])
    LogToFile($files[$j], $p)
Next
I have an array ($files) that has the function calls as strings. Now I found out that Call function doesn't support calling a function with parameters. Is there another way I could keep the simple loop and call the functions with parameters?

-juk

<{POST_SNAPBACK}>

you don't have to use the Call function... you can call the function like any of the default functions it it's #include'ed (#included? bah whatever) example

;in script1
Func MsgBoxThis($x)
msgbox(0,"blah?",$x)
EndFunc

;in script 2
#include <script1.au3>
$tell = InputBox("? ? ?", "Tell me what to say....")
MsgBoxThis($tell)
Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

you don't have to use the Call function... you can call the function like any of the default functions it it's #include'ed (#included? bah whatever) example

<{POST_SNAPBACK}>

I know, but I need to run the ProgressBar and LogToFile functions (as you see in my code) in every loop so how can I call the other functions that are in the $files array? The number of elements (=function calls) in $files -array can change and ProgressBar and LogToFile have to be run in between other funtions.

-juk

Share this post


Link to post
Share on other sites

If the elements in the array are properly formatted as AutoIt commands, or with some programmatic manipulation they can be, then Execute() is most likely for you.

Share this post


Link to post
Share on other sites

I know, but I need to run the ProgressBar and LogToFile functions (as you see in my code) in every loop so how can I call the other functions that are in the $files array? The number of elements (=function calls) in $files -array can change and ProgressBar and LogToFile have to be run in between other funtions.

-juk

<{POST_SNAPBACK}>

sorry, maybe i'm just being stupid, but i still don't understand where you're having an issue... here's some code...

script 1:

#include <stuffdoer.au3>
$length=100
ProgressOn("Progress Bar","Stuff is Happening",0,0)
Global $j 
$j = 0
while 1
    $j = stuffdoer($j)
;MsgBox(0,"blah",$j)
        ProgressSet($j/$length*100,$j/$length*100 & "%")
    sleep(10)
    if $j = $length then ExitLoop
    WEnd

script 2 that is called during the loop...

Func StuffDoer($x)
    Return($x + 1)
EndFunc

you can have a control variable that is incremented in your outermost loop and no matter how many other functions/scripts whatever you call, your progress will still do what you want it to if you do it right....i hope this example helps...


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I dont if that works but maybe you had a chance if you used

Call(String(Files[$j])) or Execute(...) instead....

Test it and tell me....

<{POST_SNAPBACK}>

Call(String($blah[$j])) works like it would work without theString function in there, meaning I still can't use Call to call a function using parameters. So that won't help.

I installed the latest beta version so that I could try that Execute thingy, but when I do Beta Run or Beta Compile from SciTE it just pops up an AutoCheck window telling: ERROR: Execute(): undefined function. What's wrong?

-juk

Share this post


Link to post
Share on other sites

sorry, maybe i'm just being stupid, but i still don't understand where you're having an issue... here's some code...

*clip*

you can have a control variable that is incremented in your outermost loop and no matter how many other functions/scripts whatever you call, your progress will still do what you want it to if you do it right....i hope this example helps...

<{POST_SNAPBACK}>

Maybe I'm not explaining myself clearly enough. See, you're calling only StuffDoer() in your script, but I need to call different functions that are listed (in an array, which is created) before the loop.

Like for example:

$files=_ArrayCreate( _
    "TheFirstFunction", _
    "SecondOne", _
    "Third", _
    "LastOne(5,3)")
The variable name "files" is a bit misleading. I used to have filenames listed in the array and then call RunWait to run autoit.exe with the filename as a commandline parameter, but now I need those functions to return something back, hence this mess.

The first three function calls would work fine with Call(), but the LastOne needs parameters. And the contents of the array might change so that it'd be calling a dozen functions with parameters, so I'd rather not hardcode the funtion calls.

-juk

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The first three function calls would work fine with Call(), but the LastOne needs parameters. And the contents of the array might change so that it'd be calling a dozen functions with parameters, so I'd rather not hardcode the funtion calls.

-juk

<{POST_SNAPBACK}>

You could put your params in a global array.

e.g, before each call,

$aParams[0] = NumOfParams
$aParams[1] = param1
$aParams[2] = param2
$aParams[3] = param3
.
.
.
Edited by SumTingWong

Share this post


Link to post
Share on other sites

You could put your params in a global array.

e.g, before each call,

$aParams[0] = NumOfParams
$aParams[1] = param1
$aParams[2] = param2
$aParams[3] = param3

<{POST_SNAPBACK}>

Heh, that might do the trick. Though it would have to be multidimensional array if I wanted the parameters for all possible functions to be included.

But all that sounds too macgyveristic and complicated (I'd have to change every function declaration). I'm even thinking of writing a script that writes the required function calls to a file in a loop and then includes the file into the main script and runs it after that! Blah, I'd rather get that Execute() to work or a better version of Call(). Btw, anyone had similar problems with Execute (see a couple of posts previous)?

-juk

Share this post


Link to post
Share on other sites

You could put your params in a global array.

<{POST_SNAPBACK}>

Actually, that was a relatively simple way to get this working! Thanks! :)

-juk

Share this post


Link to post
Share on other sites

Actually, that was a relatively simple way to get this working! Thanks! :dance:

-juk

<{POST_SNAPBACK}>

Good....remember, always KISS! :whistle:

Share this post


Link to post
Share on other sites

I installed the latest beta version so that I could try that Execute thingy, but when I do Beta Run or Beta Compile from SciTE it just pops up an AutoCheck window telling: ERROR: Execute(): undefined function. What's wrong?

SCiTe doesnt have the latest definitions included.So it thinks it is a UDF and searches for Func Execute() in the script.If you press continue it will work fine.

Share this post


Link to post
Share on other sites

SCiTe doesnt have the latest definitions included.So it thinks it is a UDF and searches for Func Execute() in the script.If you press continue it will work fine.

<{POST_SNAPBACK}>

So it does. I didn't realize to do that with Beta Run as I tried with regular Build. Thanks!

-juk

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