Download presentation
Presentation is loading. Please wait.
1
Chapter 61 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.
2
Chapter 62 Lab sheet 6.5: Login Form
3
Chapter 63 Lab sheet 6.5 : Login Form - Code Dim username, password As String Dim LoginSuccess As Boolean = False Do Until LoginSuccess = True username = InputBox("Username Please") password = InputBox("Password Please") If username = "Peter" And password = "1234" Then LoginSuccess = True End If Loop MsgBox("Login success")
4
Chapter 64 More About Flags When flagVar is a variable of Boolean type, the statements If flagVar = True Then and If flagVar = False Then can be replaced by If flagVar Then and If Not flagVar Then
5
Chapter 65 Example: Login Form - Code Dim username, password As String Dim LoginSuccess As Boolean = False Do Until LoginSuccess = True username = InputBox("Username Please") password = InputBox("Password Please") If username = "Peter" And password = "1234" Then LoginSuccess = True End If Loop MsgBox("Login success")
6
Chapter 66 Flags continued The statements Do While flagVar = True and Do While flagVar = False can be replaced by Do While flagVar and Do While Not flagVar
7
Chapter 67 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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.