0

我正在使用文本框在 VB 中制作登录脚本。我的问题是通知用户有关尝试的消息框也不断循环并用完所有(3)次尝试。不知道出了什么问题。

这是我的代码:

Dim cor_pw As String = "1234"
Dim cor_us As String = "abcd"
Dim tries1 As Integer = 3

tries1 -= 1

Do
    MsgBox("wrong combination, " & tries1 & " chances left to make it right.")

Loop Until textbox1.Text = cor_us And textbox2.Text = cor_pw Or tries1<= 0

If textbox1.Text = cor_us And textbox2.Text = cor_pw Then
    MsgBox("Congratulations! That's Correct!")
Else
    MsgBox("You've used all tries! " & tries1 & " chances left, good bye!")
    Me.Close()
End If
4

2 回答 2

1

您需要一个确定按钮来指示用户已完成输入文本。在确定按钮的情况下,您将

validate the text
If valid then you are good
otherwise increment the retry1 variable -- which must be declared at the Form (module) level!
now test retry1
if retry 1 is > 3 then display failure message and disable the OK button
otherwise display retry message 
exit the sub

此时用户可以重新输入值,然后再次点击 OK 按钮。没有循环。

于 2013-09-24T20:00:26.580 回答
0

您的循环事件位于错误的区域

Dim cor_pw As String = "1234"
Dim cor_us As String = "abcd"
Dim tries1 As Integer = 3

Do Until (textbox1.Text = cor_us And textbox2.Text = cor_pw) Or tries1<= 0
    If textbox1.Text = cor_us And textbox2.Text = cor_pw Then
        MsgBox("Congratulations! That's Correct!")
    Else
        MsgBox("You've used all tries! " & tries1 & " chances left, good bye!")
        Me.Close()
    End If
    MsgBox("wrong combination, " & tries1 & " chances left to make it right.")
    tries1 -= 1
Loop 
于 2013-09-24T19:44:20.643 回答