I have a procedure which creates a number of rectangle objects and text label objects and which should centre each text label object within its relevant rectangle object. So, each pair should look like this:
Sometimes that happens and sometimes the centering process doesn’t work and I get this:
Here’s the code - can anybody find a fault in it?
; MakeObjects 27 October 2021
save
local lvNamesArray, Centered, lvLocationX, lvLocationY, lvSizeHeight, lvSizeWidth, lvColor, lvProcedure
lvNamesArray = "Tickers,Services,Managed,Holdings,Accounts,Trades,Downloads"
lvColor = "FFD600"
lvProcedure = "call .Buttons"
lvLocationX = "40"
lvLocationY = "220"
lvSizeWidth = "150"
lvSizeHeight = "30"
looparray lvNamesArray,",",ButtonName,LoopCount
newformobject "rectangle", "name",ButtonName, "color",lvColor, "$LocationX",lvLocationX, "procedure",lvProcedure, "$LocationY",lvLocationY, "$SizeWidth",lvSizeWidth, "$SizeHeight",lvSizeHeight
newformobject "text label", "name",ButtonName+"Label", "$TextLabelContent",ButtonName, "$LocationX",lvLocationX, "$LocationY",lvLocationY
Centered = rectanglealign(objectinfo("rectangle",ButtonName),objectinfo("rectangle",ButtonName+"Label"),"center")
changeobject ButtonName+"Label","rectangle",Centered
if LoopCount < arraysize(lvNamesArray,",")
newformobject "line", "$StrokeWidth","2", "$LocationX",str(val(lvLocationX) + 151), "$LocationY",lvLocationY, "$SizeWidth","0", "$SizeHeight",lvSizeHeight
endif
lvLocationX = str(val(lvLocationX) + 151)
endloop