Puppycode Blog
Dummy for programmers
Module 5 B4A Sample Login Program
Using Database SQLite Browser
B4A (Basic4Android) SAMPLE PROGRAM
Insert data in New Record
username : adminDB2 password: adminDB2 username : adminDB password: adminDB
Step 6. Now create your Design by clicking “Designer ”-> Open Designer in the Menu bar
Step 8. Change the component name in the properties Button= btnlogin
EditText1= txtusername EditText2= txtpassword
Label1 = Username Label2= Password Btnlogin= Login
Step 10. Go back designer and right click the Button named “btnlogin” and generate “Click”
Add this codes to the btnlogin_click Dim cursor1 As Cursor
If txtusername.Text = “” And txtpassword.Text=”” Then Msgbox(“Please fill up all the fields”,”invalid”)
Else
cursor1=SQL1.ExecQuery(“Select * from accounts where username='”& txtusername.Text &”‘ and password ='”& txtpassword.Text &”‘”)
If cursor1.RowCount<>0 Then Msgbox(“Login Successful”,””) Else
Msgbox(“Please check your username or your password”,”wrong input”) End If
Step 12. Now we are going to create a simple program using DATABASE My database name is “datasample.db”
these are the codes you are going to use to connect your database to your program If File.Exists(File.DirInternal,”datasample.db”) = False Then
File.Copy(File.DirAssets,”datasample.db”,File.DirInternal,”datasample.db”) End If
If SQL1.IsInitialized = False Then
SQL1.Initialize(File.DirInternal, “datasample.db”, False) End If
and check the SQL in the library Manager and the Dim SQL1 As SQL
Make sure that your computer/laptop and your android phone connection belongs to the same network
My IP address in my computer is 192.168.1.116 and also in my android phone
Step 14. Configure the connectivity in the b4a in your computer Connect in to your IP
Check the connection in to your android phone
If your status is connected, both devices are connected.
If is not please check your IP in your computer or your network connection or Click START-Wireless
Click the login button without any input in the username and password the output should be
Now input “adminDB” in the username and “adminDB” in the password
or input “adminDB2” in the username and “adminDB2” in the password the output should be
NEXT TUTORIAL: CRUD