Page 1 of 1
Variables in arrays?
Posted: Thu Mar 19, 2009 5:02 pm
by gyroscope
Hi, I haven't read much about arrays in Rev yet, including the so-called "3D" arrays in 3.0, but a thought came to me:
Can one place variables in arrays could anyone tell me please

Posted: Thu Mar 19, 2009 5:20 pm
by SparkOut
Not sure what you mean... you want to say something like
put 1 into tVar
put <a reference to tVar> into tArr[1]
So that if someone evaluates tArr[1] the returned value is 1?
And if subsequently tVar changes to 2, then when someone evaluates tArr[1] the returned value also is 2?
You can do the "pass by reference" thing in a function, but I am not aware of a similar approach with an array.
You could, of course put the variable name into the array and then "do" a command which will be evaluated before action, thus:
Code: Select all
local t1,t2,tArr
put field "Field1" into tVar1
put field "Field2" into tVar2
put "tVar1" into tArr[1]
put "tVar2" into tArr[2]
do "put" && tArr[1] && "into field" && quote & "Field3" & quote
--this evaluates to
--put tVar1 into field "Field3" - so the result is the same
--but it's not reading a reference to the variable tVar1 from the array
--it's evaluating the name held in the array as part of the "do" string
--which is then actioned
do "put" && tArr[2] && "into field" && quote & "Field4" & quote
Is that anything like what you're trying to determine?
Assuming it's what you're describing, any of the forum heavyweights know a better technique?
Posted: Thu Mar 19, 2009 7:28 pm
by gyroscope
Hi SparkOut
you want to say something like
put 1 into tVar
put <a reference to tVar> into tArr[1]
So that if someone evaluates tArr[1] the returned value is 1?
Yes, exactly what I meant, thank you.
And if subsequently tVar changes to 2, then when someone evaluates tArr[1] the returned value also is 2?
I hadn't thought that far, to be honest, i.e the variable changing and being "automatically" updated within the array if the variable changes; that interesting to know and useful for the future, I'm sure. As "pass by reference" is another of my sticking points I'm hoping I'll "get it" nearer the time.
any of the forum heavyweights know a better technique?
Well SparkOut, if you consider yourself a middleweight I must be between a lightweight and a bantamweight!
Thanks again for your help.

Posted: Thu Mar 19, 2009 10:02 pm
by Philhold
Posted: Thu Mar 19, 2009 10:18 pm
by gyroscope
That's a useful link Phil, thanks.

Posted: Thu Mar 19, 2009 10:39 pm
by SparkOut
gyroscope wrote:Well SparkOut, if you consider yourself a middleweight I must be between a lightweight and a bantamweight!
Well, I, um, guess I'm sort of shocked. I never thought of myself as anything but "a contributor" - and never compared myself to Mark, Jan, Malte, Klaus, etc, etc. on the forum, and as for some of the "old-timers" on the use- and improve- lists, well... Anyway, I'm heartened and thankful.
gyroscope wrote:That's a useful link Phil, thanks.
Useful, definitely - but as of Rev 3.0 don't forget that there are multi-dimensional arrays available and you will also find this pertinent:
http://www.runrev.com/newsletter/septem ... W57S445981 and find some of that older information superceded.
Posted: Thu Mar 26, 2009 10:08 pm
by SparkOut
See, it takes a proper forum heavyweight to help:
http://forums.runrev.com/phpBB2/viewtop ... 2813#12813
Try
Code: Select all
on mouseUp
local tArr, tVar
put "tVar" into tArr[1]
repeat with tVar = 1 to 100
put value(tArr[1]) & cr after field "fldResult"
end repeat
end mouseUp
Thanks Jan!
Posted: Thu Mar 26, 2009 11:02 pm
by gyroscope
Anyway, I'm heartened
I'm glad of that, SparkOut! Please don't underestimate your value. I was truly impressed by your coding in GyroButtonSortRevisited.rev.
It's great that whatever level we're at we all chip in (and there's not much punching goes on in the Forum

)
Thank you for that info on arrays. I'm bound to revisit this thread when I delve boldly into multi-dimensional arrays at a later date. (I'm still wrangling with custom properties which I'm sort of getting the hang of, although I expect I'll be putting another question about it soon!)
