Sign in to follow this  
Followers 0
crazyjts

How do I increment a variable name

14 posts in this topic

I'm trying to figure out how to increment a variable while working thru a do...until loop.

Func Deploy () ;dbl-clicks the location
    $k = 1
    Do
        $CrntLocx = $Loc & $k & x ;I'm trying to get this value to increment each time thru e.g Loc1x, Loc2x, Loc3x, etc.
        $CrntLocy = $Loc & $k & y ;I'm trying to get this value to increment each time thru e.g Loc1y, Loc2y, Loc3y, etc.
        MouseClick ("left",$CrntLocx,$CrntLocy,2)
        Sleep(1000)
        $k = $k + 1
    Until $k = 10
EndFunc

Thanks for any help

Share this post


Link to post
Share on other sites



I'm trying to figure out how to increment a variable while working thru a do...until loop.

Func Deploy () ;dbl-clicks the location
    $k = 1
    Do
        $CrntLocx = $Loc & $k & x ;I'm trying to get this value to increment each time thru e.g Loc1x, Loc2x, Loc3x, etc.
        $CrntLocy = $Loc & $k & y ;I'm trying to get this value to increment each time thru e.g Loc1y, Loc2y, Loc3y, etc.
        MouseClick ("left",$CrntLocx,$CrntLocy,2)
        Sleep(1000)
        $k = $k + 1
    Until $k = 10
EndFunc

Thanks for any help

What you need is Eval I think

$CrntLocx = Eval("Loc" & $k & "x")
$CrntLocy = Eval("Loc" & $k & "y")

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

I ended up getting the Execute function to do what I wanted.

$CrntLocx = Execute("$Loc" & $k & "x")
$CrntLocy = Execute("$Loc" & $k & "y")

Share this post


Link to post
Share on other sites

Assign() function will help you here to define your variables and assign them any value you need.. Eval() will help u in using the value stored in those variables.


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

You should never use Execute in your life trust me.

Why?

I'm asking WolfWorld.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Facing a tough audience is not easy.

I'll be rating you WolfWorld. Every word counts.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Why?

I'm asking WolfWorld.

First Sorry for the late reply.

Autoit is a Weak Type (WT) language. As you may know: P this is already a weakness in the language (doesn’t get me wrong, WT language is easy to learn and use but in a bigger program it will get confusing and lead to the wrong result)

Using Execute even forces that Weak Typed to be SUPER I mean SUPER (the weakest it can get!). Autoit does not check the syntax of the “execute” at all (string that you put in).

And does not throw any error, if something goes wrong, try this Execute("MsgBox(0,'1','1')MsgBox(0,'2','2')") As yourself is this a valid syntax?

The answer is yes and no, yes it runs properly, No it's not a valid syntax. There is no warning at ALL. You could evidently execute two commands without knowing. Now not everything works in execute, and Obfuscator does not like it also. It leads to hard to find bugs, the syntax does not highlight, Thing of Execute ("$i =+ 1") the =+ should be += but he typed in wrong. Is there any way to find that out? The answer is no. EVEN at RUNTIME.

Look (assuming it work out in this case the ‘"’ is not balance so it won't work out)

Execute ("MsgBox(0, ""'Box"'"",""Ink"")")

Where does it go wrong?

Lots of you, okay all of you without syntax highlighting will think Box is the problem BUT! Box is a valid string the problem is with Ink.

This all prove the point of not using Execute (so you and run anything after compile), like not using Pointers in c(for speed) unless you really need to.

Is this okay trancexx

Share this post


Link to post
Share on other sites

First Sorry for the late reply.

Autoit is a Weak Type (WT) language. As you may know: P this is already a weakness in the language (doesn’t get me wrong, WT language is easy to learn and use but in a bigger program it will get confusing and lead to the wrong result)

Using Execute even forces that Weak Typed to be SUPER I mean SUPER (the weakest it can get!). Autoit does not check the syntax of the “execute” at all (string that you put in).

And does not throw any error, if something goes wrong, try this Execute("MsgBox(0,'1','1')MsgBox(0,'2','2')") As yourself is this a valid syntax?

The answer is yes and no, yes it runs properly, No it's not a valid syntax. There is no warning at ALL. You could evidently execute two commands without knowing. Now not everything works in execute, and Obfuscator does not like it also. It leads to hard to find bugs, the syntax does not highlight, Thing of Execute ("$i =+ 1") the =+ should be += but he typed in wrong. Is there any way to find that out? The answer is no. EVEN at RUNTIME.

Look (assuming it work out in this case the ‘"’ is not balance so it won't work out)

Execute ("MsgBox(0, ""'Box"'"",""Ink"")")

Where does it go wrong?

Lots of you, okay all of you without syntax highlighting will think Box is the problem BUT! Box is a valid string the problem is with Ink.

This all prove the point of not using Execute (so you and run anything after compile), like not using Pointers in c(for speed) unless you really need to.

Is this okay trancexx

Well, it's always important to know that there is syntax and there is semantics.

Is it ok by me if I draw some parallels to Run() and related functions and say they equably suck?

I wonder what would Manadar say about your Execute thoughts.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Other people (Need I say names? I think not.) on this forum are far more knowledgeable on this subject, it would be wise to keep quiet on this one before I make a word slip. :D

The only thing I can say for sure about Execute, is that it is a useful function if you use it the right way.

#include <Array.au3>

Dim $aArray[3][2] = [ [ 'a', 'b' ] , _
[ 'c', 'd' ], _
[ 'e', 'f' ] ]

$iDimensions = UBound($aArray,0)
$sDimensions = ""

for $i = 1 to $iDimensions
    $sDimensions &= "[0]"
Next

$iValue = Execute("$aArray"&$sDimensions)

MsgBox(0,"",$iValue) ; prompts with 'a'

Share this post


Link to post
Share on other sites

The only thing I can say for sure about Execute, is that it is a useful function if you use it the right way.

Like with any other function, right?

WolfWorld said "You should never use Execute in your life trust me" and gives what seems to be explanation only in traces. Or am I reading wrong?

The way I see it, that's not good WolfWorld.


♡♡♡

.

eMyvnE

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