home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / ventura / vpapp_7s.arc / EXAMP4.PRG < prev    next >
Text File  |  1989-10-09  |  14KB  |  483 lines

  1. * dBase III(R) to Ventura Publisher(R) Professional Extension(R)
  2. *
  3. * Written by John Meyer. Copyright (c) John Meyer 1989.
  4. * This program is offerred as is with no warranty expressed or implied.
  5. * You may use and modify this program, but it may not be sold, nor
  6. * may any part of it be incorporated into any other program 
  7. * which is to be sold.
  8. *
  9. * This dBase program will extract fields in any order from 
  10. * any database you choose. These fields are then formatted
  11. * so that they can be directly read into the Professional Extension
  12. * using the ASCII selection in the Load Text/Picture option.
  13. * Memo fields are allowed and are converted to a column width of 
  14. * 40 characters. This is hard-wired into the program, but can easily
  15. * be changed.
  16. *
  17. * Set the initial environment variables.
  18. *
  19. set confirm on
  20. set scoreboard off
  21. set status off
  22. set safety off
  23. set exact on
  24. set talk off
  25. set echo off
  26. set deleted off
  27. close all
  28. clear all
  29. clear
  30. * Let user specify the database and, optionally, the index by which
  31. * the database should be sorted. Let the user also specify which fields
  32. * in the database should be extracted, and in which order.
  33. * First, initialize the input variables.
  34. *
  35. mdrv = '                              '
  36. mdbf = '            '
  37. midx = '            '
  38. mout = '            '
  39. entry=.F.
  40. do while .not. entry
  41.   entry=.T.
  42. *
  43. * Re-initialize the length of the input variables for successive passes
  44. * through the input questions.
  45. *
  46.   mdrv = mdrv+replicate(" ",30-len(mdrv))
  47.   mdbf = mdbf+replicate(" ",12-len(mdbf))
  48.   midx = midx+replicate(" ",12-len(midx))
  49.   mout = mout+replicate(" ",12-len(mout))
  50. *
  51. * Generate input screen.
  52. *
  53.   @ 2,4 say 'Enter drive and directory (optional) : ' get mdrv pict '@! XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  54.   @ 3,4 say 'Enter Database File Name             : ' get mdbf pict '@! XXXXXXXXXXX'
  55.   @ 4,4 say 'Enter Index File Name (optional)     : ' get midx pict '@! XXXXXXXXXXX'
  56.   @ 5,4 say 'Output File Name (default-TABLE.TXT) : ' get mout pict '@! XXXXXXXXXXX'
  57.   @ 24,10 say 'Press "Ctrl" plus "End" or "Ctrl" plus "W" when finished.'
  58.   read
  59. *
  60. * Clear the alert lines.
  61. *
  62.   @ 7,0
  63.   @ 8,0
  64.   @ 9,0 
  65. *
  66. * Change the default drive and directory, if specified.
  67. *
  68.   if .not. mdrv='                              '
  69.     if ":"$mdrv
  70.       store at(":",mdrv) to start
  71.       store trim(substr(mdrv,start-1,start)) to temp
  72.       set default to &temp
  73.       store trim(substr(mdrv,start+1,len(mdrv))) to temp
  74.       set path to &temp
  75.     else
  76.       set path to &mdrv
  77.     endif
  78.   endif
  79. * Check to see if user added the DBF extension to database file name.
  80. * If not, add it.
  81. *
  82.   if .not. "."$mdbf
  83.     mdbf=trim(mdbf)+".DBF"
  84.   else
  85.     mdbf=trim(mdbf)
  86.   endif
  87. *
  88. * Check to see if database file exists.
  89. *
  90.   if .not. file(mdbf)
  91.     clear
  92.     ? chr(7)
  93.     @ 7,10 say '---> Database file ' + mdbf + ' not found <---'
  94.     entry=.F.
  95.   endif
  96. *
  97. * Check if user entered an index file name. If yes, then
  98. * check to see if the file exists. 
  99. *
  100.   if midx='                              '
  101.     midx=' '
  102.   else
  103.     if .not. "."$midx
  104.       midx=trim(midx)+".NDX"
  105.     else
  106.       midx=trim(midx)
  107.     endif
  108.     if .not. file(midx)
  109.       clear
  110.       ? chr(7)
  111.       @ 8,10 say '---> Index file ' + midx + ' not found <---'
  112.       entry=.F.
  113.     endif
  114.   endif
  115. *
  116. * If no output file name was specified, assign a default file name called
  117. * TABLE.TXT. Then, check to see if the output file name exists. If
  118. * no extension is specified, dBase will assume .TXT.
  119. *
  120.   if mout='                              '
  121.     mout="table.txt"
  122.   endif
  123.   if .not. "."$mout
  124.     mout=trim(mout)+".txt"
  125.   else
  126.     mout=trim(mout)
  127.   endif
  128.   if file(mout)
  129.     ? chr(7)
  130.     @ 9,10 say '---> Ouput file ' + mout + ' already exists. Pick a new one. <---'
  131.     entry=.F.
  132.   endif
  133. enddo
  134. *
  135. * Open the data base requested by the user.
  136. *
  137. if "."$midx
  138.   midx='index '+midx
  139. endif
  140. use &mdbf &midx
  141. * Create a database which contains the field names and 
  142. * length of the chosen database.
  143. copy structure extended to temptabl
  144. sele b
  145. use temptabl
  146. *
  147. * Check to see if database has more fields than this sample program
  148. * can handle
  149. *
  150. go bott
  151. if recno()>22
  152.   ? chr(7)
  153.   clear
  154.   @ 10,5 say "This database contains more than 22 fields."
  155.   @ 11,5 say "The input form for this program is only"
  156.   @ 12,5 say "set up for 22 fields. If you want this program to work"
  157.   @ 13,5 say "with an unlimited number of fields, you must modify it"
  158.   @ 14,5 say "yourself."
  159.   cancel
  160. endif
  161. * Save the stucture database's decimal setting in an "array" variable.
  162. * Then, initialize the sort/selection (field_dec) for each field to 0.
  163. *
  164. * This is required because the selection criteria will be stored in 
  165. * the structure database so that it can be sorted. This sorted database
  166. * is then used to print out the fields of the chosen database in the 
  167. * order specified.
  168. go top
  169. do while .not. eof()
  170.   i=ltrim(str(recno()))
  171.   store field_dec to m_dec&i
  172.   replace field_dec with 0
  173.   skip +1
  174. enddo
  175. *
  176. * Display the headings for the input form.
  177. *
  178. clear
  179. @ 1,0
  180. TEXT
  181.                                  Enter numbers in the Sort Order
  182.                                  column for every field you wish to
  183.                                  retrieve. Enter 1 for the field you wish
  184.                                  to appear in column 1 of the Ventura
  185.                                  Publisher table, 2 for field you wish
  186.                                  to appear in column 2, etc. If you leave 
  187.                                  the Sort Order column blank, ALL records 
  188.                                  are retrieved.
  189.  
  190.                                  Enter names in the Tag Name column
  191.                                  if you want a particular field tagged
  192.                                  with a tag other than TABLE TEXT.
  193. ENDTEXT
  194. @ 0,0 say "Sort"
  195. @ 1,0 say "Order"
  196. @ 0,8 say "Field"
  197. @ 1,8 say "Name"
  198. @ 0,22 say "Tag"
  199. @ 1,22 say "Name"
  200. * Create the input form for the selection criteria.
  201. * The selection numbers will be stored in the "array" called
  202. * M_ORDER&I. This array information will then be transferred to
  203. * the FIELD_DEC field of the structure database.
  204. Y=2
  205. go top
  206. do while .not. eof()
  207.   i=ltrim(str(recno()))
  208.   m_order&i="  "
  209.   @ Y,2 get m_order&i picture "99"
  210.   @ Y,7 say field_name
  211.   Y=Y+1
  212.   skip +1
  213. enddo
  214. *
  215. * Create the input form for special tag names which can be associated
  216. * with each cell in the table, if desired. These tag names are stored
  217. * in the "array" variable called M_TAG&Y.
  218. *
  219. go top
  220. Y=2
  221. do while .not. eof()
  222.   i=ltrim(str(recno()))
  223.   m_tag&i="             "
  224.   @ Y,18 get m_tag&i picture "@!"
  225.   Y=Y+1
  226.   skip +1
  227. enddo
  228. @ 24,10    say 'Press "Ctrl" plus "End" or "Ctrl" plus "W" when finished.'
  229. *
  230. * Enter the information.
  231. *
  232. go top
  233. read 
  234. *
  235. * Replace field_dec with order information prior to sorting.
  236. *
  237. go top
  238. do while .not. eof()
  239.   i=ltrim(str(recno()))
  240.   replace field_dec with val(m_order&i)
  241.   skip +1
  242. enddo
  243. *
  244. * Sort the field database so that it can later be used to retrieve 
  245. * fields from the chosen database in the order just specified.
  246. *
  247. index on field_dec to temptabl
  248. *
  249. * If at least one criteria was specified, delete all fields which were
  250. * not selected. This will prevent these fields from being extracted to 
  251. * the table. If NO selection criteria were given, assume that ALL records
  252. * are to be retrieved in the "natural" order of the database.
  253. *
  254. go bott
  255. if field_dec <>0
  256.   delete all for field_dec=0
  257. endif
  258. *
  259. * Figure out how many fields are in database
  260. *
  261. set deleted on
  262. count all to rec_tot
  263. store ltrim(str(rec_tot)) to srec_tot
  264. *
  265. * We're now ready to begin creating the table file.
  266. * Place the table output into the file specified by the user.
  267. *
  268. set alternate to &mout
  269. *
  270. * Create table header. Only some of the Ventura Publisher
  271. * Professional Extension table parameters are used. The number
  272. * of fields in the structure database determines the number of 
  273. * columns.
  274. *
  275. set alternate on
  276. ? "@Z_TBL_BEG = COLUMNS("+srec_tot+"), DIMENSION(PT), "
  277. set alternate off
  278. *
  279. * Figure out the widths for each table entry. These are passed to
  280. * Ventura Publisher with the COLWIDTHS parameter.
  281. *
  282. go top
  283. mrow=""
  284. do while .not. eof()
  285. *
  286. * If the field type is NOT a memo field, then use the FIELD_LEN
  287. * value to set the field width of the table.
  288. *
  289.   if field_type <>"M"
  290.     mrow=mrow+"E"+ltrim(str(field_len))+","
  291.   else
  292. *
  293. * If the field type for this record IS a memo field, set the field
  294. * length to 40. If you want to change this, change the "E40" value
  295. * below to a different number. You could also have the user provide
  296. * this value.
  297. *
  298.     mrow=mrow+"E40,"
  299.   endif
  300.   skip +1
  301. enddo
  302. *
  303. * Set the column widths. Also, set above and below space to 12 points,
  304. * space between columns to 0, space between rows to 12 points, vertical
  305. * justification above and below the table to 12 points maximum, and 
  306. * use the ruling line definitions for the tags Z_DOUBLE and Z_SINGLE
  307. * for the various ruling lines. Turn KEEP off so the table can break
  308. * across page boundaries
  309. *
  310. * You will probably want to change the HGUTTER to put some space between
  311. * columns. It is set to zero here to avoid ever generating a nuisance
  312. * message within Ventura Publisher that can result if your table has 
  313. * lots of columns. If you specify HGUTTER other than zero, you may create
  314. * a situation where no space is left for some of the really narro columns.
  315. *
  316. set alternate on
  317. ? "COLWIDTHS("+subst(mrow,1,len(mrow)-1)+"),"
  318. ? "ABOVE(12), BELOW(12), HGUTTER(0), VGUTTER(12), VJTOP(12), VJBOT(12), "
  319. ? "BOX(Z_DOUBLE), HGRID(Z_SINGLE), VGRID(Z_SINGLE), KEEP(OFF)"
  320. ? ""
  321. set alternate off
  322. *
  323. * Generate the tags for each cell in the table. If no tag is 
  324. * specified, use TABLE TEXT.
  325. *
  326. go top
  327. tag="@Z_TBL_BODY = "
  328. do while .not. eof()
  329.   i=ltrim(str(recno()))
  330.   if m_tag&i = "                "
  331.     tag=tag+"TABLE TEXT, "
  332.   else
  333.     tag=tag+upper(trim(ltrim(m_tag&i)))+", "
  334.   endif
  335.   skip +1
  336. enddo
  337. set alternate on
  338. ? substr(tag,1,len(tag)-2)
  339. ? ""
  340. set alternate off
  341. * The following code transmits the data from the database.
  342. * Each type of field requires slightly different processing.
  343. *
  344. sele a
  345. go top
  346. do while .not. eof()
  347.   sele b
  348.   go top
  349.   mrow=""
  350.   do while .not. eof()
  351.     store field_name to mfname
  352.     if field_type<>"M"
  353.       store A->&mfname to mtable
  354.     endif
  355.     do case 
  356. *
  357. * If the field is a character ("C") field, each comma followed by a 
  358. * space must be converted to TWO commas followed by a space. This
  359. * is required because the Professional Extension's table feature uses
  360. * COMMA SPACE as the delimiter between cells in a table.
  361. *
  362.         case field_type="C"
  363.         store 1 to lc
  364.         do while at(", ",substr(mtable,lc,field_len))<>0  
  365.           store lc+at(", ",substr(mtable,lc,field_len)) to lc
  366.           store stuff(mtable,lc,1,", ") to mtable
  367.           lc=lc+1
  368.         enddo
  369. *
  370. * If the field is a numeric ("N") field, it must be translated to
  371. * a string field. Since the FIELD_DEC field was overwritten in the 
  372. * earlier part of this program, the "array" variable m_dec&i is used
  373. * to specify how many places to generate to the right of the decimal
  374. * point.
  375. *
  376.       case field_type="N"
  377.         i=ltrim(str(recno()))
  378.         store str(mtable,field_len,m_dec&i) to mtable
  379. *
  380. * If the field is a date ("D") field, it must be converted to 
  381. * a string field.
  382. *
  383.       case field_type="D"
  384.         store dtoc(mtable) to mtable
  385. *
  386. * If the field is a Logical ("L") field, it must be converted to 
  387. * a string field.
  388. *
  389.       case field_type="L"
  390.         if mtable
  391.           store "T" to mtable
  392.         else
  393.           store "F" to mtable
  394.         endif
  395. *
  396. * If the field is a Memo ("M") field, we have to play some tricks to
  397. * get it to print out, since dBase doesn't allow string manipulation
  398. * with memo fields. Fortunately, when Ventura Publisher reads ASCII
  399. * text, it doesn't care whether text is all on one line or whether it
  400. * is spread over several lines. Until Ventura Publisher sees two
  401. * carriage return-line feeds in a row WITH NOTHING IN BETWEEN, it 
  402. * assumes that everything should be combined together into one big 
  403. * paragraph.
  404. *
  405.       case field_type="M"
  406.         store "" to mtable
  407.         store recno() to mrecn
  408.         sele a
  409.         store field(mrecn) to mmemo
  410.         set alternate on
  411.         ? substr(mrow,1,len(mrow))
  412.         ? &mmemo
  413.         set alternate off
  414.         store "" to mrow
  415.         sele b
  416.     endcase
  417. *
  418. * Combine this cell entry with all previous cell entries. Use the 
  419. * SKIP function to get the next database field.
  420. *
  421.     mrow=mrow+ltrim(trim(mtable))+", "
  422.     skip +1
  423.   enddo
  424. *
  425. * Put out the rest of the data unless the last field was a memo field
  426. * (i.e., if mrow contains nothing but a comma followed by a space, then
  427. * the last record was a memo field and all previous fields were already
  428. * sent as part of the memo case statement.
  429. *
  430.   if mrow<>", "
  431.     set alternate on
  432.     ? substr(mrow,1,len(mrow)-2)
  433.     set alternate off
  434.   endif
  435. *
  436. * Use the SKIP function to get the next database record.
  437. *
  438.   sele a
  439.   skip +1
  440.   set alternate on
  441.   ? ""
  442.   set alternate off
  443. enddo   
  444. *
  445. * Send the end of table information to the Ventura Publisher file.
  446. * Then, close all files and delete all temporary files.
  447. *
  448. set alternate on
  449. ? "@Z_TBL_END = "
  450. ? ""
  451. ? ""
  452. set alternate off
  453. close alternate
  454. *
  455. * Return all variables to factory defaults. Delete all temporary files.
  456. *
  457. close all
  458. clear all
  459. !del temptabl.*
  460. set default to
  461. set path to
  462. set confirm off
  463. set scoreboard on
  464. set status on
  465. set safety on
  466. set exact off
  467. set deleted on
  468. set talk on
  469. set echo on
  470. return
  471.