|
本帖最后由 markang 于 2015-8-27 13:15 编辑
各位老师,同学大家晚上好,
以下代码摘自一个小程序里,在编写一些代"active x"控件的程序中遇到条件语句,经常要表达if xxxx then xxx控件的某属性true, else xxx控件的某属性false.
程序可以简化吗非得把else后面的内容填全?像下面这样?
If InStr("03,04,08,09,02", Range("j2")) Then
CheckBox9.Enabled = False
CheckBox10.Enabled = False
CheckBox8.Value = True
CheckBox4.Value = True
CheckBox5.Enabled = False
CheckBox6.Enabled = False
Else
CheckBox9.Enabled = True
CheckBox10.Enabled = True
CheckBox8.Value = False
CheckBox4.Value = False
CheckBox5.Enabled = True
CheckBox6.Enabled = True
End If
End If
1)是否填全,看需求。
2)为什么有这么多控件。
3)写成下面这样,只是短点,是一个意思。
Sub test()
Dim x as boolean
x = InStr("03,04,08,09,02", Range("j2")) > 0
CheckBox4.Value = x
CheckBox5.Enabled = Not (x)
CheckBox6.Enabled = Not (x)
CheckBox8.Value = x
CheckBox9.Enabled = Not (x)
CheckBox10.Enabled = Not (x)
End Sub
|
|