Code: Select all
abc(max_index)
{
static Array := []
return
}
Code: Select all
abc(max_index)
{
static Array := []
return
}
Code: Select all
arr:=abc()
for k, v in arr
str.=v " "
MsgBox, % str
abc()
{
static max_index:=5 ; How many.
static fill:="0" ; What to fill with, note, single char.
static Array := fillArr(fill,max_index)
return array
}
fillArr(char,n){
; Returns an array of length n whose elements consist of on single symbol: char
; 0<=ord(char)<=255
static enc:=A_IsUnicode?"UTF-8":""
VarSetCapacity(str,n,ord(char))
return StrSplit(StrGet(&str,n,enc))
}
Code: Select all
fillArr(char,n){
; Returns an array of length n whose elements consist of on single symbol: char
; 0<=asc(char)<=255
VarSetCapacity(str,n,asc(char))
return StrSplit(StrGet(&str,n,""))
}
Code: Select all
fillArr(str,n,del:="`n"){
; Returns an array of length n whose elements consist of the string str.
VarSetCapacity(var,n*strlen(n+strlen(del))*(A_IsUnicode?2:1),1)
s:=StrSplit(StrReplace(StrGet(&var,n,""),chr(1),str . del,,n),del), s.pop()
return s
}
Helgef wrote:There are many ways to do this, this is one suggestion, test code and brief instructions in codeGood luck.Code: Select all
arr:=abc() for k, v in arr str.=v " " MsgBox, % str abc() { static max_index:=5 ; How many. static fill:="0" ; What to fill with, note, single char. static Array := fillArr(fill,max_index) return array } fillArr(char,n){ ; Returns an array of length n whose elements consist of on single symbol: char ; 0<=ord(char)<=255 static enc:=A_IsUnicode?"UTF-8":"" VarSetCapacity(str,n,ord(char)) return StrSplit(StrGet(&str,n,enc)) }
Code: Select all
static Var := 0
I'm not sure I get your point. There are no built-in functions for filling arrays, but you can still initialise static arrays, either by making a custom function that returns an array (my previous example) on the desired form, or hardcode it,paik1002 wrote: FYI, I was struggling a while with the manual and thought that I had perhaps missed a simpler solution, noting that static (or global) variables are very elegant and simple to initialize, but I guess it means that AHK does not support such a solution for arrays afterall.
Code: Select all
static Var := 0
Code: Select all
f(){
static arr:=[0,0,0,0,0] ; This is fine for shorter arrays, but gets tedious for longer arrays.
}
Users browsing this forum: No registered users and 326 guests