B4A Beginner Tutorial - Pin Login
Submitted by boluvisako on Sunday, March 20, 2016 - 16:34.
Language
NOTE: THIS IS B4A formerly Basic4android tutorial. Note android studio or eclipse android tutorial
The first part of this tutorial , we will create buttons up to 10, also create panels and name them key1 to key4. we will also create our variables This will indicate number of keys entered with red dots
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private btnEight As Button
Private btnFive As Button
Private btnFour As Button
Private btnNine As Button
Private btnOne As Button
Private btnSeven As Button
Private btnSix As Button
Private btnThree As Button
Private btnTwo As Button
Private btnZero As Button
Private key1 As Panel
Private key2 As Panel
Private key3 As Panel
Private key4 As Panel
Private Label1 As Label
Dim Click_Count As Int = 0
Dim Master_Password As String = "4545"
Dim entered_Password As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("lyScreen")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnZero_Click
Log(btnZero.Text & " clicked")
click_count_Increment_and_fill(btnZero.Text)
End Sub
Sub btnOne_Click
Log(btnOne.Text & " clicked")
click_count_Increment_and_fill(btnOne.Text) 'filling the keys with red
End Sub
Sub btnTwo_Click
Log(btnTwo.Text & " clicked")
click_count_Increment_and_fill(btnTwo.Text) 'filling the keys with red
End Sub
Sub btnThree_Click
Log(btnThree.Text & " clicked")
click_count_Increment_and_fill(btnThree.Text) 'filling the keys with red
End Sub
Sub btnFour_Click
Log(btnFour.Text & " clicked")
click_count_Increment_and_fill(btnFour.Text) 'filling the keys with red
End Sub
Sub btnFive_Click
Log(btnFive.Text & " clicked")
click_count_Increment_and_fill(btnFive.Text) 'filling the keys with red
End Sub
Sub btnSix_Click
Log(btnSix.Text & " clicked")
click_count_Increment_and_fill(btnSix.Text) 'filling the keys with red
End Sub
Sub btnSeven_Click
Log(btnSeven.Text & " clicked")
click_count_Increment_and_fill(btnSeven.Text) 'filling the keys with red
End Sub
Sub btnEight_Click
Log(btnEight.Text & " clicked")
click_count_Increment_and_fill(btnEight.Text) 'filling the keys with red
End Sub
Sub btnNine_Click
Log(btnNine.Text & " clicked")
click_count_Increment_and_fill(btnNine.Text) 'filling the keys with red
End Sub
From there we will create a sub to handle the shading of the panels that is our key1 to key 4
Sub click_count_Increment_and_fill (input_Text As String)
Click_Count = Click_Count + 1
Select Click_Count
Case 1
key1.Color = Colors.Red
'getting the text value value from the button and passing it ot entered password
entered_Password = entered_Password & input_Text
Log("Current Entered pass: " & entered_Password)
Case 2
key2.Color = Colors.Red
'getting the text value value from the button and passing it ot entered password
entered_Password = entered_Password & input_Text
Log("Current Entered pass: " & entered_Password)
Case 3
key3.Color = Colors.Red
'getting the text value value from the button and passing it ot entered password
entered_Password = entered_Password & input_Text
Log("Current Entered pass: " & entered_Password)
Case 4
key4.Color = Colors.Red
'getting the text value value from the button and passing it ot entered password
entered_Password = entered_Password & input_Text
Log("Current Entered pass: " & entered_Password)
'===============================================================
'============CHECKING IF THE PASSWORD IS CORRECT===============
If entered_Password = Master_Password Then
Log("Login succesful")
Log("===============")
Log("***SUCCESS****")
Log("================")
'reset
resetting_all
'Letting the user in to a new page afer succesful login
StartActivity(actLoggedIn)
Else
Log("Wrong password")
Log("*************************")
'reset
resetting_all
End If
End Select
End Sub
Finally we will create a sub which will reset the shaded panels (keys) to white in case of wrong password entry
Sub resetting_all
'clearing the keys panel for new entry
key1.color = Colors.White
key2.Color = Colors.White
key3.Color = Colors.White
key4.Color = Colors.white
'Resetting entered password to empty
entered_Password = ""
'reset click count to ZERO...This will enable the SELECT CASE STATEMENT
'TO restart counting from 1 to fill the panels keys
Click_Count = 0
End Sub
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Add new comment
- Add new comment
- 959 views