Easy to use Database setup -Need Help

LisaM

Member
Licensed User
Longtime User
Hi,

I am very new to Basic4Android I come from App Inventor. I have been using B4A for a week now and i have somewhat firgured out the basics:
- MultiScreen App.
- Button Events
- Changing states: e.g label/button text change, visibility
- InputDialogues etc.

What I am stuck on is setting up a database I am using Margret's easy to use db. I am trying to Create an exercise app.

1st question is: In app inventor If i used a Check Box I needed to save a value for the check box state to db and then recall that value when the program loads. In App inventor it would read something similar to this
If Else Checkbox.checked = True
Then db store value Tag= checkbox1 Value=True As (Boolean)
Else db store value Tag=checkbox1 Value=False As (Boolean)
Do I need to do this in B4A as well?
I have found an answer to this question thnx

2nd Question: I have 3 diff screens with 3 different data entry screens, Do i need to create 3 seperate databases? I have made some progress with this as well but any input on databases would be greatly appreciated!!

I am very very much a :sign0104: and need lots of :sign0085: and I appreciate anyone's input

Cheers
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
For the second question, no, you can use one database or Map file.
 
Upvote 0

LisaM

Member
Licensed User
Longtime User
easy to use db with 2 diff db's and 2 diff layouts

Rather than start a new thread i thought i would just add to this one.
I am having a bit of trouble.
I have setup my DB

B4X:
Dim Pointer As Int : Pointer = -1
   Dim FilePath, FileName As String
   FilePath = File.DirInternal & "/"
   FileName = "Insanity.dat"
   Dim Field(19,2) As String
   Field(0,0) = "WeekNo."      :Field(0,1)=4         'Fit Test Week No.
   Field(1,0) = "P-Jacks"      :Field(1,1)=4         'Power Jacks
   Field(2,0) = "P-Knees"      :Field(2,1)=4         'Power Knees
   Field(3,0) = "P-Jumps"      :Field(3,1)=4         'Power Jumps
   Field(4,0) = "G-Jumps"      :Field(4,1)=4         'Globe Jumps
   Field(5,0) = "S-Jumps"      :Field(5,1)=4         'Suicide Jumps
   Field(6,0) = "PU-Jacks"      :Field(6,1)=4         'Push-Ups Jacks
   Field(7,0) = "Oblique"      :Field(7,1)=4         'Low Plank Oblique
   Field(8,0) = "S-Kicks"      :Field(8,1)=4         'Switch Kicks
   Field(9,0) = ""            :Field(9,1)=0         'Spare
   Field(10,0) = "Date"      :Field(10,1)=100      'Workout Date
   Field(11,0) = "Workout"      :Field(11,1)=100      'WorkoutLabel
   Field(12,0) = "Calories"   :Field(12,1)=100      'Calories
   Field(13,0) = "MaxHr"      :Field(13,1)=100      'Max hr
   Field(14,0) = "AvgHR"      :Field(14,1)=100      'Avg hr
   Field(15,0) = "Complete"   :Field(15,1)=100      'Completed
   Field(16,0) = "Skipped"      :Field(16,1)=100      'Skipped
   Field(17,0) = "Intensity"   :Field(17,1)=100      'Intensity Level
   Field(18,0) = ""         :Field(18,1)=100      'Spare

and i have setup my structure

B4X:
Sub SelectdbFitTest         'Structure for database #1
   pointerhold(2) = db.iif(db.Pointer > -1, db.Pointer, -1)
   db.Pointer = 0
   db.FilePath = File.DirInternal & "/"      
   db.FileName = "fittest.dat"            
   db.Field(0,0) = ""      :db.Field(0,1)=4      'I want this field as my Index   
   db.Field(1,0) = ""      :db.Field(1,1)=4   
   db.Field(2,0) = ""      :db.Field(2,1)=4
   db.Field(3,0) = ""      :db.Field(3,1)=4   
   db.Field(4,0) = ""      :db.Field(4,1)=4   
   db.Field(5,0) = ""      :db.Field(5,1)=4   
   db.Field(6,0) = ""      :db.Field(6,1)=4   
   db.Field(7,0) = ""      :db.Field(7,1)=4   
   db.Field(8,0) = ""      :db.Field(8,1)=4   
   db.Field(9,0) = ""      :db.Field(9,1)=0   
   'Last entry should have field name empty "" and length set to 0
End Sub   
Sub SelectdbWorkout         'Structure for database #2
   pointerhold(1) = db.iif(db.Pointer > -1, db.Pointer, -1)
   db.Pointer = 0      
   db.FilePath = File.DirInternal & "/"      
   db.FileName = "workout.dat"            
   db.Field(10,0) = ""      :db.Field(10,1)=100      'I want this field as my Index   
   db.Field(11,0) = ""      :db.Field(11,1)=100   
   db.Field(12,0) = ""      :db.Field(12,1)=100
   db.Field(13,0) = ""      :db.Field(13,1)=100   
   db.Field(14,0) = ""      :db.Field(14,1)=100   
   db.Field(15,0) = ""      :db.Field(15,1)=100   
   db.Field(16,0) = ""      :db.Field(16,1)=100   
   db.Field(17,0) = ""      :db.Field(17,1)=100   
   db.Field(18,0) = ""      :db.Field(18,1)=0   
    'Last entry should have field name empty "" and length set to 0
End Sub

When i try to put an entry in the workout db i get this error

program paused on line: 774
db.Field(0,0) = lblFitTestWK.Text


it comes from this sub

B4X:
Sub PutFields
   db.Field(0,0) = lblFitTestWk.Text
   db.Field(1,0) = tbSKicks.Text
   db.Field(2,0) = tbPowJacks.Text
   db.Field(3,0) = tbPowKnees.Text
   db.Field(4,0) = tbPowJumps.Text
   db.Field(5,0) = tbGJumps.Text
   db.Field(6,0) = tbSJumps.Text
   db.Field(7,0) = tbPushJacks.Text
   db.Field(8,0) = tbOblique.Text
   db.Field(10,0) = lblWDate.Text
   db.Field(11,0) = lblWDis.Text
   db.Field(12,0) = EditText1.Text
   db.Field(13,0) = EditText2.Text
   db.Field(14,0) = EditText3.Text
   db.Field(15,0) = Ccontainer
   db.Field(16,0) = Scontainer
   db.Field(17,0) = lblIntensityDisplay.Text
End Sub

I understand why I am getting the error in terms of the program is trying to call text from a field when no text has been entered yet. the thing is lblfittestwk has nothing to do with the workout db, it belongs to the fittest db. I initially had PutFields sub set up in 2 separate subs and calling to corresponding sub to the db. but i still get the same error it still tried to call the fitest putfield sub first. I am pulling my hair out everything else seems to work. how do i get this setup correctly if it is even possible??
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You should change your PutFields sub to look like below and I think you will be good.

B4X:
Sub PutFields
   If db.FileName = "fittest.dat" Then
      db.Field(0,0) = lblFitTestWk.Text
      db.Field(1,0) = tbSKicks.Text
      db.Field(2,0) = tbPowJacks.Text
      db.Field(3,0) = tbPowKnees.Text
      db.Field(4,0) = tbPowJumps.Text
      db.Field(5,0) = tbGJumps.Text
      db.Field(6,0) = tbSJumps.Text
      db.Field(7,0) = tbPushJacks.Text
      db.Field(8,0) = tbOblique.Text
      db.Field(10,0) = lblWDate.Text
      db.Field(11,0) = lblWDis.Text
      db.Field(12,0) = EditText1.Text
      db.Field(13,0) = EditText2.Text
      db.Field(14,0) = EditText3.Text
      db.Field(15,0) = Ccontainer
      db.Field(16,0) = Scontainer
      db.Field(17,0) = lblIntensityDisplay.Text
   End If
   If db.FileName = "workout.dat" Then
      'define what the Fields equal in this database
   End If
End Sub

Also, if you are using B4A version 2.0 or above, I have just posted the Class version of this. It may be easier to use.

http://www.b4x.com/forum/additional-libraries-classes-official-updates/22118-class-databases.html
 
Last edited:
Upvote 0

LisaM

Member
Licensed User
Longtime User
Oh thankyou so much!!!
:sign0188:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…