StringSplit and use the array in a function.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

StringSplit and use the array in a function.

16 Apr 2015, 02:43

Follow is the code:

Code: Select all

global aString
aString=q|w|e|r|t

StringSplit,aString,aString,|
aFunc()
return

aFunc()
{
	MsgBox,% aString
	MsgBox,%aString1%
}
I cant use "aString0" in my "aFunc".
Why !? Because I didnt "split it as a global array"?
Such as...(I can solve this problem by just adding follow code.But that's incredibly stupid.)

Code: Select all

global aString1
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: StringSplit and use the array in a function.

16 Apr 2015, 03:22

Pseudo arrays are not connected, they are just some variables that happen to have similar names. Making one variable global has no effect on another variable.
Try using real arrays.

Code: Select all

global aString
aString=q|w|e|r|t
aString := StrSplit("q|w|e|r|t", "|")	

aFunc()
return

aFunc()
{
    MsgBox,% aString	; <- blank because it now holds a reference to the array
    MsgBox, % aString.1
}
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: StringSplit and use the array in a function.

16 Apr 2015, 03:35

aString := "q|w|e|r|t"
StringSplit, aString, aString, |
aFunc()
Return
aFunc()
{
Global
Loop % aString0
MsgBox % aString%A_Index%
}
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: StringSplit and use the array in a function.

16 Apr 2015, 03:37

aFunc("q|w|e|r|t")
Return
aFunc(x)
{
StringSplit, x, x, |
Loop % x0
MsgBox % x%A_Index%
}
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: StringSplit and use the array in a function.

16 Apr 2015, 03:39

Msgbox % aFunc("q|w|e|r|t")
Return
aFunc(x)
{
StringSplit, x, x, |
Loop % x0
y .= x%A_Index% "`n"
Return y
}
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: StringSplit and use the array in a function.

16 Apr 2015, 03:42

^^The above 3 posts are good examples, but maybe some code tags and an explanation would be beneficial.
Guest

Re: StringSplit and use the array in a function.

16 Apr 2015, 10:03

kon wrote:Pseudo arrays are not connected, they are just some variables that happen to have similar names. Making one variable global has no effect on another variable.
Try using real arrays.

Code: Select all

global aString
aString=q|w|e|r|t
aString := StrSplit("q|w|e|r|t", "|")	

aFunc()
return

aFunc()
{
    MsgBox,% aString	; <- blank because it now holds a reference to the array
    MsgBox, % aString.1
}
Oh my god...Thank you all !

You guys are awesome :dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 338 guests