strange behaviour of a Variable inside a loop
Posted: Wed Oct 22, 2014 4:35 pm
This command creates a bunch of Fields as buttons inside a group (for scrolling) depending on a variable number of Records in an SQLite Table passed as "SelectorList".
This variable bLeft ( at the *) initially may get 43
at ** I use this to set the Left of my Field.
Nothing else is done to the variable and when I step through the loop, bLeft never changes.
BUT:
the first Field created gets a Left of 39, all the others get the expected 43.
Where am I wrong?
command buildButtonsList SelectorList
global D, F, L, S
lock screen
put empty into S["msg"]
put the top of group "Buttons" +8 into bTop
* put the left of group "Buttons" +8 into bLeft
put (L["ButtonWidth"] - the scrollbarWidth of me) into bWidth
repeat for each element tItem in SelectorList
put "Sel" & tItem["Key"] into selectFieldName
create field selectFieldName in group "Buttons"
# set the behavior of it to the long ID of button "SelectMaster"
set the script of field selectFieldName to the script of button "SelectMaster"
set the cID of field selectFieldName to tItem["Key"]
set the backColor of field selectFieldName to L["Col_FieldBG"]
set the opaque of field selectFieldName to true
set the textSize of field selectFieldName to L["FS_Large"]
set the margins of field selectFieldName to 12
set the unicodetext of field selectFieldName to uniencode (tItem["Info"],"UTF8")
set the locktext of field selectFieldName to true
set the traversalOn of field selectFieldName to false
set the width of field selectFieldName to bWidth
set the height of field selectFieldName to the formattedheight of field selectFieldName
set the top of field selectFieldName to bTop
** set the left of field selectFieldName to bLeft
put the bottom of field selectFieldName +8 into bTop
end repeat
For Information:
this is a sequence of selections with each step producing a different set of buttons, depending on all previous selections, so I mostly have to ( clear and ) rebuild the group.
In the rare case that I want to see the same selection a second time (i. e. just removing all the Fields and building the same list again) all the fields get the correct left of 43.
Beats me!
This variable bLeft ( at the *) initially may get 43
at ** I use this to set the Left of my Field.
Nothing else is done to the variable and when I step through the loop, bLeft never changes.
BUT:
the first Field created gets a Left of 39, all the others get the expected 43.
Where am I wrong?
command buildButtonsList SelectorList
global D, F, L, S
lock screen
put empty into S["msg"]
put the top of group "Buttons" +8 into bTop
* put the left of group "Buttons" +8 into bLeft
put (L["ButtonWidth"] - the scrollbarWidth of me) into bWidth
repeat for each element tItem in SelectorList
put "Sel" & tItem["Key"] into selectFieldName
create field selectFieldName in group "Buttons"
# set the behavior of it to the long ID of button "SelectMaster"
set the script of field selectFieldName to the script of button "SelectMaster"
set the cID of field selectFieldName to tItem["Key"]
set the backColor of field selectFieldName to L["Col_FieldBG"]
set the opaque of field selectFieldName to true
set the textSize of field selectFieldName to L["FS_Large"]
set the margins of field selectFieldName to 12
set the unicodetext of field selectFieldName to uniencode (tItem["Info"],"UTF8")
set the locktext of field selectFieldName to true
set the traversalOn of field selectFieldName to false
set the width of field selectFieldName to bWidth
set the height of field selectFieldName to the formattedheight of field selectFieldName
set the top of field selectFieldName to bTop
** set the left of field selectFieldName to bLeft
put the bottom of field selectFieldName +8 into bTop
end repeat
For Information:
this is a sequence of selections with each step producing a different set of buttons, depending on all previous selections, so I mostly have to ( clear and ) rebuild the group.
In the rare case that I want to see the same selection a second time (i. e. just removing all the Fields and building the same list again) all the fields get the correct left of 43.
Beats me!