Did I miss something?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Did I miss something?
I've used code like this many times...
repeat with i = 1 to 38
put "SectorCount" & i into cTarget
if field cTarget > 2 then
put "tot" & i into NewOnes
end if
end repeat
The critical word seems to be "field" as when
cTarget is a variable I can't get it to work.
Is there a key word for a variable eg "var"
or should I use a lot of hidden fields?
repeat with i = 1 to 38
put "SectorCount" & i into cTarget
if field cTarget > 2 then
put "tot" & i into NewOnes
end if
end repeat
The critical word seems to be "field" as when
cTarget is a variable I can't get it to work.
Is there a key word for a variable eg "var"
or should I use a lot of hidden fields?
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
If the variable is a global or local variable, you can use the 'do' command to manipulate its contents indirectly.
Another interesting bit for this sort of work, is the 'value' function:
Hope this helped,
Jan Schenkel.
Code: Select all
on mouseUp
global gVar1, gVar2, gVar3
repeat with i = 1 to 3
put "gVar" & i into tVarName
do "put" && tVarName && "into tArray[i]"
end repeat
end mouseUp
Code: Select all
on mouseUp
global gVar1, gVar2, gVar3
repeat with i = 1 to 3
put "gVar" & i into tVarName
put value(tVarName) into tArray[i]
end repeat
end mouseUp
Hope this helped,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Manipulating Variables
Thanks Jan - but it's strange that a var
can't be changed directly as for a field.
Surely this would be a desirable addition to RR?
Perhaps there's a way to use a "by reference"
function like $myVar as with some languages
but I can't find one.
can't be changed directly as for a field.
Surely this would be a desirable addition to RR?
Perhaps there's a way to use a "by reference"
function like $myVar as with some languages
but I can't find one.
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Unforunately there isn't a syntax for using a var to reference another var. You would have to do what Jan sugested if you want to use flat vars. In cases like yours I like to use arrays. So I would convert SectorCount to an array if possible. Might look like this:
Don't know if that is possible in your case or not.
Code: Select all
repeat with i = 1 to 38
if SectorCount[i] > 2 then
put "tot" & i into NewOnes[i]
end if
end repeat
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Fun with variables
Thanks Jan and Trevor.
Haven't quite solved all my "problems" yet.
I have an array Sectors[1] etc each containing
a string of numbers like 1,2,3,5.
I want to use the individual numbers but can't figure
out a way to access them.
I can get "Sectors[34]" into theTarget but so far
can only get "Sectors[34] out!
Tried
repeat with w = 1 to 4
put item w of theTarget into xvar
put "btn" & xvar into btnTarget
set backgroundColor of btnTarget to 200,200,220
end repeat
but get nothing in xvar so obviously isn't the way to do it.
Tried a do "put" as suggested above but can't find
a combination that works.
Perhaps it just can't be done.
I could put the individual numbers into array
elements as Sectors[34,1] etc. but would be
rather long-winded and not so "elegant".
Tell me it can't be done and I'll stop trying.
Haven't quite solved all my "problems" yet.
I have an array Sectors[1] etc each containing
a string of numbers like 1,2,3,5.
I want to use the individual numbers but can't figure
out a way to access them.
I can get "Sectors[34]" into theTarget but so far
can only get "Sectors[34] out!
Tried
repeat with w = 1 to 4
put item w of theTarget into xvar
put "btn" & xvar into btnTarget
set backgroundColor of btnTarget to 200,200,220
end repeat
but get nothing in xvar so obviously isn't the way to do it.
Tried a do "put" as suggested above but can't find
a combination that works.
Perhaps it just can't be done.
I could put the individual numbers into array
elements as Sectors[34,1] etc. but would be
rather long-winded and not so "elegant".
Tell me it can't be done and I'll stop trying.
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
For this technique to work you need to use the variable for the array key, not the array itself.I can get "Sectors[34]" into theTarget but so far
can only get "Sectors[34] out!
Code: Select all
repeat for each line theKey in the keys of Sectors
repeat with w = 1 to 4
put item w of Sectors[theKey] into xvar
put "btn" & xvar into btnTarget
set backgroundColor of btnTarget to 200,200,220
end repeat
end repeat
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder