Sign in to follow this  
Followers 0
supersonic

How to execute a variable as function

11 posts in this topic

#1 ·  Posted (edited)

Hello to everybody reading my post,

I'm converting our batch script (*.cmd) to AutoIt scripts.

Therefore I have to convert the following batch command sequence:

@echo off

set test=PING.EXE

%test% 192.168.0.1

Any ideas?

Greets,

-supersonic.

Edited by supersonic

Share this post


Link to post
Share on other sites



Hello to everybody reading my post,

I'm converting our batch script (*.cmd) to AutoIt scripts.

Therefore I have to convert the following batch command sequence:

@echo off

set test=PING.EXE

%test% 192.168.0.1

Any ideas?

Greets,

-supersonic.

Can you use the Ping function in the help file?

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.

Share this post


Link to post
Share on other sites

This is just an example script.

Share this post


Link to post
Share on other sites

This is just an example script.

And? There are plenty of "examples" of batch conversion on the forum if you are just looking for a generalization on how to do it for many different functions.

I think my point was to look at the help file for standard functions before you try to recreate them all using cmd.exe.

But I'll humor you all the same:

http://www.autoitscript.com/forum/index.ph...st&p=308667

http://www.autoitscript.com/forum/index.ph...st&p=313340


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.

Share this post


Link to post
Share on other sites

Hm... Maybe you got me wrong...

When I parse text file value - e. g. "exampleFunc()" - returns.

This value is a name of a function.

To call this function I could use this:

If $i = "exampleFunc()" Then

$returnCode = exampleFunc()

EndIf

More useful could be a command like this:

CallAsAFunction($i)

Any ideas?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hm... Maybe you got me wrong...

When I parse text file value - e. g. "exampleFunc()" - returns.

This value is a name of a function.

To call this function I could use this:

If $i = "exampleFunc()" Then

$returnCode = exampleFunc()

EndIf

More useful could be a command like this:

CallAsAFunction($i)

Any ideas?

You answered your own question.

Call($i)

Edit:

Without the parenthesis in "exampleFunc()" of course... Would have to be "exampleFunc"

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.

Share this post


Link to post
Share on other sites

I tried this before but nothing happens.

Even when the function not exists, like:

$i = thisFuncNotExists

Call($i)

No error msg at all.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I tried this before but nothing happens.

Even when the function not exists, like:

$i = thisFuncNotExists

Call($i)

No error msg at all.

You have to handle the error.

$i = "thisFuncNotExists"

Call($i)

If @ERROR Then MsgBox(0,"","Function: " & $i & " does not exist")

EDIT: Good point rich

Edited by weaponx

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

That should be a syntax error on thisFuncNotExists because it's not a proper token though. Did you mean for it to be in quotes?

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

I tried this before but nothing happens.

Even when the function not exists, like:

$i = thisFuncNotExists

Call($i)

No error msg at all.

You can't call a function that doesn't exist.

Local $vCallFunc
Switch Random(1, 2, 1)
    Case 1
        $vCallFunc = "One"
    Case 2
        $vCallFunc = "Two"
EndSwitch

Call($vCallFunc)

Func One()
    MsgBox(64, "Info", "You called function one")
EndFunc

Func Two()
    MsgBox(64, "Info", "You called function two")
EndFunc

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.

Share this post


Link to post
Share on other sites

Shame on me. Of course it works like you said. I got it ... Better later than never!

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