Flags A flag is a variable that keeps
Flags • A flag is a variable that keeps track of whether a certain situation has occurred. • The data type most suited to flags is Boolean. Chapter 6 1
Lab sheet 6. 5: Login Form Chapter 6 2
Lab sheet 6. 5 : Login Form Code Dim username, password As String Dim Login. Success As Boolean = False Do Until Login. Success = True username = Input. Box("Username Please") password = Input. Box("Password Please") If username = "Peter" And password = "1234" Then Login. Success = True End If Loop Msg. Box("Login success") Chapter 6 3
More About Flags When flag. Var is a variable of Boolean type, the statements If flag. Var = True Then and If flag. Var = False Then can be replaced by If flag. Var Then and If Not flag. Var Then Chapter 6 4
Example: Login Form - Code Dim username, password As String Dim Login. Success As Boolean = False Do Until Login. Success = True username = Input. Box("Username Please") password = Input. Box("Password Please") If username = "Peter" And password = "1234" Then Login. Success = True End If Loop Msg. Box("Login success") Chapter 6 5
Flags continued The statements Do While flag. Var = True and Do While flag. Var = False can be replaced by Do While flag. Var and Do While Not flag. Var Chapter 6 6
Yours Challenge ! • Try to modify your program by limiting the number of try to 3. • If a user enter incorrect username or password more than 3 times, system prompt an error message and does not allow user to try again. • Hint: Use a counter variable to check the number of try and modify your Loop Condition. Chapter 6 7
- Slides: 7