I have this:
Data_Source=
(
1one,1two,1three,1four
2one,2two,2three,2four
3one,3two,3three,3four
)
After that I need to do a send key for each val.
Is it better to do an array or an object?
I never done an array or an object.
Can you also show me how to do, so I can learn for a later use.
I hope I was clear enough.
Thanks in advance.
P.S.: I'm using the latest x64 unicode AHK.
[SOLVED] Array or object
[SOLVED] Array or object
Last edited by ozzii on 16 Jul 2015, 04:40, edited 1 time in total.
Re: Array or object
Assuming 1 is a key and one is a value, you'd need an object ( which is basically an array and vice versa )
Here's an example that reflects that:Because your main "Keys" contain a collection of data, you will need to have 2 loops to iterate through each value.
If you just want to recall the data in a given collection you can also go: msgbox % Data_Source.animals.1 " " Data_Source.furniture.3 " " Data_Source.numbers.2
Hope this makes sense.
Here's an example that reflects that:
Code: Select all
; original data
; Data_Source := { 1: [ "one", "two", "three", "four" ], 2: [ "one", "two", "three", "four" ], 3: ["one", "two", "three", "four" ] }
; some other possible keynames and values
Data_Source := { animals: [ "bird", "fish", "cat", "snake" ], furniture: [ "bed", "shelf", "chair", "lamp" ], numbers: [ "one", "two", "three", "four" ] }
For i, array in Data_Source
{
For j, val in array
{
msgbox % "Key: " i "`nSubKey: " j "`nValue: " val
}
}
If you just want to recall the data in a given collection you can also go: msgbox % Data_Source.animals.1 " " Data_Source.furniture.3 " " Data_Source.numbers.2
Hope this makes sense.
Re: Array or object
This make sense thanks (and thanks for the fast answer).
But to maintain my script with this model of attribution it's harder than in my example.
I will wait a little longer if someone have an solution with my example of attribution.
Too bad that this is not working, easier to change the values and to read
But to maintain my script with this model of attribution it's harder than in my example.
I will wait a little longer if someone have an solution with my example of attribution.
Too bad that this is not working, easier to change the values and to read
Code: Select all
Data_Source := {
animals: [ "bird", "fish", "cat", "snake" ],
furniture: [ "bed", "shelf", "chair", "lamp" ],
numbers: [ "one", "two", "three", "four" ]
}
Re: Array or object
yes AHk isn't that flexible, however there are workarounds,
for instance:
for instance:
Code: Select all
Data_Source := { ""
. animals: [ "bird", "fish", "cat", "snake" ]
, furniture: [ "bed", "shelf", "chair", "lamp" ]
, numbers: [ "one", "two", "three", "four" ]
. "" }
Re: Array or object
Yes, this is not bad at all and a good workaround.
Easier to maintain (at least for me).
But can something like this can be done for a use with my example?
After that I don't know what to do. Or maybe like you, add a second 'for loop'. What do you think?
Easier to maintain (at least for me).
But can something like this can be done for a use with my example?
Code: Select all
For Each, Line In StrSplit(Data_Source,"`n","`r")
Re: Array or object
Yes sureHowever, to recall the data in the using dot notation like Data_Source.line2.2 for instance,
you'd have to place each item into another array or you'd have to go msgbox % StrSplit( StrSplit( Data_Source, "`n", "`r" ).2, "`," ).1
which is ugly imo lol
Code: Select all
Data_Source=
(
1one,1two,1three,1four
2one,2two,2three,2four
3one,3two,3three,3four
)
For i, line in StrSplit( Data_Source, "`n", "`r" )
{
For each, item in StrSplit( line, "`," )
{
msgbox % "Line: " i "`nKey: " each "`nValue: " item
}
}
you'd have to place each item into another array or you'd have to go msgbox % StrSplit( StrSplit( Data_Source, "`n", "`r" ).2, "`," ).1
which is ugly imo lol
Re: Array or object
if your original data source can simply use integer keys, then you can simplify the definition by just using an array of arrays:
but might be better for you to just post a real example of what you're trying to accomplish
Code: Select all
Data_Source := [ ["1one", "1two", "1three"]
, ["2one", "2two", "2three"]
, ["3one", "3two", "3three"] ]
for i, line in Data_Source
for each, item in line
MsgBox, % "line=" i "`nvalue=" item
Re: Array or object
You are right, this is uglyTLM wrote: which is ugly imo lol
@guest3456
Like I said in my fist post i need to do a send key, so nothing fancy.
so for example
Data_Source=
(
1one,1two,1three,1four
2one,2two,2three,2four
3one,3two,3three,3four
)
loop the data and :
send 1one{tab}1two{tab}1three{tab}1four{tab}
and so on for every loop until the end
Re: Array or object
ehh, so what about :ozzii wrote: @guest3456
loop the data and :
send 1one{tab}1two{tab}1three{tab}1four{tab}
and so on for every loop until the end
Code: Select all
Data_Source := [ ["1one", "1two", "1three"]
, ["2one", "2two", "2three"]
, ["3one", "3two", "3three"] ]
for i, line in Data_Source
for each, item in line
Send, %item%{Tab}
Re: Array or object
This is just what I need to do.
So I will think what's the easier way for me.
Thanks all
So I will think what's the easier way for me.
Thanks all
Re: Array or object
Code: Select all
Data_Source=
(Join,
1one,1two,1three,1four
2one,2two,2three,2four
3one,3two,3three,3four
)
for i, val in StrSplit(Data_Source, ",")
Send, %val%{Tab}
Send, {Enter} ;Or
Loop, Parse, Data_SOurce, `,
Send, %A_LoopField%{Tab}
Re: Array or object
Thanks nli
This is what I use
This is what I use
Code: Select all
Loop, Parse, Data_Source, `,
Send, %val%{Tab}
Who is online
Users browsing this forum: Descolada and 130 guests