TZTJ 发表于 2008-6-18 22:48

[求助]代码问题

请问各位高手,以下代码有错吗?
thisform.Lebel1.caption=""
thisform.Lebel2.caption=""
thisform.Lebel3.caption=""
thisform.Lebel4.caption=""
thisform.Lebel5.caption=""
thisform.Lebel6.caption=""
..............
for i=1 to thisform.list2.listcount
  thisform.Lebeli.caption=thisform.list2.list(i-1)
  endfor
在运行过程中,总出现语法错误,不能识别成员"LEBEL1,....."
原因何在呢?

Tiger5392 发表于 2008-6-19 09:30

for i=1 to thisform.list2.listcount
  ci=alltrim(str(i))
  thisform.Lebel&ci..caption=thisform.list2.list(i-1)&&i-1可能为i
endfor

qjbzjp 发表于 2008-6-21 14:59

Label不能改Lebel

thisform.Label1.caption=""
thisform.Label2.caption=""
thisform.Label3.caption=""
thisform.Label4.caption=""
thisform.Label5.caption=""
thisform.Label6.caption=""
..............
for i=1 to thisform.list2.listcount
  thisform.Labeli.caption=thisform.list2.list(i-1)
  endfor

午丁 发表于 2008-6-21 19:32

是不是要在某一个“Lebel”显示“list2”某一行的数据

[quote][bo][un]TZTJ[/un] 在 2008-6-18 22:48 的发言:[/bo]

请问各位高手,以下代码有错吗?
thisform.Lebel1.caption=""
thisform.Lebel2.caption=""
thisform.Lebel3.caption=""
thisform.Lebel4.caption=""
thisform.Lebel5.caption=""
thisform.Lebel6.caption=""
.. ...
for i=1 to thisform.list2.listcount
  thisform.Labeli.caption=thisform.list2.list(i-1)
  endfor
[/quote]
是不是要在某一个“Lebel”显示“list2”某一行的数据?
如是,则:

c变量1="thisform.Label"+alltrim(str(i))+".caption"
c变量2="thisform.list2.list(i-1)"  && 或者 c变量2="thisform.list2.list("+alltrim(str(i-1))+")"
   &c变量1 = &c变量2

但请注意,i必须>1,则 i-1>0

TZTJ 发表于 2008-6-27 22:15

感谢各位高手,近来由于网络不通,不能及时回贴,实在抱歉。

TZTJ 发表于 2008-6-27 23:12

请教版主,为什么代码thisform.Label&ci..caption=thisform.list2.list(i)必须有“..”而单有“.”不成呢?

Tiger5392 发表于 2008-6-27 23:27

“&ci.”是固定搭配,宏替换函数,只是很多情况下我们只写成&ci是因为其后为空格。现在Label&ci的后面还有别的内容,就加上这个小数点作为与别的内容的分割符。若只加一个点,则当ci=1的时候,那结果就变成Label1Caption了;若加了二个点,则会出现Label1.Caption

TZTJ 发表于 2008-6-28 22:58

谢谢版主耐心的指点

页: [1]

编程论坛