Post Reply 
notebook code error
01-02-2023, 07:10 AM
Post: #1
notebook code error
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;
Find all posts by this user
Quote this message in a reply
01-02-2023, 08:34 AM
Post: #2
RE: notebook code error
I can see one issue : you define a local variable mainMenuOptions, but in the WHILE loop you call it mainMenuOption, without ā€˜sā€™.
Find all posts by this user
Quote this message in a reply
01-03-2023, 01:06 AM
Post: #3
RE: notebook code error
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;
Find all posts by this user
Quote this message in a reply
01-04-2023, 04:18 AM
Post: #4
RE: notebook code error
(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
Find all posts by this user
Quote this message in a reply
01-04-2023, 04:22 AM
Post: #5
RE: notebook code error
(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.
Find all posts by this user
Quote this message in a reply
01-04-2023, 04:39 AM (This post was last modified: 01-04-2023 05:45 AM by DrEureka.)
Post: #6
RE: notebook code error
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;
Find all posts by this user
Quote this message in a reply
01-04-2023, 01:47 PM (This post was last modified: 01-04-2023 04:49 PM by roadrunner.)
Post: #7
RE: notebook code error
(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
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: