楼主看看这个: Option ExplicitPrivate Function CheckOpt(ByRef strRetVal As String) As Boolean Dim strTemp As String Dim i&, c& strTemp = String(60, "-") c = 0 For i = opt1.LBound To opt1.UBound If (opt1(i).Enabled) Then c = c + 1 Else Mid$(strTemp, i * 3 + 1, 2) = opt1(i).Caption End If Next i = opt1.Count If (i > c) Then strTemp = Replace(strTemp, "-2", " 2") strTemp = Replace(Replace(strTemp, "-1", " 1"), "-0", " 0") strRetVal = Replace(strTemp, "-", "") End If CheckOpt = i = c End Function' 调用示例 Private Sub Command1_Click() Dim strMSG As String If (CheckOpt(strMSG)) Then MsgBox "全部可编辑!", 64 Else MsgBox "以下不可编辑:" & strMSG, 48 End If End Sub
If (i > c) Then ...... End if 那段可以这样改下:If (i = c) Then strRetVal = "" Else strTemp = Replace(strTemp, "-2", " 2") strTemp = Replace(Replace(strTemp, "-1", " 1"), "-0", " 0") strRetVal = Replace(strTemp, "-", "") End If
Dim mySettings(19) As Boolean, i As IntegermySettings(0) = True mySettings(1) = True mySettings(2) = True mySettings(3) = TrueFor i = 0 To 19 If mySettings(i) Xor opt1(i) Then MsgBox "选项 " & (i + 1) & " 没有设置为" & IIf(mySettings(i), "True", "False") End If Next i
楼主看看这个如何。Option ExplicitPrivate Function CheckObjPass(objCtrls As Object) As Boolean ' objCtrls ----- 被检查的控件数组 Dim i&, c&, u&, Mask& u = 0&: Mask = -1& For i = objCtrls.LBound To objCtrls.UBound c = objCtrls(i).Enabled u = ((Mask Xor c) And 1&) + u Mask = c Next CheckObjPass = u < 2& End Function '调用示例: Private Sub Command2_Click() If (CheckObjPass(opt1)) Then MsgBox "通过!", 64 Else MsgBox "错误!", 48 End If End Sub
Option ExplicitPrivate Function CheckOpt(ByRef strRetVal As String) As Boolean
Dim strTemp As String
Dim i&, c&
strTemp = String(60, "-")
c = 0
For i = opt1.LBound To opt1.UBound
If (opt1(i).Enabled) Then
c = c + 1
Else
Mid$(strTemp, i * 3 + 1, 2) = opt1(i).Caption
End If
Next
i = opt1.Count
If (i > c) Then
strTemp = Replace(strTemp, "-2", " 2")
strTemp = Replace(Replace(strTemp, "-1", " 1"), "-0", " 0")
strRetVal = Replace(strTemp, "-", "")
End If
CheckOpt = i = c
End Function' 调用示例
Private Sub Command1_Click()
Dim strMSG As String
If (CheckOpt(strMSG)) Then
MsgBox "全部可编辑!", 64
Else
MsgBox "以下不可编辑:" & strMSG, 48
End If
End Sub
strRetVal = ""
Else
strTemp = Replace(strTemp, "-2", " 2")
strTemp = Replace(Replace(strTemp, "-1", " 1"), "-0", " 0")
strRetVal = Replace(strTemp, "-", "")
End If
Dim mySettings(19) As Boolean, i As IntegermySettings(0) = True
mySettings(1) = True
mySettings(2) = True
mySettings(3) = TrueFor i = 0 To 19
If mySettings(i) Xor opt1(i) Then
MsgBox "选项 " & (i + 1) & " 没有设置为" & IIf(mySettings(i), "True", "False")
End If
Next i
' objCtrls ----- 被检查的控件数组
Dim i&, c&, u&, Mask&
u = 0&: Mask = -1&
For i = objCtrls.LBound To objCtrls.UBound
c = objCtrls(i).Enabled
u = ((Mask Xor c) And 1&) + u
Mask = c
Next
CheckObjPass = u < 2&
End Function
'调用示例:
Private Sub Command2_Click()
If (CheckObjPass(opt1)) Then
MsgBox "通过!", 64
Else
MsgBox "错误!", 48
End If
End Sub