Using Variable Names for Controls/Objects?

I’m starting to get some real traction in Xojo and have started developing solutions for actual clients…migrating them from FoxPro to Xojo will take some time!

In FoxPro I was able to use something called macro substitution to use a variable as an object name. For example, something like this:

i = 1
txtbox = “textbox” + Str(i)
&txtbox.Value = “testing123”

Is there a way to do this in Xojo. There are times when I need to use variables to build my object names…say in a loop…then assign values or other properties. Great for reducing lines of code and makes things more efficient.

Thank you!

no…
the best you could do is scan all the controls looking for the name…

something like this (example only … not for cut/paste use)

For i=Me.controlcount-1 DownTo 0
  ctrl=Me.control(i) // index is to ALL control here
  If ctrl.index<=0 Then Continue
  //
  // Only those control that have a "value" [ie. not switchs etc]
  //
  If ctrl IsA pi_CHECKBOX Then 
    Dim temp As pi_CHECKBOX=pi_CHECKBOX(ctrl)
    If temp.name="fred" then 
      result=Str(temp.Value)
      ok=True
      Exit For
    End If
  end if
next 

This finds all the pi_checkboxes (a custom subclass of mine, but works with any object class)
and returns information about the one named “FRED”
note the use of casting

@Dave S Thank you Dave! Xojo will only thrive if people like you continue to use the platform!

investigate control sets instead of naming things textbox1, textbox2 textbox3 etc

@Norman Palardy Thank you…appreciate the suggestion! I know you’re one of the more “famous” personalities on this forum, so thank you for being willing to help the “little guys” out there.

Dunno about “famous”… but yeah he is a “personality” alright

Dave - ok, for people like me who are newer to the community, he’s an illustrious figure. I’d say that you are too. People say that Norman is “quirky”, but I imagine that’s par for the course in terms of people who exist the realm of software development. Apparently Bob Keeney is another highly accomplished developer who has a penchant for stirring things up in the forums. I love seeing the vigorous discussions and debates that go on in these forums…I feel right at home! I am grateful for all of you.

Control Sets are huge for me; really a big time and code saver for multiple controls displaying similar information on a screen that might be slightly different from control to control, using a simple loop to display the info as Dave demonstrated.

Quirky ? Damn. Now I have to hunt those folks down :stuck_out_tongue:
Although there are days folks would just say “Norm ? He’s nuts” so I guess quirky is ok
:stuck_out_tongue:

Controls sets are a nice thing that really doesnt exist in that many other tools so you might overlook them
And they fit the need you’re seeking really well rather than having to try & bend Xojo to be FoxPro :slight_smile:
The help is more to try & steer you in the right direction within Xojo and save you from writing FoxPro in Xojo
The tools are different enough that you might find that really frustrating

Could not resist… particularly with the location in the header of his posts… would have been better a few months ago!:

Norman Palardy’s dead
No, no, he’s outside looking in
Norman Palardy’s dead
No, no, he’s outside looking in
He’ll code on the astral plane
Takes you on trips around the IDE way
Brings you back the same day
Norman Palardy, Norman Palardy

  • with apologies to the Moody Blues
    And yes I know i need to keep my day job! :wink:

Karen