在VB 6中如何使用变量而不是固定名称来引用控制标签,例如LUH01(如下所示),它不允许循环。
Frm_Dispo_Prof_Grille.LUH01.BackColor = &HFF00&
答案 0 :(得分:1)
您可以通过Controls Collection:
来引用它Frm_Dispo_Prof_Grille.Controls("LUH01").BackColor = &HFF00&
但是,要小心。如果您需要引用不属于标准/内置属性的属性/方法,则必须将控件转换为类型:
Dim lbl as Label
Set lbl = Frm_Dispo_Prof_Grille.Controls("LUH01")
lbl.BackColor = &HFF00
答案 1 :(得分:0)
我想你想创建一个控制数组
您可以通过创建1控件,并将其Index属性设置为0(而不是空)
来实现然后,您可以加载新控件并在循环中使用它们
例如,加载一些命令按钮并将它们放在循环中:
'1 form with :
' 1 command button: name=Command1 index=0
'Number of command buttons to use in the loop
Private Const NRBUTTONS As Integer = 5
Option Explicit
Private Sub Form_Load()
Dim intIndex As Integer
'change the caption of the default button
Command1(0).Caption = "Button 0"
For intIndex = 1 To NRBUTTONS - 1
'load an extra command button
Load Command1(intIndex)
'change the caption of the newly loaded button
Command1(intIndex).Caption = "Button " & CStr(intIndex)
'newly load command buttons are invisible by deafult
'make the new command button visible
Command1(intIndex).Visible = True
Next intIndex
End Sub
Private Sub Form_Resize()
'arrange all loaded command buttons via a loop
Dim intIndex As Integer
Dim sngWidth As Single
Dim sngHeight As Single
sngWidth = ScaleWidth
sngHeight = ScaleHeight / NRBUTTONS
For intIndex = 0 To NRBUTTONS - 1
Command1(intIndex).Move 0, intIndex * sngHeight, sngWidth, sngHeight
Next intIndex
End Sub