Page 1 of 1

transfer variables from autoit

Posted: 14 Dec 2017, 12:38
by Guest

Code: Select all

Local $name[10]
$name[0] = "adf"
$name[1] = "zcxv"
$name[2] = "agf"
$name[3] = "zxcv"
$name[4] = "adsf"
$name[5] = "qtq"
$name[6] = "dfsg"
$name[7] = "cbvn"
$name[8] = "fgjh"
$name[9] = "ytre"
For $i = 2 To UBound($name)-1
ClipPut($name[$i])
Send("+{INSERT}")
next


Can you help me plox?
How can I transfer it from autoit to ahk?
I want to have a set of variables
I want to put them in clipboard and send one by one starting with a number that I set in $i. If I set 0 it sends all variables, if I set 8 it sends to last variables.

Re: transfer variables from autoit

Posted: 14 Dec 2017, 13:57
by KuroiLight
do you mean convert that code into AHK? or send those variables to an AHK script?
if the first, this should be the equivalent:

Code: Select all

name := ("adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre")
for i, v in name {
    Clipboard := v
    Send, +{INSERT}
}

Re: transfer variables from autoit

Posted: 15 Dec 2017, 04:13
by Guest
KuroiLight wrote:do you mean convert that code into AHK? or send those variables to an AHK script?
if the first, this should be the equivalent:

Code: Select all

name := ("adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre")
for i, v in name {
    Clipboard := v
    Send, +{INSERT}
}
Thank you but it didn't send anything and it didn't put anything to clipboard.

Re: transfer variables from autoit

Posted: 15 Dec 2017, 06:33
by just me
You need to use square brackets to declare an array:

Code: Select all

name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]

Re: transfer variables from autoit  Topic is solved

Posted: 15 Dec 2017, 06:56
by Guest
just me wrote:You need to use square brackets to declare an array:

Code: Select all

name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]
Thank you. How can I make it send starting from 3rd variable for example?

Re: transfer variables from autoit

Posted: 15 Dec 2017, 07:57
by BoBo
If (index > 2) ?

Re: transfer variables from autoit

Posted: 15 Dec 2017, 08:54
by Guest
BoBo wrote:If (index > 2) ?
Sorry, I don't know what it means.

Re: transfer variables from autoit

Posted: 15 Dec 2017, 09:52
by BoBo

Code: Select all

name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]
for i, v in name {
   If (i > 2) {
    Clipboard := v
    Send, +{INSERT}
    }
}
Not tested. Unfortunately that's quite unflexible. Embeding this within a function + using a variable would be a better approach.

Re: transfer variables from autoit

Posted: 15 Dec 2017, 10:34
by Guest
BoBo wrote:

Code: Select all

name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]
for i, v in name {
   If (i > 2) {
    Clipboard := v
    Send, +{INSERT}
    }
}
Not tested. Unfortunately that's quite unflexible. Embeding this within a function + using a variable would be a better approach.
Thank you. Is there a chance to have my variables numbered like in my autoit code? I have hundreds of them. I want to enter a number so sending starts with a variable that I choose and ends with the last one.

Re: transfer variables from autoit

Posted: 15 Dec 2017, 11:08
by BoBo

Code: Select all

$name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"] ; the hardcoded array. It shouldn't be a problem to parse AU3 arrays adding its content to a variable on the fly instead.
Random, i, 1, $name.MaxIndex() ; creating a random number of iterations for testing
Loop % i ; looping that random number of iterations
   MsgBox % "We'll check the content of " . i . " vars.`nThis is the " A_Index . ". one: " . $name[A_Index] ; getting all array elements based on the number of iterations
SoundBeep
MsgBox % This is the content of the 5th array element: $name[5] ; getting a single array element by its number/position within the array
Not tested.

There are definitely more sophisticated methods available. But the following one (that lies within my abilities) should do the trick ...

Code: Select all

Global $name
$name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]

func(8) ; the no of the element from where you want to go until the end of the array. Here the 8th one: "cbvn", ...

func(Element) {
i := $name.MaxIndex()-(Element-1)
Loop % i {
   MsgBox % $name[Element]
   Element++
   }
}
Hope that helps.

Re: transfer variables from autoit

Posted: 15 Dec 2017, 13:52
by KuroiLight
just me wrote:You need to use square brackets to declare an array:

Code: Select all

name := ["adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre"]
my mistake, I ment name := Array("adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre")
Guest wrote:Thank you. Is there a chance to have my variables numbered like in my autoit code? I have hundreds of them. I want to enter a number so sending starts with a variable that I choose and ends with the last one.
AHK arrays are indexed, starting from 1.

Code: Select all

SendFromIndex(n) {
    name := Array("adf", "zcxv", "agf", "zxcv", "adsf", "qtq", "dfsg", "cbvn", "fgjh", "ytre")
    for i, v in name {
        if(i >= n) {
            Clipboard := v
            Send, +{INSERT}
        }
    }
}

Re: transfer variables from autoit

Posted: 15 Dec 2017, 14:41
by Guest
KuroiLight wrote:AHK arrays are indexed, starting from 1.
I mean I have to count variables before inputting my number. Is there a way to assign numbers to them like in my autoit code?

Re: transfer variables from autoit

Posted: 15 Dec 2017, 15:39
by BoBo
Using KuroiLight's code (from above) + researching if an option exists to use the AU3 code with only minor additions/changes we/I ended up with this ... and yes, it's working! :thumbup:

Code: Select all

$name := {}				; let's create/declare an array
$name[0] := "adf"		; let's define elements of the array with its assigned values
$name[1] := "zcxv"
$name[2] := "agf"
$name[3] := "zxcv"
$name[4] := "adsf"
$name[5] := "qtq"
$name[6] := "dfsg"
$name[7] := "cbvn"
$name[8] := "fgjh"
$name[9] := "ytre"

; MsgBox % $name[5]		; test if we've assigned a value to the 6th element of the array. YES WE CAN!

SendFromIndex("$name", 7)		; let's call the function to parse the array beginning with its 8th element (keep in mind that AU3's index count starts with "0"!)

SendFromIndex(Array, n) {
    for i, v in %Array% {
        if(i >= n) {
            Clipboard := v
            MsgBox % ClipBoard	; comment this line after testing            
;			Send, +{INSERT}		; uncomment this line after testing
        }
    }
}
Hope that helps. :ugeek:
https://autohotkey.com/docs/Objects.htm ... ple_Arrays

Re: transfer variables from autoit

Posted: 16 Dec 2017, 04:17
by Guest
BoBo wrote:
Thank you! What's the difference between this and your previous version?

Code: Select all

Global $name:={}
$name[1] := "zcxv"  ;
$name[2] := "agf"
$name[3] := "zxcv"
$name[4] := "adsf"
$name[5] := "qtq"
$name[6] := "dfsg"
$name[7] := "cbvn"
$name[8] := "fgjh"
$name[9] := "ytre"

SendFromIndex(2) 
SendFromIndex(n) {
for i, v in $name {
if(i >= n) {
Clipboard := v
Send +{INSERT} 
}
}
}
Both seem to work fine.

Re: transfer variables from autoit

Posted: 16 Dec 2017, 08:08
by BoBo
Gast wrote:
BoBo wrote:
Thank you! What's the difference between this and your previous version?

Code: Select all

Global $name:={}
$name[1] := "zcxv"  ;
$name[2] := "agf"
$name[3] := "zxcv"
$name[4] := "adsf"
$name[5] := "qtq"
$name[6] := "dfsg"
$name[7] := "cbvn"
$name[8] := "fgjh"
$name[9] := "ytre"

SendFromIndex(2) 
SendFromIndex(n) {
for i, v in $name {
if(i >= n) {
Clipboard := v
Send +{INSERT} 
}
}
}
Both seem to work fine.
As you can see, the array has been set to act globaly, while at the other script the array is handed over within the function call.

Re: transfer variables from autoit

Posted: 17 Dec 2017, 11:22
by KuroiLight
and that his will start index at 0.