home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBAPG.ARC
/
FORMGEN.PRG
< prev
next >
Wrap
Text File
|
1984-08-12
|
15KB
|
502 lines
* Program.: FORMGEN.PRG
* Author..: Luis A. Castro & Roy M. Moore
* Date....: 7/11/83
* Notice..: Copyright 1983, Ashton-Tate, All Rights Reserved
* Version.: dBASE II, version 2.4x
* Notes...: Generates a command file which prints reports
* similar to the REPORT FORM command.
* Includes subtotaling and totaling.
* Local...: equals, y:n, extension, datafile, formfile,
* lmargin, pagelen, pagewidth, pagehdg, string,
* issubtotal, totstack, substack, subfield,
* Mcontents, Mwidth, option, item, prompt,
* yourname, totalopts, stackcount, heading,
* width, istotal, col
*
CLEAR
SET TALK OFF
STORE ".PRG" TO extension
STORE "Your Name" TO yourname
STORE "N" TO y:n
STORE "========================================" +;
"========================================" TO equals
* ---Macros to determine WIDTH & CONTENTS of values entered.
STORE [VAL($(option&item,1,@(",",option&item)-1))] TO Mwidth
STORE [option&item,@(",",option&item)+1,] +;
[LEN(option&item)-@(",",option&item)] TO Mcontents
*
* ---Open datafile name.
ERASE
@ 2, 0 SAY "REPORT FORM program generator"
@ 2,72 SAY DATE()
@ 3, 0 SAY "========================================"
@ 3,40 SAY "========================================"
ACCEPT "Enter DATABASE filename " TO datafile
STORE !( TRIM(datafile) ) + "." TO datafile
STORE $( datafile, 1, @(".",datafile) - 1 ) TO datafile
DO CASE
CASE datafile = " "
ERASE
CLEAR
SET TALK ON
RETURN
CASE .NOT. FILE( datafile + ".DBF" )
? "FILE DOES NOT EXIST"
CLEAR
SET TALK ON
RETURN
ENDCASE
USE &datafile
*
* ---Get REPORT FORM filename.
ACCEPT "Enter REPORT FORM filename " TO formfile
STORE !( TRIM( formfile ) ) + "." TO formfile
STORE $( formfile, 1, @(".",formfile) - 1 ) TO formfile
DO CASE
CASE formfile = " "
ERASE
CLEAR
SET TALK ON
RETURN
CASE FILE( formfile + extension )
* ---Command file already exists.
SET BELL OFF
STORE "N" TO select
@ 7,0 SAY "COMMAND FILE ALREADY EXISTS. " +;
"Delete it? (Y/N) ";
GET select PICTURE "!"
READ
SET BELL ON
@ 7,0 SAY "C"
IF select <> "Y"
CLEAR
SET TALK ON
RETURN
ENDIF
ENDCASE
STORE formfile + extension TO formfile
*
* ---Enter REPORT FORM parameters.
?
? "ENTER OPTIONS:"
ACCEPT " Left Margin...<1>." TO lmargin
ACCEPT " Lines/Page...<56>." TO pagelen
ACCEPT " Page Width...<80>." TO pagewidth
* ---Set to default values if null entries.
IF VAL(lmargin) = 0
STORE "1" TO lmargin
ENDIF
IF VAL(pagelen) = 0
STORE "56" TO pagelen
ENDIF
IF VAL(pagewidth) = 0
STORE "80" TO pagewidth
ENDIF
?
ACCEPT "Enter Page Heading." TO pagehdg
ACCEPT "Are Totals Required? (Y/N) " TO string
STORE @( string, "Yy" ) > 0 TO istotal
ACCEPT "Subtotals in Report? (Y/N) " TO string
STORE @( string, "Yy" ) > 0 TO issubtotal
*
* ---Set up environment for totaling.
STORE " " TO totstack,substack
IF issubtotal
STORE 1 TO counter
STORE " " TO subfield
DO WHILE subfield = " " .AND. counter <= 3
ACCEPT "Enter subtotal field" TO subfield
STORE !(subfield) TO subfield
IF 0 = TEST(&subfield)
* ---If subfield not in the datafile.
STORE " " TO subfield
ENDIF
STORE counter + 1 TO counter
ENDDO
IF counter > 3
CLEAR
SET TALK ON
RETURN
ENDIF
ENDIF
?
* ---Enter REPORT FORM Width,Contents.
? "ENTER COLUMN DESCRIPTORS:"
*
* ---Loop through until a carriage return
* ---or more than 12 options are entered.
STORE "11" TO item
STORE "X" TO option&item
DO WHILE option&item <> " " .AND. VAL( item ) <= 22
STORE STR( VAL(item)-10, 2 ) + ". Width,Contents." TO prompt
ACCEPT "&prompt" TO option&item
STORE $(&Mcontents) TO string
IF @(",",option&item) > 3 .OR. @(",",option&item) = 0 .OR.;
option&item = " " .OR. 0 = TEST(&string)
* ---Syntax error in input, or exit.
* ---The TEST() function will return 0,
* ---if the contents cannot be parsed.
LOOP
ENDIF
IF TYPE(&string)="L"
* ---Logicals are not accepted.
LOOP
ENDIF
ACCEPT " Heading........" TO heading&item
IF LEN(heading&item) > &Mwidth
STORE $(heading&item,1,&Mwidth) TO heading&item
ENDIF
* ---See if field entered is numeric, so as to inquire
* ---about totaling and/or subtotaling for this field.
* ---The TEST() function will always return a negative
* ---number on numeric fields or numeric memory variables.
IF 0 > TEST(&string) .AND. istotal
ACCEPT " Totals? (Y/N)" TO y:n
IF !(y:n) = "Y"
STORE totstack + "&item" TO totstack
ENDIF
ENDIF
IF 0 > TEST(&string) .AND. issubtotal
ACCEPT " Subtotals? (Y/N)" TO y:n
IF !(y:n) = "Y"
STORE substack + "&item" TO substack
ENDIF
ENDIF
?
STORE STR( VAL( item ) + 1, 2 ) TO item
STORE "X" TO option&item
ENDDO
STORE VAL( item ) - 1 TO totalopts
IF option11=" "
CLEAR
SET TALK ON
RETURN
ENDIF
*
* ---Create a temporary structure file to
* ---determine field LEN and DEC for numerics.
COPY STRUCTURE EXTENDED TO &datafile..$$$
USE &datafile..$$$
*
* ---Generate REPORT FORM file.
ERASE
SET RAW ON
SET ALTERNATE TO &formfile
SET ALTERNATE ON
? [* Program.: ] + formfile
? [* Author..: ] + yourname
? [* Date....: ] + DATE()
? [* Notice..: Copyright 19] + $( DATE(), 7, 2 ) +;
[, All Rights Reserved]
? [* Local...: pagenum, line, pagehdg, col:hdg, condition,]
? [* lastrec]
? [*]
? [SET TALK OFF]
? [SET BELL OFF]
? [SET MARGIN TO ] + lmargin
? [STORE 1 TO pagenum]
? [STORE 254 TO line]
? [STORE "] + pagehdg + [" TO pagehdg]
? [STORE ( ] + pagewidth + [ - LEN( pagehdg ) ) / 2 TO col:hdg]
STORE "11" TO item
IF istotal .AND. LEN(totstack) <> 1
? [*]
? [* ---Initialize accumulators.]
STORE $( totstack, 2, LEN( totstack ) ) TO totstack
STORE "11" TO item
STORE 1 TO stackcount
DO WHILE stackcount < LEN( totstack )
IF item = $( totstack, stackcount, 2 )
? [STORE 0 TO total&item]
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
ENDIF
IF issubtotal .AND. LEN(substack) <> 1
STORE $( substack, 2, LEN( substack ) ) TO substack
STORE "11" TO item
STORE 1 TO stackcount
DO WHILE stackcount < LEN( substack )
IF item = $( substack, stackcount, 2 )
? [STORE 0 TO subtot&item]
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
ENDIF
? [*]
? [* ---Open the datafile and print the report.]
? [USE ] + datafile
? [ERASE]
? [@ 2, 0 SAY pagehdg]
? [@ 2,72 SAY DATE()]
? [@ 3, 0 SAY "========================================"]
? [@ 3,40 SAY "========================================"]
? [STORE " " TO select]
? '@ 5,0 SAY "Output to the screen or printer? [S/P] ";'
? [ GET select PICTURE "!"]
? [READ]
? [DO CASE]
? [ CASE select = "S"]
? [ ERASE]
? [ STORE 22 TO pagelen]
? [ CASE select = "P"]
? [ SET FORMAT TO PRINT]
? [ STORE ] + pagelen + [ TO pagelen]
? [ OTHERWISE]
? [ ERASE]
? [ SET BELL ON]
? [ SET TALK ON]
? [ RETURN]
? [ENDCASE]
? [* ---Enter FOR <expression> for the report, such as,]
? [* ---STORE "STATE = 'CA'" TO condition]
? [STORE " " TO condition]
? [DO WHILE .NOT. EOF]
? [ IF line > pagelen]
? [ IF select = "S"]
? [ ERASE]
? [ ELSE]
? [ EJECT]
? [ ENDIF]
? [ @ 0,0 SAY "PAGE NO."]
? [ @ 0,9 SAY STR(pagenum,3)]
? [ @ 2,col:hdg SAY pagehdg]
? [ *]
? [ * ---Generate column headings.]
* ---Provide for proper column spacing.
STORE STR( totalopts, 2 ) TO colcount
DO WHILE VAL( colcount ) >= 11
STORE "11" TO item
STORE 0 TO col&colcount
DO WHILE VAL( colcount ) > VAL( item )
STORE col&colcount + &Mwidth + 1 TO col&colcount
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
STORE col&colcount + ((VAL(colcount)-11)*2) TO col&colcount
STORE STR( VAL( colcount ) - 1, 2 ) TO colcount
ENDDO
* ---Generate headings.
STORE "11" TO item
DO WHILE VAL(item) <= totalopts
? [ @ 4,] + STR(col&item,3) + [ SAY "]+heading&item+["]
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
* ---Generate underlining.
STORE "11" TO item
DO WHILE VAL( item ) <= totalopts
? [ @ 5,] + STR(col&item,3) + [ SAY "] +;
$(equals,1,&Mwidth) + ["]
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
? [ STORE pagenum + 1 TO pagenum]
? [ STORE 7 TO line]
? [ ENDIF]
? [ * ---Test to see if the condition exists.]
? [ IF condition <> " "]
? [ IF .NOT. ( ] + "&" + [condition )]
? [ SKIP]
? [ LOOP]
? [ ENDIF]
? [ ENDIF]
*
* ---Control break for subtotals.
IF issubtotal .AND. LEN(substack) <> 1
? [ IF 0=TEST(lastrec)]
? [ * ---Field has not been initialized.]
? [ STORE ] + subfield + [ TO lastrec]
? [ ENDIF]
? [ *]
? [ * ---Print subtotals and reset accumulators]
? [ * ---upon control break.]
? [ IF lastrec <> ] + subfield
STORE "11" TO item
STORE 1 TO stackcount
? [ STORE line + 1 TO line]
LOCATE FOR Field:name = subfield
IF Field:type = "N"
? [ @ line,2 SAY "** SUBTOTAL FOR "] +;
[+STR(lastrec,] + STR(Field:len,3) +;
[,] + STR(Field:dec,2) + [)+" **"]
ELSE
? [ @ line,2 SAY ] +;
["** SUBTOTAL FOR "+TRIM(lastrec)+" **"]
ENDIF
? [ STORE line + 1 TO line]
DO WHILE stackcount < LEN(substack)
IF item = $( substack, stackcount, 2 )
LOCATE FOR Field:name = $(&Mcontents)
IF .NOT. EOF
* ---Is a single field.
? [ @ line,] + STR(col&item,3) +;
[ SAY STR(subtot&item,] +;
STR(&Mwidth,3) + [,] + STR(Field:dec,1) + [)]
ELSE
* ---Is an expression.
* ---Hard code DEC to 2.
? [ @ line,] + STR(col&item,3) + [ SAY ] +;
[STR(subtot&item,] + STR(&Mwidth,3) + [,2)]
ENDIF
? [ STORE 0 TO subtot&item]
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
? [ STORE line + 2 TO line]
? [ STORE ] + subfield + [ TO lastrec]
? [ ENDIF]
ENDIF
*
* ---Detail line section.
? [ *]
? [ * ---Print detail line.]
STORE "11" TO item
DO WHILE VAL(item) <= totalopts
STORE $(&Mcontents) TO string
STORE &Mwidth TO width
LOCATE FOR Field:name = string
IF .NOT. EOF
* ---The contents is a Field name.
IF Field:type="C"
* ---The field is a character type.
? [ @ line,] + STR(col&item,3) + [ SAY ] +;
[$(] + string + [,1,] + STR(width,3) + [)]
ELSE
* ---The field is a numeric type.
? [ @ line,] + STR(col&item,3) + [ SAY ] +;
[$(STR(] + string + [,] + STR(width,3) +;
[,] + STR(Field:dec,2) + [),1,] + STR(width,3) + [)]
ENDIF
ELSE
* ---The contents is an expression.
USE &datafile
IF 0 > TEST(&string)
* ---The expression is a numeric type.
* ---Hard code the LEN and DEC to 10,2.
? [ @ line,] + STR(col&item,3) + [ SAY ] +;
[$(STR(] + string + [,10,2),1,] + STR(width,3) + [)]
ELSE
* ---The expression is a character type.
? [ @ line,] + STR(col&item,3) + [ SAY ] +;
[$(] + string + [,1,] + STR(width,3) + [)]
ENDIF
* ---Reopen the STRUCTURE EXTENDED datafile.
USE &datafile..$$$
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
*
* ---Accumulate totals and/or subtotals.
? [ STORE line + 1 TO line]
IF istotal .AND. LEN(totstack) <> 1
? [ *]
? [ * ---Accumulate totals and/or subtotals.]
STORE "11" TO item
STORE 1 TO stackcount
DO WHILE stackcount < LEN(totstack)
IF item=$(totstack,stackcount,2)
? [ STORE total&item+] + $(&Mcontents) +;
[ TO total&item]
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL(item) + 1, 2 ) TO item
ENDDO
ENDIF
IF issubtotal .AND. LEN(substack) <> 1
STORE "11" TO item
STORE 1 TO stackcount
DO WHILE stackcount < LEN(substack)
IF item = $( substack, stackcount, 2 )
? [ STORE subtot&item+] + $(&Mcontents) +;
[ TO subtot&item]
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL(item) + 1, 2 ) TO item
ENDDO
ENDIF
? [ SKIP]
? [ENDDO]
*
* ---Final subtotal and totals.
IF issubtotal .AND. LEN(substack) <> 1
? [*]
? [* ---Print last subtotal record after end-of-file.]
? [STORE line + 1 TO line]
LOCATE FOR Field:name = subfield
IF Field:type = "N"
? [@ line,2 SAY "** SUBTOTAL FOR "] + [+STR(lastrec,] +;
STR(Field:len,3) + [,] + STR(Field:dec,2) + [)+" **"]
ELSE
? [@ line,2 SAY "** SUBTOTAL FOR "+TRIM(lastrec)+" **"]
ENDIF
? [STORE line + 1 TO line]
STORE "11" TO item
STORE 1 TO stackcount
DO WHILE stackcount < LEN(substack)
IF item = $( substack, stackcount, 2 )
STORE $(&Mcontents) TO string
LOCATE FOR Field:name = string
IF .NOT. EOF
* ---Is a single field.
? [@ line,] + STR(col&item,3) +;
[ SAY STR(subtot&item,],&Mwidth,[,] +;
STR(Field:dec,1) + [)]
ELSE
* ---Is an expression.
* ---Hard code DEC to 2.
? [@ line,] + STR(col&item,3) + [ SAY ] +;
[STR(subtot&item,],&Mwidth,[,2)]
ENDIF
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
ENDIF
IF istotal .AND. LEN(totstack) <> 1
? [*]
? [* ---Print final totals.]
STORE "11" TO item
STORE 1 TO stackcount
? [STORE line + 2 TO line]
? [@ line,2 SAY "*** FINAL TOTALS ***"]
? [STORE line + 1 TO line]
DO WHILE stackcount < LEN(totstack)
IF item = $( totstack, stackcount, 2 )
STORE $(&Mcontents) TO string
LOCATE FOR Field:name = string
IF .NOT. EOF
* ---Is a single field.
? [@ line,] + STR(col&item,3) +;
[ SAY STR(total&item,],&Mwidth,[,] +;
STR(Field:dec,1) + [)]
ELSE
* ---Is an expression.
* ---Hard code DEC to 2.
? [@ line,] + STR(col&item,3) +;
[ SAY STR(total&item,],&Mwidth,[,2)]
ENDIF
STORE stackcount + 2 TO stackcount
ENDIF
STORE STR( VAL( item ) + 1, 2 ) TO item
ENDDO
ENDIF
*
? [@ line + 1, 0 SAY " "]
? [SET FORMAT TO SCREEN]
? [RELEASE ALL]
? [SET TALK ON]
? [SET BELL ON]
? [RETURN]
? [* EOF: ] + formfile
?
SET ALTERNATE OFF
SET ALTERNATE TO
USE
DELETE FILE &datafile..$$$
CLEAR
SET RAW OFF
SET TALK ON
RETURN
* EOF: FORMGEN.PRG