If you don't want to count an empty username and password as a failed attempt, then (looking at
@Star-Dust's code) move the Num_of_Insert increment into the Else portion of the If statement. Also, should there not be an And in the first If part instead of Or?
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Num_of_Insert As Int = 0
End Sub
Sub Button1_Click
Dim Username As String = EditText1.Text
Dim Password As String = EditText2.Text
If Username = "ABCDE" And Password = "12345" Then
'Right
EditText3.Text="您是合法使用者!真厲害"
Else If Username = "" Or Password = "" Then
'Empty
EditText3.Text="您輸入的不正確,請重新輸入"
Else
'Wrong password
Num_of_Insert=Num_of_Insert+1
If Num_of_Insert >= 3 Then ExitApplication
End If
End Sub
But, if a blank username and/or password does count as an invalid try, then the above will never exit (nor
@Star-Dust's) as long as one of them is blank as the user tries. The code then needs to be:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Num_of_Insert As Int = 0
End Sub
Sub Button1_Click
Dim Username As String = EditText1.Text
Dim Password As String = EditText2.Text
If Username = "ABCDE" And Password = "12345" Then
'Right
EditText3.Text="您是合法使用者!真厲害"
Else If Username = "" Or Password = "" Then
'Empty
Num_of_Insert=Num_of_Insert+1
EditText3.Text="您輸入的不正確,請重新輸入"
Else
'Wrong password
Num_of_Insert=Num_of_Insert+1
End If
If Num_of_Insert >= 3 Then ExitApplication
End Sub