home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
bix
/
dif.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-08-04
|
3KB
|
142 lines
{TITLE: DIF files (to Lotus 1-2-3 or other such) from Turbo
Here are some Turbo Pascal procedures that you can use to write DIF
files that can be recognized by Lotus 1-2-3 or other spreadsheet
program.}
Var
WKSrows : Integer;
WKScolumns : Integer;
FileName : Str20;
Procedure DIFWrite (TypInd : Integer;
NumValue : Real;
StrValue : Str255 );
Var SNum: Str255;
Begin
Str (NumValue : 15 : 4, SNum);
While SNum[1] = ' ' Do
Delete (SNum, 1, 1);
While SNum [Length(SNum)] = '0' Do
Delete (SNum, Length(SNum), 1);
If SNum [Length(SNum)] = '.' then
Delete (SNum, Length(SNum), 1);
{ write the TypeIndicator, Numeric Value, & String Value }
Writeln (DIFFile, TypInd, ',', SNum);
If TypInd = 0 then
Writeln (DIFFile, 'V')
Else
If TypInd = -1 then
Writeln (DIFFile, StrValue)
Else
Writeln (DIFFile, '"', StrValue, '"');
End;
Procedure DIFString (S : Str255);
Begin
DIFWrite (1, 0, S);
End;
Procedure DIFNumber (N : Real);
Begin
DIFWrite (0, N, '');
End;
Procedure DIFHeader ( RowCount : Integer;
ColumnCount : Integer );
Begin
Writeln (DIFFile, 'TABLE');
DIFWrite(0, 1, '');
Writeln (DIFFile, 'VECTORS');
DIFWrite(0, Int(ColumnCount), '');
Writeln (DIFFile, 'TUPLES');
DIFWrite(0, Int(RowCount), '');
Writeln (DIFFile, 'DATA');
DIFWrite(0, 0, '');
End;
Procedure BegOfTuple;
Begin
DIFWrite (-1, 0, 'BOT');
End;
Procedure EndOfDIF;
Begin
DIFWrite (-1, 0, 'EOD');
End;
Procedure DoEmptyVector;
Begin
DIFWrite (1, 0, '');
End;
Procedure DoEmptyTuple;
Var I : Integer;
Begin
BegOfTuple;
For I := 1 to WKSColumns Do
DoEmptyVector;
End;
Procedure RestOfTuple (NextColumn : Integer);
{ this procedure "fills out" a row in which only the first few }
{ columns have been used. }
Var I : Integer;
Begin
For I := NextColumn to WKSColumns Do
DoEmptyVector;
End;
Procedure LastDIFCall;
Begin
EndOfDIF;
Writeln(DIFfile, ^Z);
Close (DIFfile);
End;
Procedure FirstDIFCall;
Begin
WKSrows := 0; {**** because we don't know ***}
{ (Lotus 1-2-3 won't care) }
WKScolumns := 18; { or whatever }
FileName := 'Budget.DIF'; { " " }
Assign (DIFfile, FileName);
Rewrite(DIFfile);
DIFHeader ( WKSrows, WKScolumns);
DoEmptyTuple; {optional, I use it as a separator}
End;
(*declare STR20 as a String[20] type before the incorporation of the
above code.*)
{I forgot. Also declare
DIFFile : Text;
somewhere ahead of the code.}