home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
calculat
/
addcol.zip
/
ADDCOL.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-07-14
|
2KB
|
91 lines
PROGRAM AddColumnOfNumbersInFile;
CONST
ProgData = 'ADDCOL- Free DOS utility: adds a column of numbers in a text file.';
ProgDat2 = 'V1.00: July 14, 1993. (c) 1993 by David Daniel Anderson - Reign Ware.';
Usage = 'Usage: ADDCOL <file> [<column # start in> <column width>]';
VAR
NumbFile : Text;
CSumStr : String[40];
CSum : Real;
StartLoc,
NumbLen : Byte;
NumbersAdded : Word;
PROCEDURE InitGVars;
VAR ValERR : Integer;
BEGIN
Writeln(ProgData);
Writeln(ProgDat2);
Writeln;
Assign(NumbFile,ParamStr(1));
{$I-} Reset(NumbFile); {$I+}
IF ((IOResult <> 0) OR (ParamCount = 0)) THEN
BEGIN
WriteLn(Usage);
Halt;
END;
IF (ParamCount = 3) THEN
BEGIN
Val(ParamStr(2),StartLoc,ValERR);
Val(ParamStr(3),NumbLen,ValERR);
END
ELSE BEGIN
StartLoc := 1;
NumbLen := 50;
END;
CSum := 0.0;
NumbersAdded := 0;
END;
PROCEDURE AddTheNumbs;
VAR
CNumbStr : String[80];
CNumb : Real;
ValERR : Integer;
MaxLen : Integer;
BEGIN
MaxLen := StartLoc + NumbLen;
REPEAT
ReadLn(NumbFile,CNumbStr);
IF (Length(CNumbStr) <> 0) THEN
BEGIN
Delete(CNumbStr,MaxLen,255);
WHILE (CNumbStr[Length(CNumbStr)] = ' ') DO
Delete(CNumbStr,Length(CNumbStr),1);
CNumbStr := Copy(CNumbStr,StartLoc,NumbLen);
Val(CNumbStr,CNumb,ValERR);
IF (ValERR = 0) THEN
BEGIN
CSum := CSum + CNumb;
Inc(NumbersAdded);
END;
END;
UNTIL Eof (NumbFile);
Close(NumbFile);
END;
FUNCTION NormalizeRealStr ( AbNormal : String ) : String;
VAR LastChar : String[1];
BEGIN
LastChar := Copy(AbNormal,Length(AbNormal),1);
WHILE LastChar = '0' DO
BEGIN
Delete(AbNormal,Length(AbNormal),1);
LastChar := Copy(AbNormal,Length(AbNormal),1);
END;
IF Pos('.',AbNormal) = Length(AbNormal) THEN
Delete(AbNormal,Length(AbNormal),1);
NormalizeRealStr := AbNormal;
END;
BEGIN
InitGVars;
AddTheNumbs;
Str(CSum:0:8, CSumStr);
WriteLn('The ',NumbersAdded,' numbers from "',ParamStr(1),'" total ',NormalizeRealStr(CSumStr));
END.