vb6中关于if语句,其中的and条件能否由变量控制

比如当form1的text1的值为2的时候,if语句为:if check2.value=1 and check1.value=1 then...end if当text1的值为3的时候if check3.value=1 and check2.value=1 and check1.value=1 then...end if请问这种动态的if语句能否由代码实现?我是新手,请多多指教,谢谢或者这么说:当form1的text1的值为2的时候,if语句为:if check1(2).value=1 and check1(1).value=1 then...end if当text1的值为3的时候if check1(3).value=1 and check1(2).value=1 and check1(1).value=1 then...end if
2026年09月28日 08:21
有4个网友回答
网友(1):

可以用select case 来实现
i= text1.text
select case i
case 2
if check1(2).value=1 and check1(1).value=1 then

case 3
if check1(3).value=1 and check1(2).value=1 and check1(1).value=1 then

End Select

网友(2):

你好,if语句中是可以用And连接的。但是我没有明白你的意思,你是在用复选框做什么呢?其实你可以用一个frame把那些单选复选都放在一起。

网友(3):

Select Case Val(Text1)
Case 1
'你的代码
Case 2
'你的代码
Case 10
'你的代码
End Select

网友(4):

Private Sub Command1_Click()
Dim f As Boolean
If Text1 = 2 Then
For i = 1 To 2
f = Me("check" & i).Value = 1
If Not f Then Exit For
Next

ElseIf Text1 = 3 Then
For i = 1 To 3
f = Me("check" & i).Value = 1
If Not f Then Exit For
Next

End If

If f Then MsgBox f

End Sub

VB6专家百度Hi群1358368