VB6为什么这不会改变? [Checkbox&文本框]

时间:2013-06-21 15:48:41

标签: text checkbox vb6 textbox

如果未勾选复选框,为什么文本框中的文本不会更改?如果未选中,则文本框的文本应为“-g no”,但单击Command1时不会更改。有解决方案吗可能是一些非常简单的事情,但我只是没有成功。 :\

我的代码:

Private Sub Command1_Click()
    If Check1.Enabled = True Then
        If TextPass.Text = "" Then
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -g yes " & "-t " & Combo1.ListIndex
        Else
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -p " & TextPass.Text & " -g yes " & "-t " & Combo1.ListIndex
        End If
    Else
        If TextPass.Text = "" Then
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -g no " & "-t " & Combo1.ListIndex
        Else
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -p " & TextPass.Text & " -g no " & "-t " & Combo1.ListIndex
        End If
    End If
End Sub

感谢帮助!或者只是修复我的代码。

2 个答案:

答案 0 :(得分:2)

因为您可以选中或取消选中Check1,所以很明显它已启用,因此您的情况

If Check1.Enabled = True Then

永远是真的。您实际想要做的是查看Check1是否已检查,条件为

If Check1.Value = 1 Then

答案 1 :(得分:0)

您所要做的就是改变

  

check1.enabled = true

..进入:

  

check1.value = vbchecked

结果如此,(请不要忘记评价我的答案!Thansk!)

Private Sub Command1_Click()
    If Check1.value = vbChecked Then
        If TextPass.Text = "" Then
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -g yes " & "-t " & Combo1.ListIndex
        Else
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -p " & TextPass.Text & " -g yes " & "-t " & Combo1.ListIndex
        End If
    Else
        If TextPass.Text = "" Then
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -g no " & "-t " & Combo1.ListIndex
        Else
            Text1.Text = "-o " & TextPool.Text & ":" & TextPort.Text & " -u " & TextUser.Text & " -p " & TextPass.Text & " -g no " & "-t " & Combo1.ListIndex
        End If
    End If
End Sub