using vars in a thisform. statment

Hello again,
I have a problem using a variable in a thisform. statment.
I tried it using the following code:
IF v_sichtbar < 10 then
DO WHILE v_sichtbar < 11
v_button = "button0"+ALLTRIM(STR(v_sichtbar))
v_label = "label"+ALLTRIM(STR(v_sichtbar))
thisform.v_button.visible = .F.
thisform.v_label.visible = .F.
v_sichtbar = v_sichtbar + 1
ENDDO
ENDIF

The thisform. statement does not replace the v_button var with its value.
I checked the value of the var wich is ok, var is also properly declared
Help would be very much appreciated
[638 byte] By [theblackknight] at [2008-3-6]
# 1

Hi, I can guess what you want to get in result. You want to loop from 0 to 9 and set Visible prop to commandbuton named Button01, buton02.... and so on. You should do it this way:

Local v_button , v_label, v_sichtbar
IF v_sichtbar < 10 then
DO WHILE v_sichtbar < 11
v_button = "THISFORM.button0"+ALLTRIM(STR(v_sichtbar))
v_label = "THISFORM.label"+ALLTRIM(STR(v_sichtbar))
with &v_button
.Visible=.f.
endwith
with &v_label
.Visible=.f.
endwith
v_sichtbar = v_sichtbar + 1
ENDDO
ENDIF

you should perform macro substitution for commandbutton objects.Try this command

a="var1"
b="var2"
store 2 to &a, &b
?var1*var2

kanguru at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 2
Since those are objects, you could EVAL the strings instead of using macro substitution.

IF v_sichtbar < 10 then
DO WHILE v_sichtbar < 11
o_button = EVAL("button" + LPAD(v_sichtbar, 2, '0'))
o_label = EVAL("label" + TRANSFORM(v_sichtbar))
thisform.o_Button.visible = .F.
thisform.o_Label.visible = .F.
v_sichtbar = v_sichtbar + 1
ENDDO
ENDIF

If you are wanting to do this for labels and buttons in a particular container, you can call that container's SETALL method:

local llEnabled
llEnabled = .F.
if some_condition_based_on_your_criteria
llEnabled = .T.
endif
THISFORM.SetAll('Enabled', llEnabled, 'button_class_name')
THISFORM.SetAll('Enabled', llEnabled, 'label_class_name')

The class name would be the actual name of your button class and label class, and not the baseclass name. So if your label class is called MyLabel, that is the class name you would use. Keep in mind that the SetAll method will apply to EVERY label and button class of that name that is directly on the form. If you have labels in some other container on the form, they will not be affected.

MarkMcCasland at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 3
Yes, Mark McCasland was right. EVAL instead of using macro substitution will run faster and shorter. I've got used to my way of using macro substitution to do the same action and never wondered whether it was the best way! Now, it changed.
kanguru at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 4
I do that as Mark suggested. I'd just add it'd be better if you use for...endfor and with..endwith. ie:

local ix
for m.ix = 1 to 10 && I'm not sure you want to that 1-9 or 1-10
with eval('thisform.button0'+alltrim(str(m.ix)))
.visible = .f.
endwith
with eval('thisform.label'+alltrim(str(m.ix)))
.visible = .f.
endwith
endfor

A fast alternative for setting property is to use store and name expression. ie:

local ix
for m.ix = 1 to 10 && I'm not sure you want to that 1-9 or 1-10
store .f. to ;
('thisform.button0'+alltrim(str(m.ix))+'.visible') , ;
('thisform.label'+alltrim(str(m.ix))+'.visible')
endfor

CetinBasoz at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...