Sign in to follow this  
Followers 0
JonathanChan

Execute Function Assignment Limitation?

4 posts in this topic

Hi all,

How come the following fails:

execute('$tmp="test"')
msgbox(0,@error,"error is: " &@error)

According to the docs, @error code of 0 is good, anything else means the code failed. I get an error code of 1. Why does the execute code fail on assignment statements?

Thanks,

Jonathan

Share this post


Link to post
Share on other sites



Variable $tmp has do be defined before you can test it. You know that function Execute doesn't do an assignment but a comparison? That's why you get "False" as a result.

Global $tmp
$Result = Execute("$tmp='test'")
MsgBox(0, @error, "Result is: " & $Result & ", error is: " & @error)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Advice:

u can call a function using Execute

So make a function that will assign the values to a variable

if u use string for both variable and its value then use

Assign and Eval functions to pass it as a parameter to the respective Function

This will give you successful results ;)

Code:

ConsoleWrite(Execute('Assign ( "tmp", "" , 2 )')&@CRLF) ;Declare Global
ConsoleWrite(Execute('Assign ( "tmp", "test" , 4 )')&@CRLF) ; Assign a Value and Fail if the Var hasnt been already Declared
MsgBox(0,"",Eval('tmp')) ;Show the Value of The Var

Regards

Phoenix XL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

thanks for the advice about Assign. I learned some new behavior about autoit. I'm trying to provide a configurable session in my script to allow people to put code snippets in autoit and for it to execute. The assignment was one of the things that was not working. I'm guessing I will find other things that doesn't exactly work like if you were writing a regular script.

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

  • Similar Content

    • hawkair
      By hawkair
      Hi
      I am trying to insert line numbers in to a string
      with this script
      Func _MyInc () Static Local $i = 0 $i += 1 Return $i EndFunc Exit _InsertLines() Func _InsertLines()     $String = "A" & @CRLF & "B" & @CRLF & "C" & @CRLF & "D" $NewString =  Execute("'" & StringRegExpReplace($String,"[\r\n]*",  "' & _MyInc () & '\1" ) & "'") MsgBox (0, "", $NewString) EndFunc but I get this:
      1A23B45C67D8
      I never really could master how Execute works here and I always get some working example and make substitutions.
      But this is the closest i could get...
       
    • cherrylatte
      By cherrylatte
      hi
      I'm trying to execute files 
      I want it to run in order.
      for instance, if there's folder like below, I want to run 1.exe > 2.exe > 3.exe
      root folder
        |___folder 1 > 1.exe
        |___folder2 > 2.exe
        |___folder3 > 3.exe
       
      What I did to do the above, was to make a text file that contains the path to each of those files and put those in array form.
      but copying and pasting every path of those files into a text file is very exhausting thing to do when there's like hundreds of files to execute.
      So I was wondering if there is a simple way to run those files.
      I'd be thankful if anybody answers it. 
       
       
    • LegitStack
      By LegitStack
      Is there a way to execute the text inside a variable is if it was part of the script?
      In this example I'd like to get a message box pop up but I don't: 
      ;testme.au3   local $var = 'msgbox(64,"hello","world")'   $var is there a command that can be used like maybe 'Exec' or 'Execute' or something?
        local $var = 'msgbox(64,"hello","world")'   Execute $var  
    • algiuxas
      By algiuxas
      Hello,
      I need to assign data to array:
      Global $Test[3][4] $Array = "Test" SetArrayData($Array,"Hello world!",1,3) ConsoleWrite($Array[1][3]&@CRLF) Exit Func SetArrayData($Array,$Data,$1,$2) $Array[$1][$2] = $Data; <-- ??? EndFunc I need that somebody would help me with that function
    • WoodGrain
      By WoodGrain
      Hi All,
      I've got a script setup to drop a program into a temp folder and then run it from there, but I have mixed results, the Run() command will work on some computers but not others. The file will be placed into the temp folder in all cases. Running AutoIT 3.3.14.0. The computers are all either Win 7 or 8.1, x64 (exe is compiled to x64 too), UAC is off, all have local admin rights - if I've missed something ask and I'll update the details.
      If Not FileExists (@TempDir & "\HCTB") Then DirCreate(@TempDir & "\HCTB") FileInstall("G:\IT\Downloads\TB\12.0.45471\Host\TB_Setup-sif7r8pgcq.exe", @TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe", 1) Local $iPID = Run(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe", "") Any suggestions?
      Thanks!