Jump to content

Use Variable as Line


 Share

Recommended Posts

is it possible to store a line of code in a variable and then call it by just using the variable:

$Line1 = MsgBox(0,"Message","Line1"

then in to run MsgBox(0,"Message","Line1") I would only have to use $Line1

the point of this is so that I can store a segment of a code in an Ini File

Link to comment
Share on other sites

What i need is for the variable to contain the whole command

$Msg = MsgBox(0,"","Message")

then to call it simply $Msg not MsgBox(0,"",$Msg)

When you're assigning a variable to a MsgBox all you're trying to do is get the return information on the button pressed. In the case of your MsgBox you've allowed for an OK button. If you were to check out what the variable is you would see that it's '1' meaning that the OK button was pressed. So to answer your question, no it can't be done.

Link to comment
Share on other sites

When you're assigning a variable to a MsgBox all you're trying to do is get the return information on the button pressed. In the case of your MsgBox you've allowed for an OK button. If you were to check out what the variable is you would see that it's '1' meaning that the OK button was pressed. So to answer your question, no it can't be done.

You mean as far as you know it can't be done.

From the Autoit3 help

To execute a single line of code, use the command:

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')

So in AcidCorps' case you would need

To execute a single line of code, use the command:

Run(@AutoItExe & ' /AutoIt3ExecuteLine $Line1')

But you need to have first

$Line1 = "msgBox(0,'message','something')"

You would have to be careful in case $Line1 contained variables, so in this case I would format $Line1 first using StringFormat.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

HI,

Global $scriptlines[2] = ['"consolewrite(""test"")"', '"MsgBox(0, ''Hello World!'', ''Hi!'')"']

For $i = 0 To UBound($scriptlines) - 1
    Run(@AutoItExe & ' /AutoIt3ExecuteLine  ' & $scriptlines[$i])
Next

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

You mean as far as you know it can't be done.

From the Autoit3 help

So in AcidCorps' case you would need

To execute a single line of code, use the command:

Run(@AutoItExe & ' /AutoIt3ExecuteLine $Line1')

But you need to have first

$Line1 = "msgBox(0,'message','something')"

You would have to be careful in case $Line1 contained variables, so in this case I would format $Line1 first using StringFormat.

I knew I should have caveated what I was saying knowing all too well someone would take the liberty to find an alternative solution. My correct reply should have been, "No it can't be done in the manner you desire. " :)

Link to comment
Share on other sites

You mean as far as you know it can't be done.

From the Autoit3 help

So in AcidCorps' case you would need

To execute a single line of code, use the command:

Run(@AutoItExe & ' /AutoIt3ExecuteLine $Line1')

But you need to have first

$Line1 = "msgBox(0,'message','something')"

You would have to be careful in case $Line1 contained variables, so in this case I would format $Line1 first using StringFormat.

HI,

Global $scriptlines[2] = ['"consolewrite(""test"")"', '"MsgBox(0, ''Hello World!'', ''Hi!'')"']

For $i = 0 To UBound($scriptlines) - 1
    Run(@AutoItExe & ' /AutoIt3ExecuteLine  ' & $scriptlines[$i])
Next

So long,

Mega

Perfect martin & Xenobiologist

Why would you call a messagebox from a messagebox?

It was just an example

Link to comment
Share on other sites

Ok so I tried running this as a function

$Line1 = MsgBox(0,"","Hello World!")
_RunVar($Line1)

Func _RunVar($iVar, $iOpt = 0)
    Global $scriptlines[2] = ['"consolewrite(""test"")"', '$iVar']
    For $i = 0 To UBound($scriptlines) - 1
    If $Opt = 0 Then Run(@AutoItExe & ' /AutoIt3ExecuteLine  ' & $scriptlines[$i])
    If $Opt = 1 Then RunWait(@AutoItExe & ' /AutoIt3ExecuteLine  ' & $scriptlines[$i])
Next
EndFunc

it runs fine showing MsgBox(0,"","Hellow World!") but then after it successfully runs it shows the fallowing error message

Line 1:

$iVar

Error: Expected a "=" operator in assignment statement.

Edit: Typo

Edited by AcidCorps
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...