Attach notes to an individual record.

CD Tom

Member
Licensed User
Longtime User
I have my app working great thanks to all the help from this forum. Now as I look at this I see it would be nice if when I have a member loaded on the screen I would like to add some notes to this individual. I can see a button that says add notes. When the user hits this button they get a window where they can add comments. When they leave the note field the note would be saved either in a database or folder with their member number so when that member is called up again the note would be attached and the button would say notes attached. If they tapped the button the note would come up and they could add more notes to it.
Now that's what I want to do, but not sure what's the best approach or even where to start. So I've come to the god's of B4a for help.
Again thanks for all the help.
 

pluton

Active Member
Licensed User
Longtime User
Hi CD Tom

I see you have done very good progress in B4A. Nice to see you with it.
I'll give you idea how you can do it.

Example:
B4X:
Sub Globals
   Dim TextField As EditText 'your Text field where you will write notes
   Dim MemberID As Int 'or string if your number begins like 007,008 etc...
End Sub

Sub ButtonAddNotes_Click 
   File.WriteString(File.DirRootExternal, MemberID&".txt",TextField.Text) 'it writes text from text field into memberId.txt file example 007.txt
End Sub
Sub ButtonReadNotes_Click
    TextField.Text = File.ReadString(File.DirRootExternal, MemberID&".txt") ' it reads from text file memberid.txt example 007.txt and it shows under text field
End Sub

Hope it will help you.
Just a short tip before read or write a text file first check is that directory writeable and does it exist already same text file in that folder.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, looks good but I have a newbie question, and a dumb one the Textfield thats a edittext box correct? To start with I make the Edittext field visable = false, (not enough room on screen) when they click the add notes I make the edittext visible. When I go to compile I get an error on the dim textfield as edittext Word: edittext
I was trying to see how you go about entering text into the box before writing it to the file.
Am I confusing you.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Short example is attached

Here is code also

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim btnForAll As Button
   Dim ButtonAddNotes As Button
   Dim ButtonReadNotes As Button

   Dim TextField As EditText 'your Text field where you will write notes
    Dim MemberID As String 'or string if your number begins like 007,008 etc...
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("cdtom")
   MemberID = "007"
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub ButtonAddNotes_Click 
    File.WriteString(File.DirRootExternal, MemberID&".txt",TextField.Text)'it writes text from text field into memberId.txt file example 007.txt
   ToastMessageShow("File " &MemberID&".txt saved. WRITE",False)
   TextField.Text = "" 'just to empty edittext box
   TextField.Visible = False 'put edittext visible to false
End Sub
Sub ButtonReadNotes_Click
   TextField.Text = "" 'just empty text if has left something inside it
   TextField.Visible = True 'show edit text
   ToastMessageShow("Load " &MemberID&".txt. READ",False)
    TextField.Text = File.ReadString(File.DirRootExternal, MemberID&".txt") ' it reads from text file memberid.txt example 007.txt and it shows under text field
End Sub

Sub btnForAll_Click
   If TextField.Visible = False Then
   TextField.Visible = True
   ButtonReadNotes_Click
   Else
   ButtonAddNotes_Click
   End If
End Sub

Screenshot
image.png
 

Attachments

  • CdTom_Example.zip
    7.5 KB · Views: 263
Last edited:
Upvote 0

CD Tom

Member
Licensed User
Longtime User
great that worked, now for another question. When I want to enter a note the textfield doesn't show up so I don't know where to start typing. I would like it to overlay some of the data displayed on the screen and maybe some type of a label that says enter notes here or something like that. Or maybe when we tap the add notes button the textfield show up and the keyboard comes up also. Can you show me how do to that.
Thanks
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
1. I looked at Pluton's code and it does show the text box with a hint text that says: 'Type some text here'.
2. Since your database has about 5000 members, how are you going to keep track of 5000 separate text files with notes in them when you eventually have them all created (one file for each member). Your best approach would be to add a COMMENT field to the main table where you keep track of the notes there, so when you open the database and table, the COMMENT information can be easily accessed.
3. Another option would be to have a separate table that has the ID (INTEGER) and the COMMENTS (TEXT) field and you can join it to the main members table via the ID like you would in Access (with your knowledge of Access). In my opinion it is a lot easier to maintain massive data in databses than tex files, of course unless you have a paramont reason.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
I had thought about that but didn't know how if there was a comment field available in this db. I do have this working using the .txt files and it seems to be working fine but you are correct about the amount of .txt file that could accumulate.
Let me see if I have this correct how to add to the comment field.
I would add the field when I create the db say Notes comment, is Notes a reserved word?
Then when I go to save the notes I just do a put to that field for that member or would you use an insert statement
B4X:
m.dbutils.executeMap(sql1, "Insert into members (notes) values (textfield.text) where mbr_number = Id"
not sure if that's even close.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You will need something like this:
B4X:
Dim txt as string
'Do the ALTER only one time to add the new field to the table, then comment it  or delete the code
txt="ALTER TABLE members ADD COLUMN NOTES TEXT "       
SQL1.ExecNonQuery(txt)
'The above code you only do once to add the new column.

Dim MyID as Int 
MyId=24536    'assuming your member number is INTEGER that your insert for
txt="INSERT into members (NOTES) VALUES  (?) WHERE  mbr_number = ?" 
SQL1.ExecNonQuery2(txt,array as object(textfield.text, MyID ))
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Just a question how does the ? work. I see you are using it twice (?) and = ?
Is there some where that explains this.

Thank you for your help
 
Last edited:
Upvote 0

pluton

Active Member
Licensed User
Longtime User
It is simple

txt="INSERT into members (NOTES) VALUES (?) WHERE mbr_number = ?"
SQL1.ExecNonQuery2(txt,array as object(textfield.text, MyID ))

? replaces words

look at SQL Tutorial
 
Upvote 0
Top