home *** CD-ROM | disk | FTP | other *** search
- **********************************************************************
- ** LAB_GEN.PRG
- ** (C) Copyright 1990-92, Sub Rosa Publishing Inc.
- **
- ** A demonstration program provided to VP-Info users.
- ** This program may be copied freely. If it is used in commercial code,
- ** please credit the source, Sub Rosa Publishing Inc.
- **
- ** LAB_GEN is a more advanced program than any of the others in
- ** the SUB ROSA demo collection. It is offered as a 'DIPLOMA' program.
- ** When you have understood it all, you are well on your way.
- **
- ** LAB_GEN is compatible with all current versions of VP-Info.
- **
- ** LAB_GEN.PRG demonstration program use of macros, files as
- ** vectors, and general matrices. This is a general-purpose
- ** program generator capable of producing most forms of labels
- ** any number of labels across, up to width of printer.
- **
- ** Sid Bursten and Bernie Melman
- **********************************************************************
- xpict=:picture ;save standard picture, restore at end
- :picture='999' ;use short picture in generating label program
- ON escape
- SET print off
- SPOOL
- WINDOW
- ERASE
- :picture=xpict
- CANCEL
- ENDON
- ON error
- SET print off
- SPOOL
- WINDOW
- ERASE
- :picture=xpict
- CANCEL
- ENDON
- DIM char 80 xline[6],xline2[6] ;vectors to hold label-line expressions
- USE matrix compile ;program must have a valid file in use to compile
- xfld1=0 ;variables to hold field numbers from structure
- xfld2=0
- xfld3=0
- xfld4=0
- xfld5=0
- xfld6=0
- xfld7=0
- xfld8=0
- xfld9=0
- xfld10=0
- xfname=blank(8) ;data file name to be put into use with macro
- xndxname=blank(8)
- xwidth=4.25 ;default label width in inches
- xacross=3 ;default number of labels across
- xcpi=10 ;default characters per inch
- xlines=6 ;default depth of label (one inch at 6 lpi)
- xsetup='018'+blank(12)
- xselect='N'
- xselection=blank(50)
- xout='LABEL '
- xoutprg=' '
- xoutcpl=' '
- WINDOW
- ERASE
- WINDOW 1,2,23,77 double ;read in parameters of label job
- TEXT
- .. xfname,!!!!!!!!
- .. xndxname,!!!!!!!!
- .. xout,!!!!!!!!
- .. xacross,9
- .. xwidth,99999.99
- .. xcpi,99.99
- .. xlines,99
- .. xsetup,999-999-999-999-999
- .. xselect,!
-
- GENERAL-PURPOSE PROGRAM GENERATOR FOR LABELS
- (To quit enter ALL BLANKS instead of filename.)
-
- Enter name of file to print to labels........... @xfname
-
- Name of index file (if any) to use for order.... @xndxname
-
- Name of program to generate..................... @xout
-
- Number of labels to print across................ @xacross
- Number of lines per label (measure top to top).. @xlines
-
- Width of each label (right side to right side).. @xwidth inches
- Number of characters per inch for print font.... @xcpi
- Setup string to be sent to printer at start..... @xsetup
- (default is standard spacing on most printers)
- Should selection criteria be used (Y/N)?........ @xselect
- ──────────────────────────────────────────────────────────────────────────
- ENDTEXT
- ON field
- FIELD 0
- @ 22,3 say cen('Press Ctrl-F1 for directory of data files.',74)
- FIELD xfname
- IF xfname=blank(8) .or. :key=350
- :field=65
- ELSE
- IF file(xfname)
- USE &xfname
- @ 22,3 say cen('If no index specified, automatically indexes on zip+lastname',74)
- ELSE
- :field=field(xfname)
- RING
- ENDIF
- ENDIF
- FIELD xndxname
- IF xndxname>blank(8)
- IF file(trim(xndxname)+'.ndx')
- SET index to &xndxname
- ELSE
- :field=field(xndxname)
- RING
- ENDIF
- ENDIF
- @ 22,3 say blank(74)
- FIELD xout
- IF xout=' '
- RING
- :field=field(xout)
- ELSE
- xoutprg=trim(xout)+'.PRG'
- IF file(xoutprg)
- RING
- @ 22,10 say cen(xoutprg+' already exists. Overwrite (Y/N)?',60)
- CURSOR 23,39
- IF !(chr(inkey()))<>'Y'
- :field=field(xout)
- ENDIF
- @ 22,10 say blank(60)
- ENDIF
- ENDIF
- FIELD xacross
- IF xacross<1 .or. xacross>8
- :field=field(xacross)
- RING
- ENDIF
- FIELD xwidth
- IF xwidth<1 .or. xwidth>11
- :field=field(xwidth)
- RING
- ENDIF
- FIELD xlines
- IF xlines<4 .or. xlines>24
- :field=field(xlines)
- RING
- ENDIF
- FIELD xcpi
- IF xcpi<5 .or. xcpi>20
- :field=field(xcpi)
- RING
- ELSE
- @ 22,3 say cen('Enter up to ASCII character numbers of printer initialization string',74)
- ENDIF
- FIELD xsetup
- @ 22,3 say blank(74)
- ENDON
- DO WHILE t
- :field=1
- READ
- IF :key=350 ;give directory if Ctrl-F1 is pressed
- SCREEN 1,2
- WINDOW
- CLS
- DIRF *.dbf
- WAIT
- SCREEN 2,1
- ELSE
- BREAK ;no directory needed, we're done
- ENDIF
- ENDDO
- xwidth=int(xcpi*xwidth-1) ;width of ultimate label in characters
- xwidth2=int(xwidth-xcpi/2.5) ;width that ensures no label contents run over end
- formxwidth=(xwidth+2)*xacross ;total print width just enough to accommodate labels
- IF xfname=' ' .or. xout=' '
- CHAIN samples
- ENDIF
- IF xselect='Y' ;get and test valid selection criteria if required
- SELECT 1,2
- WINDOW 10,10,17,69 double
- ? ' Selection Criteria Requested. Enter below:'
- @ 13,13 get xselection
- DO WHILE t
- ERASE 13,17
- READ
- IF xselection=' ' .or. test(xselection)
- BREAK
- ENDIF
- ? ' Error in selection criteria...Press any key.'
- RING
- inkey=inkey()
- ENDDO
- SCREEN 2,1
- WINDOW
- ENDIF
- WINDOW
- ERASE
- USE &xfname
- WINDOW 1,35,22,78 double ;list 1st 21 fields of file structure
- REPEAT iff(dbf(fields)>21,21,dbf(fields)) times varying xfld
- ?? str(xfld,2),fld(name,xfld)
- ?
- ENDREPEAT
- IF dbf(fields)>21 ;if necessary, list next 21 fields of structure
- WINDOW 1,55,22,78 blank
- REPEAT iff(dbf(fields)>42,21,dbf(fields)-21) times varying xfld
- ?? str(xfld+21,2),fld(name,xfld+21)
- ?
- ENDREPEAT
- ENDIF
- WINDOW 1,1,22,30 double ;read in field numbers to use in labels
- TEXT
- .. xfld1,99
- .. xfld2,99
- .. xfld3,99
- .. xfld4,99
- .. xfld5,99
- .. xfld6,99
- .. xfld7,99
- .. xfld8,99
- .. xfld9,99
- .. xfld10,99
- For each of the following, enter number of the field containing the data to include in the label.
-
- If any item is not to appear, leave its number zero.
-
- Title..... @xfld1
- First Name @xfld2
- Last Name. @xfld3
- Position.. @xfld4
- Company... @xfld5
- Address... @xfld6
- City...... @xfld7
- State..... @xfld8
- Zip Code.. @xfld9
- Country... @xfld10
- ENDTEXT
- READ
- WINDOW
- ERASE ;following section generates expressions for label lines
- DO CASE ;title, first name, last name
- CASE xfld1>0 .and. xfld2>0 .and. xfld3>0
- xline[1]='ltrim(trim('+fld(name,xfld1)+')+" "+trim('+fld(name,xfld2)+')+" "+'+fld(name,xfld3)+')'
- CASE xfld2>0 .and. xfld3>0
- xline[1]='ltrim(trim('+fld(name,xfld2)+')+" "+'+fld(name,xfld3)+')'
- CASE xfld3>0
- xline[1]=fld(name,xfld3)
- ENDCASE
- IF xfld4>0 ;position
- xline[2]=fld(name,xfld4)
- ENDIF
- IF xfld5>0 ;company
- xline[3]=fld(name,xfld5)
- ENDIF
- IF xfld6>0 ;address
- xline[4]=fld(name,xfld6)
- ENDIF
- DO CASE ;city, state, zip
- CASE xfld7>0 .and. xfld8>0 .and. xfld9>0
- xline[5]='ltrim(trim('+fld(name,xfld7)+')+", "+trim('+fld(name,xfld8)+')+" "+'+fld(name,xfld9)+')'
- CASE xfld7>0 .and. xfld9>0
- xline[5]='ltrim(trim('+fld(name,xfld7)+')+" "+'+fld(name,xfld9)+')'
- CASE xfld7>0
- xline[5]=fld(name,xfld7)
- CASE xfld7>0 .and. xfld8>0
- xline[5]='ltrim(trim('+fld(name,xfld7)+')+", "+'+fld(name,xfld8)+')'
- CASE xfld9>0
- xline[5]=fld(name,xfld9)
- ENDCASE
- IF xfld10>0 ;country
- xline[6]=fld(name,xfld10)
- ENDIF
- CLS
- xoutprg=trim(xout)+'.PRG'
- xoutcpl=trim(xout)+'.CPL'
- xlines2=0
- REPEAT 6 times varying xfld ;eliminate empty lines in label form
- IF xline[xfld]>' '
- xlines2=xlines2+1
- xline2[xlines2]=xline[xfld]
- ENDIF
- ENDREPEAT
- xskip=xlines-xlines2 ;extra lines needed to get to full depth of label
- IF xacross>1
- xskip=xskip-1 ;for 2 or more across, Info automatically add 1 line
- ENDIF
- SPOOL &xoutprg ;print generated program into output file
- DELETE file &xoutcpls ;old CPL must be deleted to force use of new program
- CLEAR gets
- ERASE
- cdate=date(dmy)
- ctime=time(ampm)
- SET print on ;start generating output program file
- SET width to 250 ;prevents "wrapping" of long lines in program
- ?? '**********************************************************************'
- TEXT
- * LABEL.PRG USES &XFNAME GENERATED &CDATE &CTIME
- **********************************************************************
- WINDOW
- ERASE
- DIM char &xwidth2 label[6,&xacross]
- DIM char &xwidth labelout[&xlines2,&xacross]
- USE &XFNAME
- ENDTEXT
- IF xselect='Y' .and. xselection>' '
- ? 'SET filter to '+xselection
- ENDIF
- IF xndxname>' '
- ? 'SET index to',xndxname
- ELSE
- DO CASE
- CASE xfld9>0 .and. xfld3>0
- ? 'INDEX on '+fld(name,xfld9)+'+!('+fld(name,xfld3)+') to xlabel'
- CASE xfld3>0
- ? 'INDEX on !('+fld(name,xfld3)+') to xlabel'
- CASE xfld9>0
- ? 'INDEX on '+fld(name,xfld9)+' to xlabel'
- ENDCASE
- ENDIF
- TEXT
- DO WHILE .not. printer()
- CLS
- ? 'NOTE: Printer must be ON to print labels. Put on-line and press any key.'
- WAIT
- ENDDO
- SET print on
- SET width to &formxwidth
- GOTO top
- ENDTEXT
- IF xsetup>' '
- xstr=$(xsetup,1,3)
- xsetup2='chr('+xstr+')'
- REPEAT 4 times varying xfld
- xstr=$(xsetup,xfld*3+1,3)
- IF xstr=' '
- BREAK
- ENDIF
- xsetup2=xsetup2+'+chr('+xstr+')'
- ENDREPEAT
- ? 'xsetup2='+xsetup2
- ? '?? xsetup2'
- ENDIF
- TEXT
- DO WHILE .not. eof
- REPEAT &xlines2 times varying xfld
- REPEAT &xacross times varying xcolumn
- labelout[xfld,xcolumn]=' '
- ENDREPEAT
- ENDREPEAT
- REPEAT &xacross times varying xcolumn
- ENDTEXT
- REPEAT xlines2 times varying xfld
- ? ' label[',str(xfld,2),',xcolumn]=',trim(xline2[xfld])
- ENDREPEAT
- TEXT
- xline2=0
- REPEAT &xlines2 times varying xline
- IF label[xline,xcolumn]>' '
- xline2=xline2+1
- labelout[xline2,xcolumn]=label[xline,xcolumn]
- ENDIF
- ENDREPEAT
- SKIP
- IF eof
- BREAK
- ENDIF
- ENDREPEAT
- ? labelout
- ENDTEXT
- IF xskip>0
- TEXT
- REPEAT &xskip times
- ?
- ENDREPEAT
- ENDTEXT
- ENDIF
- TEXT
- ENDDO
- SET print off
- EJECT
- CHAIN samples
- *
- * *** end of program &xoutcpl ***
- * USES &XFNAME GENERATED &CDATE &CTIME
- ENDTEXT
- ?
- SET print off
- SPOOL
- :picture=xpict
- *WRITE &xout ;remove asterisk if you want to inspect program before running
- CHAIN &xout
- *
- * *** END OF PROGRAM LAB_GEN.PRG ***