0284 -- PB控件的“宏替换”
http://www.51pb.com/viewthread.php?tid=1147&extra=page%3D1
问:
我想编写一个程序,代码如下:
P_1.PictureName = 'help.gif'
P_2.PictureName = 'help.gif'
P_3.PictureName = 'help.gif'
P_4.PictureName = 'help.gif'
P_5.PictureName = 'help.gif'
请问有没有一种简单的办法,能让我用循环语句来实现?
如:
for i = 1 to 5
P_***.PictureName = 'help.gif'
next
答:
假设这段代码写在WINDOW的OPEN事件,THIS就是当前WINDOW:
int i
picture lp
for i=1 to upperbound(this.Control)
if typeof(this.Control)=picture! then
lp=parent.Control
// 可以通过 lp.classname() 进一步确定是不是要修改的图像控件
lp.picturename='help.gif'
end if
next
你也可以定义一个 picture 变量数组来进行操作,通过OpenUserObject()使它们出现在window中。
答:
int i
picture p_temp
for i = 1 to Upperbound(w_test.control)
if left(w_test.control.classname,2) = 'p_' then
p_temp = w_test.control
p_temp.picturename = '.......'
end if
next
问:我现在有60个相同的控件,控件名为cbx_1~cbx_61现在我要对这60个控件做同样的处理,是否有办法用循环来处理呢?
就象
for i=1 to 61
messagebox('',cbx_i.text)
next
相似的处理,我上面用法当然是错误的,只是不知道有没有什么办法来解决呢?
Integer li_control
String ls_name
//This 是窗口,换成window的名字
FOR li_control = 1 TO UpperBound(This.Control[])
ls_name = This.Control[li_control].classname()
IF Left(ls_name,4) = 'cbx_' AND &
Integer(Right(ls_name(),Len(ls_name) - 4)) >= 1 AND &
Integer(Right(ls_name(),Len(ls_name) - 4)) <= 61 THEN
//此处处理
CheckBox cbx_which
cbx_which = This.Control[li_control]
messageBox('',cbx_which.Text)
END IF
NEXT