Using Variable Names for Controls/Objects?

  1. 2 weeks ago

    Aaron S

    Nov 29 Pre-Release Testers, Xojo Pro San Diego, CA

    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!

    @Aaron S Is there a way to do this in Xoj

    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

  2. Dave S

    Nov 29 Answer San Diego, California USA

    @Aaron S Is there a way to do this in Xoj

    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

  3. Aaron S

    Nov 29 Pre-Release Testers, Xojo Pro San Diego, CA

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

  4. Norman P

    Nov 29 Pre-Release Testers, Xojo Pro under THE bus

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

  5. Aaron S

    Nov 29 Pre-Release Testers, Xojo Pro San Diego, CA

    @Norman P 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.

  6. Dave S

    Nov 29 San Diego, California USA

    Dunno about "famous"... but yeah he is a "personality" alright

  7. Aaron S

    Nov 29 Pre-Release Testers, Xojo Pro San Diego, CA

    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.

  8. Derek D

    Nov 30 Pre-Release Testers Newnan, GA. USA

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

    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.

  9. Norman P

    Nov 30 Pre-Release Testers, Xojo Pro under THE bus

    @Aaron S People say that Norman is "quirky"

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

  10. Norman P

    Nov 30 Pre-Release Testers, Xojo Pro under THE bus

    @Aaron S @Norman P 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.

    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 :)
    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

  11. Karen A

    Nov 30 Pre-Release Testers

    @Dave S Dunno about "famous"... but yeah he is a "personality" alright

    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! ;)

    Karen

or Sign Up to reply!