How to insert code into button?

I need dynamicaly array of buttons. So I found how to create buttons… But I don’t know, how can I insert my code into the new button?
My code, which I want insert into every new button:

[code] dim jscript as string
dim a as integer
dim b as Integer
jscript = jscript+ “var settings = ganttChartView.settings; var items=ganttChartView.items;” + EndOfLine
if isExpand=0 then
for a = 0 to Urovenrozpadupocet
if Urovenrozpadu(a)=“2” then // Bold letters I need to change before I insert it into new button
jscript = jscript + “items[”+str(a)+"].isExpanded = ““False””;"+ EndOfLine
end if
end if

if isExpand=1 then
jscript = jscript + “items[0].isExpanded = ““True””;”+ EndOfLine
end if
if isExpand>1 then
for a = 0 to Urovenrozpadupocet
if Urovenrozpadu(a)=str(isExpand-1) then
jscript = jscript + “items[”+str(a)+"].isExpanded = ““True””;"+ EndOfLine
end if
end if


jscript = jscript+“ganttChartView.refresh();”+ EndOfLine

Should I insert it into a property? I want to use “Action” event on buttons.

You can create a method and call the method from Action. If your button is working as a control with multiple button instances, you can call the method like this MyMethod(me.index) and this will tell the button code which button you are referring to.

Assuming you are using Xojo and not an earlier version of RS, what you want to do is create a Control Set of your buttons.

  1. Drag a single button object from the Library to your window.
  2. Give that button a unique name
  3. Click the ‘gear’ icon above the properties pane and from the drop down menu select, create new control set
  4. Now duplicate that button as many times as you need. ( you can also do this in code if needed)
  5. Each subsequently created button will have an index number
    All of the buttons in the set have the same event handlers. You distinguish which button you are using by the index value which is passed to each event.