Sign in to follow this  
Followers 0
AcidCorps

Use Variable as Line

11 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$msg = "Hello World"

MsgBox(0,"",$msg)

Edited by weaponx

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Why would you call a messagebox from a messagebox?

Share this post


Link to post
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. " :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Fixed:

$Line1 = Run("Notepad.exe")
_RunVar($Line1)

Func _RunVar($iVar)
    Global $scriptlines[2] = ['"consolewrite(""test"")"', '$iVar']
    For $i = 0 To UBound($scriptlines) - 1
    Next
EndFunc

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