HP Forums

Full Version: notebook code error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm trying to make a notebook-style application, but it gives me a syntax error and I can't find the solution.
Code:
EXPORT Notebook()

BEGIN
  // Define variables for notebook and notes
  LOCAL notebook, notes;
  notebook := {};
  notes := {};

  // Define main menu options
  LOCAL mainMenuOptions;
  mainMenuOptions := ["New note", "View notes", "Delete note"];

  // Main menu loop
  WHILE TRUE DO
    // Display main menu
    mainMenuOption := Menu("Notebook", mainMenuOptions);

    // Handle main menu option selection
    CASE mainMenuOption OF
      1:
        // Create new note
        noteTitle := Input("Enter note title: ");
        noteText := Input("Enter note text: ");
        note := {noteTitle, noteText};
        notes := {note, notes...};
        Disp("Note created successfully.");
      2:
        // View notes
        IF notes = {} THEN
          Disp("No notes to display.");
        ELSE
          noteTitles := {};
          FOR i TO LENGTH(notes) DO
            noteTitles := {noteTitles, notes[i][1]};
          END;
          noteIndex := Menu("Notes", noteTitles);
          Disp("Title: " + notes[noteIndex][1]);
          Disp("Text: " + notes[noteIndex][2]);
        END;
      3:
        // Delete note
        IF notes = {} THEN
          Disp("No notes to delete.");
        ELSE
          noteTitles := {};
          FOR i TO LENGTH(notes) DO
            noteTitles := {noteTitles, notes[i][1]};
          END;
          noteIndex := Menu("Notes", noteTitles);
          notes := {notes[1...noteIndex-1], notes[noteIndex+1...]};
          Disp("Note deleted successfully.");
        END;
    END;
  END;
END;
I can see one issue : you define a local variable mainMenuOptions, but in the WHILE loop you call it mainMenuOption, without ā€˜sā€™.
I dont know if CASE works that way on the prime

here is a Example from the Demo Case


#pragma mode( separator(.,Wink integer(h32) )
EXPORT Demo_CASE()
BEGIN
LOCAL my_rnd,out_str,forever;

REPEAT
PRINT();
FOR J FROM 1 TO 10 DO
my_rnd:=ROUND(RANDOM(1,100),0);
out_str:="Run "+J+", RND:="+my_rnd;
CASE
IF my_rnd<=25 THEN PRINT(out_str+" <= 25") END;
IF my_rnd<=50 THEN PRINT(out_str+" <= 50") END;
IF my_rnd<=75 THEN PRINT(out_str+" <= 75") END;
DEFAULT PRINT(out_str+" <= 100");
END;
END;
PRINT("Press any key to repeat, ON to exit.");
WAIT();
UNTIL forever;

END;
(01-02-2023 08:34 AM)Didier Lachieze Wrote: [ -> ]I can see one issue : you define a local variable mainMenuOptions, but in the WHILE loop you call it mainMenuOption, without ā€˜sā€™.

Thx but, this error persist
(01-03-2023 01:06 AM)Dougggg Wrote: [ -> ]I dont know if CASE works that way on the prime

here is a Example from the Demo Case


#pragma mode( separator(.,Wink integer(h32) )
EXPORT Demo_CASE()
BEGIN
LOCAL my_rnd,out_str,forever;

REPEAT
PRINT();
FOR J FROM 1 TO 10 DO
my_rnd:=ROUND(RANDOM(1,100),0);
out_str:="Run "+J+", RND:="+my_rnd;
CASE
IF my_rnd<=25 THEN PRINT(out_str+" <= 25") END;
IF my_rnd<=50 THEN PRINT(out_str+" <= 50") END;
IF my_rnd<=75 THEN PRINT(out_str+" <= 75") END;
DEFAULT PRINT(out_str+" <= 100");
END;
END;
PRINT("Press any key to repeat, ON to exit.");
WAIT();
UNTIL forever;

END;

Thanks for the info, I'll check it out.
I made a modification instead of using "case" use conditionals, now I have a problem on line 43 that I don't understand why
Code:
EXPORT Notebook()

BEGIN
  // Define variables for notebook and notes
  LOCAL notebook, notes;
  notebook := {};
  notes := {};

  // Define main menu options
  LOCAL mainMenuOptions;
  mainMenuOptions := ["New note", "View notes", "Delete note"];

  // Main menu loop
  WHILE TRUE DO
    // Display main menu
    LOCAL options, optionIndex, option;

    options := ["Option 1", "Option 2", "Option 3"];

    optionIndex := Input("Choose an option: ", options);

    option := options[optionIndex];

    // Handle main menu option selection
    IF option == "Option 1" THEN
      // Create new note
      noteTitle := Input("Enter note title: ");
      noteText := Input("Enter note text: ");
      note := {noteTitle, noteText};
      notes := {note, notes};
      Print("Note created successfully.");
    ELSE
      IF option == "Option 2" THEN
        // View notes
        IF notes = {} THEN
          Print("No notes to display.");
        ELSE
          noteTitles := {};
          FOR i FROM 1 TO LENGTH(notes) DO
            noteTitles := {noteTitles, notes[i, 1]};
          END;
          noteIndex := Input("Notes", noteTitles);
          Print("Title: " + notes[noteIndex, 1]);
Print("Text: " + notes[noteIndex, 2]);
        END;
      ELSE
        IF option == "Option 3" THEN
          // Delete note
          IF notes = {} THEN
            Print("No notes to delete.");
          ELSE
            noteTitles := {};
            FOR i FROM 1 TO LENGTH(notes) DO
              noteTitles := {noteTitles, notes[i, 1]};
            END;
            noteIndex := Input("Notes", noteTitles);
            notes := remove(notes, noteIndex);
            Print("Note deleted successfully.");
          END;
        END;
      END;
    END;
  END;
END;
(01-04-2023 04:39 AM)DrEureka Wrote: [ -> ]I made a modification instead of using "case" use conditionals, now I have a problem on line 43 that I don't understand why
Code:
EXPORT Notebook()

BEGIN
  // Define variables for notebook and notes
  LOCAL notebook, notes;
  notebook := {};
  notes := {};

  // Define main menu options
  LOCAL mainMenuOptions;
  mainMenuOptions := ["New note", "View notes", "Delete note"];

  // Main menu loop
  WHILE TRUE DO
    // Display main menu
    LOCAL options, optionIndex, option;

    options := ["Option 1", "Option 2", "Option 3"];

    optionIndex := Input("Choose an option: ", options);

    option := options[optionIndex];

    // Handle main menu option selection
    IF option == "Option 1" THEN
      // Create new note
      noteTitle := Input("Enter note title: ");
      noteText := Input("Enter note text: ");
      note := {noteTitle, noteText};
      notes := {note, notes};
      Print("Note created successfully.");
    ELSE
      IF option == "Option 2" THEN
        // View notes
        IF notes = {} THEN
          Print("No notes to display.");
        ELSE
          noteTitles := {};
          FOR i FROM 1 TO LENGTH(notes) DO
            noteTitles := {noteTitles, notes[i, 1]};
          END;
          noteIndex := Input("Notes", noteTitles);
          Print("Title: " + notes[noteIndex, 1]);
Print("Text: " + notes[noteIndex, 2]);
        END;
      ELSE
        IF option == "Option 3" THEN
          // Delete note
          IF notes = {} THEN
            Print("No notes to delete.");
          ELSE
            noteTitles := {};
            FOR i FROM 1 TO LENGTH(notes) DO
              noteTitles := {noteTitles, notes[i, 1]};
            END;
            noteIndex := Input("Notes", noteTitles);
            notes := remove(notes, noteIndex);
            Print("Note deleted successfully.");
          END;
        END;
      END;
    END;
  END;
END;

Here's what i see on a short inspection:

1. A number of varialbles are not defined;
2. Some variables have an "s" on the end such as noteTitle some places and noteTitles other places;
3. The command LENGTH() shoud be length()

Fix these, then see if it compiles.

-road
Reference URL's