Help to complete an exercise

I'm creating my page to edit a note, but I'm having trouble translating the block instructions, especially at the position of segment...
Can you help me complete this exercise by displaying the blocks? Please.

  1. Initialize the screen with the selected note.

initialize global NotesList to create empty list

when EditNoteScreen.Initialize
set global NotesList to TinyDB1.GetValue("notes", create empty list)

set SelectedNote to TinyDB1.GetValue("selectedNote", "")

set TitlePart to segment SelectedNote from 1 to position of ":" in SelectedNote - 1

set ContentPart to segment SelectedNote from position of ":" in SelectedNote + 1
set ContentPart to segment ContentPart from 1 to position of ":" in ContentPart - 1

set EditTitleInput.Text to TitlePart
set EditContentInput.Text to ContentPart

  1. Save changes.
    when SaveChangesButton.Click
    if EditTitleInput.Text ≠ "" and EditContentInput.Text ≠ "" then
    set NewTimestamp to call Clock1.FormatDateTime (Clock1.Now, "dd MMM yyyy HH:mm")
    set UpdatedNote to join(EditTitleInput.Text + ":" + EditContentInput.Text + ":" + NewTimestamp)

    // Supprimer l’ancienne note
    remove item TinyDB1.GetValue("selectedNote") from global NotesList

    // Ajouter la note modifiée
    add item to list global NotesList UpdatedNote

    // Sauvegarder
    call TinyDB1.StoreValue("notes", global NotesList)

    call Notifier1.ShowAlert("Note modifiée avec succès !")
    open another screen "HomeScreen"
    else
    call Notifier1.ShowAlert("Remplis tous les champs !")

  2. Delete the note.
    when DeleteNoteButton.Click
    remove item TinyDB1.GetValue("selectedNote") from global NotesList
    call TinyDB1.StoreValue("notes", global NotesList)
    call Notifier1.ShowAlert("Note supprimée")
    open another screen "HomeScreen"

Welcome Chamford

What have you tried?

This advice probably will help you learn to code.
Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps

How to do a lot of basic things with App Inventor are described here: How do you...? .

Also look here App inventor español. Offline. Tutorial. Ejemplos. Instalación. Códigos. Juegos. Curso gratis de App inventor. and here Tutorial Index | imagnity for more tutorials including Imagnity.com List Tutorial, Mirrored - @Saj

Learn about components Component Reference
and visit the Library The MIT App Inventor Library: Documentation & Support Help>Library on the MENU

also try the advice at these links.

To get specific advice you need to share the exercise text and someone might be able to guess what you are trying to do instead of trying to guess. For instance; Initialize the screen with the selected note; what note? Is this something generated by ChatGpt instructions?

1 Like

I asked ChatGPT if I wanted to develop a personal journal-style application using MIT App Inventor.
And he suggested this code for each page.
I was able to create the RegisterScreen, LoginScreen, and AddNoteScreen pages, but I'm having trouble with the rest because I don't understand where to find certain blocks to execute the instructions ChatGPT gave me.
Editing a note doesn't work.
Neither does searching for notes.
In short, the rest is problematic.

That's why I'm asking for your help.

Here is the complete code:

Here's the complete code:

  1. RegisterScreen

when RegisterButton.Click
if PhoneInput.Text ≠ "" and PasswordInput.Text ≠ "" then
call TinyDB1.StoreValue("phone", PhoneInput.Text)
call TinyDB1.StoreValue("password", PasswordInput.Text)
call Notifier1.ShowAlert("Account created successfully!")
open another screen, "LoginScreen"
else
call Notifier1.ShowAlert("Fill in all fields!")

  1. LoginScreen

when LoginButton.Click
if PhoneLogin.Text = TinyDB1.GetValue("phone") and PasswordLogin.Text = TinyDB1.GetValue("password") then
open another screen "HomeScreen"
else
call Notifier1.ShowAlert("Numéro ou mot de passe incorrect.")

  1. HomeScreen

when HomeScreen.Initialize
set NotesList to TinyDB1.GetValue("notes", create empty list)
set NotesListView.Elements to NotesList

when AddNoteButton.Click
open another screen "AddNoteScreen"

when NotesListView.AfterPicking
call TinyDB1.StoreValue("selectedNote", NotesListView.Selection)
open another screen "EditNoteScreen"

  1. AddNoteScreen

initialize global NotesList to create empty list

when AddNoteScreen.Initialize
set global NotesList to TinyDB1.GetValue("notes", create empty list)

when SaveButton.Click
if TitleInput.Text ≠ "" and ContentInput.Text ≠ "" then
// Créer un timestamp lisible
set CurrentDateTime to call Clock1.Now
set Timestamp to call Clock1.FormatDateTime with pattern "dd MMM yyyy HH:mm"

// Créer la note
set NewNote to join (TitleInput.Text + ":" + ContentInput.Text + ":" + Timestamp)

// Ajouter à la liste
add item to list global NotesList NewNote

// Sauvegarder dans TinyDB
call TinyDB1.StoreValue("notes", global NotesList)

call Notifier1.ShowAlert("Note enregistrée avec succès !")

open another screen "HomeScreen"

else
call Notifier1.ShowAlert("Remplis tous les champs !")

  1. EditNoteScreen

initialize global NotesList to create empty list

when EditNoteScreen.Initialize
set global NotesList to TinyDB1.GetValue("notes", create empty list)

set SelectedNote to TinyDB1.GetValue("selectedNote", "")

set TitlePart to segment SelectedNote from 1 to position of ":" in SelectedNote - 1

set ContentPart to segment SelectedNote from position of ":" in SelectedNote + 1
set ContentPart to segment ContentPart from 1 to position of ":" in ContentPart - 1

set EditTitleInput.Text to TitlePart
set EditContentInput.Text to ContentPart

when SaveChangesButton.Click
if EditTitleInput.Text ≠ "" and EditContentInput.Text ≠ "" then
set NewTimestamp to call Clock1.FormatDateTime (Clock1.Now, "dd MMM yyyy HH:mm")
set UpdatedNote to join(EditTitleInput.Text + ":" + EditContentInput.Text + ":" + NewTimestamp)

// Supprimer l’ancienne note
remove item TinyDB1.GetValue("selectedNote") from global NotesList

// Ajouter la note modifiée
add item to list global NotesList UpdatedNote

// Sauvegarder
call TinyDB1.StoreValue("notes", global NotesList)

call Notifier1.ShowAlert("Note modifiée avec succès !")
open another screen "HomeScreen"

else
call Notifier1.ShowAlert("Remplis tous les champs !")

when DeleteNoteButton.Click
remove item TinyDB1.GetValue("selectedNote") from global NotesList
call TinyDB1.StoreValue("notes", global NotesList)
call Notifier1.ShowAlert("Note supprimée")
open another screen "HomeScreen"

  1. SettingsScreen

when ChangePasswordButton.Click
if NewPasswordInput.Text ≠ "" then
call TinyDB1.StoreValue("password", NewPasswordInput.Text)
call Notifier1.ShowAlert("Mot de passe mis à jour !")
set NewPasswordInput.Text to ""
else
call Notifier1.ShowAlert("Champ vide !")

when ExportButton.Click
set NotesList to TinyDB1.GetValue("notes", create empty list)

if length of list NotesList = 0 then
call Notifier1.ShowAlert("Aucune note à exporter.")
else
set CsvContent to "Titre,Contenu,Date\n"

for each item in NotesList
  set parts to split item at ":"
  set CsvContent to join CsvContent + parts[1] + "," + parts[2] + "," + parts[3] + "\n"

call File1.SaveFile(CsvContent, "/Download/mes_notes.csv")
call Notifier1.ShowAlert("Fichier enregistré dans /Download/mes_notes.csv")

when ClearNotesButton.Click
call TinyDB1.StoreValue("notes", create empty list)
call Notifier1.ShowAlert("Toutes les notes ont été supprimées.")

when LogoutButton.Click
open another screen "LoginScreen"

The exported .aia file would be more helpful.

Thanks. I exported it and here it is.
MonJournal.aia (399.2 KB)

Unfortunately that is true for even basic components like Buttons.

If a developer intends to use ChatGPT's advice for coding he or she NEEDs TO KNOW how to use App Inventor Blocks.

It appears you really do not know how to code and you are unable to use the advice ChatGPT provides you. Please read all the links I provided you. Take the programming course so you can learn to code this.

Did you actually read the advice you indicated you liked? Did you actually take the online programming course (so you learn about the controls ChatGPT says you need) ? Did you make the user interface in the Designer? You have to add the controls you need for your Project Designer? You can't start coding Blocks for most actions unless you have tools like Buttons on the Designer.

After you have taken the course and learned some basic programming skills and after you have placed the controls ChatGPT thinks you need, return here and ask a specific question

Are you aware ChatGPT often provides erroneous information?

So far, it appears you want someone to build this for you. Lots of luck.

Thank you for your help.

The problem is that I'm taking a course where we're asked to use MIT App Inventor, but only for a short period of time so that we can be assessed.

Knowing that we're just discovering the tool, I don't think I'll have enough time to read everything.

But rest assured, I already use programming languages ​​like Java for Android, Dart, and PHP. I'm more comfortable writing code than using blocks.

That's the reason for asking for help.

Ai2 Typeblocking should help you

Typeblocking

I see you've done the work, so here's a quick rundown of what to fix:

Screen1:

I will not bother with the advice of closing screens as often as you open them.
This is just a classroom exercise.

AccuielScreen:

image
The text contains test is against the wrong piece of text.
You should be testing ITEM, not global NOTE.
You also forgot to display the FilteredList in your ListView.

AddNotesScreen:


No problems.
Remember for later that the parts of a note are separated by \n, not ':'
You could have saved the notes as a list of lists.

EditNoteScreen:

This is trouble:


selectedNote is not a list. So applying list blocks(length of list?) to it will crash.

Remember how you used \n to separate the title and content parts in each note?
Splitting at ':' will split in the middle of the timestamp, nowhere else.

This is all wrong:
image

You reversed index and list.
Worse, selectedNote is a piece of text, and not an index.
Maybe you should have saved the selectionIndex instead of the Selection?

HomeScreen:
HomeScreen
Not bad, I'll leave it to you to double check tags for the signin across screen for typoes and caps mismatches.

SettingsScreen:

You are not building a CSV table correctly, and your appends lose the thing you are appending to.
The JOIN should have 3 legs, not 2. Use the blue button to add more.
CSV = Comma Separated Values, but you used \n between the columns instead of ','.
image

For a first effort, not bad.

Debugging is an important skill.

I advise using the Companion, and the Do It facility for inspecting data on the fly in the Blocks Editor.