B4A Beginner Tutorial - Pin Login

Submitted by: 
Language: 
Visitors have accessed this post 4434 times.

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

  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4.  
  5. Private btnEight As Button
  6. Private btnFive As Button
  7. Private btnFour As Button
  8. Private btnNine As Button
  9. Private btnOne As Button
  10. Private btnSeven As Button
  11. Private btnSix As Button
  12. Private btnThree As Button
  13. Private btnTwo As Button
  14. Private btnZero As Button
  15. Private key1 As Panel
  16. Private key2 As Panel
  17. Private key3 As Panel
  18. Private key4 As Panel
  19. Private Label1 As Label
  20.  
  21. Dim Click_Count As Int = 0
  22. Dim Master_Password As String = "4545"
  23. Dim entered_Password As String
  24. End Sub
  25.  
  26. Sub Activity_Create(FirstTime As Boolean)
  27. 'Do not forget to load the layout file created with the visual designer. For example:
  28. Activity.LoadLayout("lyScreen")
  29.  
  30. End Sub
  31.  
  32. Sub Activity_Resume
  33.  
  34. End Sub
  35.  
  36. Sub Activity_Pause (UserClosed As Boolean)
  37.  
  38. End Sub
  39.  
  40. Sub btnZero_Click
  41. Log(btnZero.Text & " clicked")
  42.  
  43. click_count_Increment_and_fill(btnZero.Text)
  44. End Sub
  45.  
  46. Sub btnOne_Click
  47. Log(btnOne.Text & " clicked")
  48. click_count_Increment_and_fill(btnOne.Text) 'filling the keys with red
  49. End Sub
  50.  
  51. Sub btnTwo_Click
  52. Log(btnTwo.Text & " clicked")
  53. click_count_Increment_and_fill(btnTwo.Text) 'filling the keys with red
  54. End Sub
  55.  
  56. Sub btnThree_Click
  57. Log(btnThree.Text & " clicked")
  58. click_count_Increment_and_fill(btnThree.Text) 'filling the keys with red
  59. End Sub
  60.  
  61. Sub btnFour_Click
  62. Log(btnFour.Text & " clicked")
  63. click_count_Increment_and_fill(btnFour.Text) 'filling the keys with red
  64. End Sub
  65.  
  66. Sub btnFive_Click
  67. Log(btnFive.Text & " clicked")
  68. click_count_Increment_and_fill(btnFive.Text) 'filling the keys with red
  69. End Sub
  70.  
  71. Sub btnSix_Click
  72. Log(btnSix.Text & " clicked")
  73. click_count_Increment_and_fill(btnSix.Text) 'filling the keys with red
  74. End Sub
  75.  
  76. Sub btnSeven_Click
  77. Log(btnSeven.Text & " clicked")
  78. click_count_Increment_and_fill(btnSeven.Text) 'filling the keys with red
  79. End Sub
  80.  
  81. Sub btnEight_Click
  82. Log(btnEight.Text & " clicked")
  83. click_count_Increment_and_fill(btnEight.Text) 'filling the keys with red
  84. End Sub
  85.  
  86. Sub btnNine_Click
  87. Log(btnNine.Text & " clicked")
  88. click_count_Increment_and_fill(btnNine.Text) 'filling the keys with red
  89. End Sub

From there we will create a sub to handle the shading of the panels that is our key1 to key 4

  1. Sub click_count_Increment_and_fill (input_Text As String)
  2.  
  3. Click_Count = Click_Count + 1
  4.  
  5. Select Click_Count
  6. Case 1
  7. key1.Color = Colors.Red
  8.  
  9. 'getting the text value value from the button and passing it ot entered password
  10. entered_Password = entered_Password & input_Text
  11. Log("Current Entered pass: " & entered_Password)
  12. Case 2
  13. key2.Color = Colors.Red
  14.  
  15. 'getting the text value value from the button and passing it ot entered password
  16. entered_Password = entered_Password & input_Text
  17. Log("Current Entered pass: " & entered_Password)
  18. Case 3
  19. key3.Color = Colors.Red
  20.  
  21. 'getting the text value value from the button and passing it ot entered password
  22. entered_Password = entered_Password & input_Text
  23. Log("Current Entered pass: " & entered_Password)
  24. Case 4
  25. key4.Color = Colors.Red
  26.  
  27. 'getting the text value value from the button and passing it ot entered password
  28. entered_Password = entered_Password & input_Text
  29. Log("Current Entered pass: " & entered_Password)
  30.  
  31. '===============================================================
  32. '============CHECKING IF THE PASSWORD IS CORRECT===============
  33.  
  34. If entered_Password = Master_Password Then
  35. Log("Login succesful")
  36. Log("===============")
  37. Log("***SUCCESS****")
  38. Log("================")
  39.  
  40. 'reset
  41. resetting_all
  42.  
  43. 'Letting the user in to a new page afer succesful login
  44. StartActivity(actLoggedIn)
  45. Else
  46. Log("Wrong password")
  47. Log("*************************")
  48.  
  49. 'reset
  50. resetting_all
  51.  
  52. End If
  53. End Select
  54.  
  55. End Sub

Finally we will create a sub which will reset the shaded panels (keys) to white in case of wrong password entry

  1. Sub resetting_all
  2. 'clearing the keys panel for new entry
  3. key1.color = Colors.White
  4. key2.Color = Colors.White
  5. key3.Color = Colors.White
  6. key4.Color = Colors.white
  7.  
  8. 'Resetting entered password to empty
  9. entered_Password = ""
  10.  
  11. 'reset click count to ZERO...This will enable the SELECT CASE STATEMENT
  12. 'TO restart counting from 1 to fill the panels keys
  13. Click_Count = 0
  14. 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

for study purpose thanks for sharing

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.