Dim OP1 As Long
Dim OP2 As Long
'把Command1的控件的控件Index改为由0开始,否则开不了灯。
'用这种方式可以表达最多串联30个开关(0~29)
Private Sub Command1_Click(Index As Integer)
Dim I As Long
I = 2 ^ Index
OP1 = OP1 Xor I
Command1(Index).Caption = IIf(OP1 And I, "关", "开")
I = 2 ^ (Command1.Count) - 1
Image1.Picture = LoadPicture(IIf(OP1 = I, "on.gif", "off.gif"))
End Sub
Private Sub Command2_Click()
OP2 = Not OP2
Command2.Caption = IIf(OP2, "关", "开")
Image2.Picture = LoadPicture(IIf(OP2, "on.gif", "off.gif"))
End Sub