transfer variables from autoit Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guest

transfer variables from autoit

14 Dec 2017, 12:38

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.
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: transfer variables from autoit

14 Dec 2017, 13:57

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}
}
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Guest

Re: transfer variables from autoit

15 Dec 2017, 04:13

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.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: transfer variables from autoit

15 Dec 2017, 06:33

You need to use square brackets to declare an array:

Code: Select all

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

Re: transfer variables from autoit  Topic is solved

15 Dec 2017, 06:56

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?
Guest

Re: transfer variables from autoit

15 Dec 2017, 08:54

BoBo wrote:If (index > 2) ?
Sorry, I don't know what it means.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: transfer variables from autoit

15 Dec 2017, 09:52

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.
Guest

Re: transfer variables from autoit

15 Dec 2017, 10:34

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.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: transfer variables from autoit

15 Dec 2017, 11:08

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.
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: transfer variables from autoit

15 Dec 2017, 13:52

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}
        }
    }
}
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Guest

Re: transfer variables from autoit

15 Dec 2017, 14:41

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?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: transfer variables from autoit

15 Dec 2017, 15:39

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
Guest

Re: transfer variables from autoit

16 Dec 2017, 04:17

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.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: transfer variables from autoit

16 Dec 2017, 08:08

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.
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: transfer variables from autoit

17 Dec 2017, 11:22

and that his will start index at 0.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, Rohwedder, RussF and 140 guests