Blame | Last modification | View Log | Download
{.CP20}{ Procedure GetFormula repeats calling the procedure GetLine and }{ Evaluate until the line read by GetLine contains a valid formula. }{ Evaluate returns an error position in the string evaluated. If }{ this position is non zero GetLine is called. If the user types }{ ESC in GetLine to abort the editing then the string returned from }{ Getline will contain $FF and te original value of the cell will }{ be restored later. }procedure GetFormula;beginFlashType;repeatGetLine(S,1,24,70,ErrorPosition,True);if S<>Chr($FF) thenbeginEvaluate(IsForm,S,Result,ErrorPosition);if ErrorPosition<>0 thenFlash(15,'Error at cursor'+^G,false)else Flash(15,' ',false);end;until (ErrorPosition=0) or (S=Chr($FF));if IsForm then NewStat:=NewStat+[Formula];end;{.CP20}{ Procedure GetText calls the procedure GetLine with the current }{ cells X,Y position as parameters. This means that text entering }{ takes place direcly at the cells posion on the screen. }procedure GetText;beginFlashType;with Screen[FX,FY] do GetLine(S,XPos[FX],FY+1,70,ErrorPosition,False);end;{.CP20}{ Procedure EditCell loads a copy of the current cells contents in }{ in the variable S before calling either GetText or GetFormula. In }{ this way no changes are made to the current cell. }procedure EditCell;beginwith Screen[FX,FY] dobeginS:=Contents;if Txt in CellStatus then GetText else GetFormula;end;end;{.PA}{ Procedure UpdateCells is a little more complicated. Basically it }{ makes sure to tag and untag cells which has been overwritten or }{ cleared from data from another cell. It also updates the current }{ with the new type and the contents which still is in the temporaly }{ variable "S". }procedure UpdateCells;varFlength: Integer;beginScreen[FX,FY].Contents:=S;if Txt in NewStat {Screen[FX,FY].CellStatus} thenbeginI:=FX; FLength:=Length(S);repeatI:=Succ(I);with Screen[I,FY] dobeginFLength:=Flength-11;if (Flength>0) thenbeginCellStatus:=[Overwritten,Txt];Contents:='';end elsebeginif OverWritten in CellStatus thenbeginCellStatus:=[Txt];GotoCell(I,FY);LeaveCell(I,FY);end;end;end;until (I=FXMax) or (Screen[I,FY].Contents<>'');Screen[FX,FY].CellStatus:=[Txt];end else { string changed to formula or constant }begin { Event number two }I:=FX;repeatwith Screen[I,FY] dobeginif OverWritten in CellStatus thenbeginCellStatus:=[Txt];Contents:='';end;I:=Succ(I);end;until not (OverWritten in Screen[I,FY].CellStatus);with Screen[FX,FY] dobeginCellStatus:=[Constant];if IsForm then CellStatus:=CellStatus+[Formula];Value:=Result;end;end;end;{.PA}{ Procedure GetCell finnaly starts here. This procedure uses all }{ all the above local procedures. First it initializes the temporaly }{ variable "S" with the last read character. It then depending on }{ this character calls GetFormula, GetText, or EditCell. }begin { procedure GetCell }S:=Ch; ErrorPosition:=0; Abort:=false;NewStat:=[];if Ch in ['0'..'9','+','-','.','(',')'] thenbeginNewStat:=[Constant];if not (Formula in Screen[FX,FY].CellStatus) thenbeginGotoXY(11,24); ClrEol;ClearCells;GetFormula;end elsebeginFlash(15,'Edit formula Y/N?',true);repeat read(Kbd,Ch) until UpCase(CH) in ['Y','N'];Flash(15,' ',false);if UpCase(Ch)='Y' then EditCell Else Abort:=true;end;end elsebeginif Ch=^[ thenbeginNewStat:=(Screen[FX,FY].CellStatus)*[Txt,Constant];EditCell;end elsebeginif formula in Screen[FX,FY].CellStatus thenbeginFlash(15,'Edit formula Y/N?',true);repeat read(Kbd,Ch) until UpCase(CH) in ['Y','N'];Flash(15,' ',false);if UpCase(Ch)='Y' then EditCell Else Abort:=true;end elsebeginNewStat:=[Txt];ClearCells;GetText;end;end;end;if not Abort thenbeginif S<>Chr($FF) then UpDateCells;GotoCell(FX,FY);if AutoCalc and (Constant in Screen[FX,FY].CellStatus) then Recalculate;if Txt in NewStat thenbeginGotoXY(3,FY+1); Clreol;For I:='A' to FXMax doLeaveCell(I,FY);end;end;Flash(15,' ',False);GotoCell(FX,FY);end;{.PA}{ Procedure Format is used to }procedure Format;varJ,FW,DEC,FromLine,ToLine: integer;Lock: Boolean;procedure GetInt(var I: integer; Max: Integer);varS: string[8];Err: Integer;Ch: Char;beginS:='';repeatrepeat Read(Kbd,Ch) until Ch in ['0'..'9','-',^M];if Ch<>^M thenbeginWrite(Ch); S:=S+Ch;Val(S,I,Err);end;until (I>=Max) or (Ch=^M);if I>Max then I:=Max;end;beginLowVideo;Msg('Format: Enter number of decimals (Max 11): ');GetInt(DEC,11);Msg('Enter Cell whith remember if larger than 10 next column will lock: ');GetInt(FW,20);Msg('From which line in column '+FX+': ');GetInt(FromLine,FYMax);Msg('To which line in column '+FX+': ');GetInt(ToLine,FYMax);if FW>10 then Lock:=true else Lock:=False;for J:=FromLine to ToLine dobeginScreen[FX,J].DEC:=DEC;Screen[FX,J].FW:=FW;with Screen[Succ(FX),J] dobeginif Lock thenbeginCellStatus:=CellStatus+[Locked,Txt];Contents:='';end else CellStatus:=CellStatus-[Locked];end;end;LowVideo;UpDate;GotoCell(FX,FY);end;