Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting commandgroup properties in a loop 3

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am looking for the correct syntax for setting the caption properties of a set of command buttons within a commandgroup.

I have been messing about with this as example code but I just can't get it right.
Code:
varb = 'editbuttons.command'+str(xx)+'caption'
thisform.varb = 'boo'

Is there an example on here somewhere?

I have spent a good while searching through the FAQ's and previous posts but cannot find what I am looking for.

Keith
 
To do this you could use a macro substitution thus:

Code:
varb = 'thisform.editbuttons.command'+str(xx)+'caption'
&varb = 'boo'

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Sorry

Code:
varb = 'thisform.editbuttons.command'+str(xx)+'.caption'
&varb = 'boo'

Missed the period before caption

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Ahh!, thanks Griff
I have had the eureka moment, I had forgotten the reference to the var rather than the var itself.
Easy when you know the answer

Keith
 
Just to point out the obvious, if you're going to set them all the same then call Commandgroup.Setall(). No need for a loop at all.

[rednose]
 
str(xx) also won't work, as it will include spaces, take Transform(xx) or the Setall() solution. No need for macroi substitution, here.

Bye, Olaf.
 
Fair point..
Code:
varb = 'thisform.editbuttons.command'+alltrim(str(xx,10,0))+'.caption'
&varb = 'boo'

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Transform() in place of Alltrim(Str()) is a really worthy global change to make.

Transform() is not finnicky, never throws an error, accepts any data type you throw at it. Str() has been fiddly over the years, only accepts numeric input, may produce extraneous spaces, can introduce strange rounding, and a variety of other things.

Changing to Transform() is one of the best things you can do for the reliability of your code.
 
Hey, thanks guys
It is the simple things which cause me the biggest problems.

Dan, I was keeping the example simple to get my head round the syntax.
The app I am using this with sets the caption of several buttons to the contents of a table.

Of course I want the most reliable solution, that is why I asked you guys rather than labour long and hard down a tricky road. The main syntax I was trying was alltrim(str(xx)) which will always be a numeric value, is the still liable to cause a problem.

I will look into setall and transoform when the weekend wine has qorn off, thanks to you all.

Keith
 
Seems to me the most reliable solution is to use a loop that takes advantage of the native properties:

Code:
FOR EACH oCmd IN This.Buttons FOXOBJECT
  oCmd.Caption = 'boo'
ENDFOR

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top