Question: Can anyone tell me what is causing this error and how I can solve it?

Hi everyone! I was writing this code for an interactive component, when I stumbled into a problem that I couldn't solve...

Here is the code.

use DocumentTools in 
if type(Do(%NIniziale), posint) then
    if Do(%NIterazioni)<=100 then
        if type(Do(%NIterazioni), posint) then
            Do(%E="Valid Values!");
Even:=Do(%Pari);
Odd:=Do(%Dispari);
     Iterazioni:=proc (N, i) 
         local m, n;
         n:=N;  
         for m from 1 to i do 
             if type(n, even) = true then
                 n := Even; 
                 else 
                     n := Odd; 
                     end if;
                     end do; 
                     return (SetCellFormula("Risultati", i, 1, eval(n)));
                     end proc;
ix:=Do(eval(%NIterazioni));
Nx:=Do(eval(%NIniziale));
seq(Iterazioni(Nx,y),y=1..eval(ix));
if Do(%NIterazioni)<100 then
seq(SetCellFormula("Risultati", x, 1, "//"), x=1+ix..100);
end if;
        else
            Do(%E="Inavalid Values");
            seq(SetCellFormula("Risultati", x, 1, "ERROR"), x=1..100);
            end if;
            else 
                Do(%E="Invalid Values");
                seq(SetCellFormula("Risultati", x, 1, "ERROR"), x=1..100);
            end if;
            else 
                Do(%E="Invalid Values");
                seq(SetCellFormula("Risultati", x, 1, "ERROR"), x=1..100);
            end if;
end use; 
 

Now this are what the names stands for:

%Pari is a math conainer in which there is a function of n that is to be used when n is even;

%Dispari is a math conainer in which there is a function of n that is to be used when n is odd;

"Risultati" is the name of a spreadsheet on which the results will be displayed;

%NIterazioni is a math conainer in which there is a posint that indicates how many times the procedure is to be iterated;

%NIniziale is a math conainer in which there is the starting number (another posint) to which on which the procedure will operate;

%E is a text area that will signal the validity of the input.

What I wanted to do was a procedure that reiterated two function on a given number a given amount of times and returned the result of every passage, however, when computing, it returns the function in n and not the final numbers. 

Here is what I mean! (Click for the link, hope Google Drive doesn't break the code when downloaded.).

I have opened the Spread package in the startup-code, and I really want to use the spreadsheet even though it is deprecated in newer versions. When you'll open, the function will be the ones of the Collatz Conjecture, however I want it to be able to iterate any function of n, which will be acquired via input, and will be to the user's choice.

I tried everything that came to my mind: using text area, assigning n outside of the preocedure, using evalf, eval, putting the return inside the if system, opening and closing a do inside "then" and one isndide "else" , changing names and everything... But I couldn't solve it. on the internet and on the MapleHelp I didn't find anything.

So can anyone tell me ( most importantly) why it doens't compute the formulas and just leaves them as input and (less important then the why, but still important and would appreciate) how can it be solved? Thanks to everyone even if you just read this, I know it is amybe a little too much.

Please Wait...