0

テキストボックスを使用してVBでログインスクリプトを作成しています。私の問題は、試行が残っていることをユーザーに通知する msgbox がループし続け、(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

ユーザーがテキストの入力を終了したことを示す [OK] ボタンが必要です。OKボタンのイベントでは、

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 に答える