Jump to content

How to execute a variable as function


Recommended Posts

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

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

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

Link to comment
Share on other sites

  • Moderators

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.

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

  • Moderators

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.

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...