home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / REPTOOLS.ZIP / REPT23A.PRG < prev    next >
Encoding:
Text File  |  1995-12-23  |  3.9 KB  |  132 lines

  1. /* REPT23A.PRG
  2.  
  3.    Convert @ SAY printing statements to output to .TXT file under FiveWin,
  4.    which will be printed later using Seiler's REPT23.PRG (formerly Rep23.prg -
  5.    name changed to avoid getting stepped on by future sample reports from
  6.    Ignacio Ortiz)
  7.  
  8.    Written by Roger Seiler 12/23/95
  9.  
  10.    Compile: Clipper Rept23a /n /m /w
  11.    Link:    Blinker fi Rept23a @FiveWin
  12. */ 
  13. #include "Fivewin.ch"
  14.  
  15. STATIC nRow := 0, nRowB := 0, cNewLine := "", cText := ""
  16.  
  17. PROCEDURE REPT23A()
  18.  
  19. LOCAL cMemvar := ""  // default dummy memvar in case quoted text used in @ SAY
  20. LOCAL cMyMemvar := "And so does this."  // an actual memvar
  21. LOCAL cTxtFile := "        .TXT"
  22. LOCAL lGoAhead := .f.
  23. lGoAhead := MsgGet("Print To Text File","Enter name of text file:",@cTxtFile)
  24.  
  25. *-------
  26. /* Original DOS @ SAY printing specs:
  27.  
  28. @ 3, 5 SAY "This goes to printer text file."
  29. @ 3,38 SAY cMyMemvar
  30. @ 5, 5 SAY "And also this."
  31.  
  32.  // For FiveWin, to print to text file, add to beginning and end of each line,
  33.  // use function ToTxt('at-say', cMemvar) or in other words:      
  34.  
  35.      ToTxt('  *** @ SAY statement *** followed by:  ', cMemvar)
  36.      ^^^^^^^                                        ^^^^^^^^^^^
  37.  // note use of single quotes at beginning and end of the 1st ToText param:
  38. */
  39. // @ SAYs modified for FiveWin:
  40.  
  41. ToTxt('@ 3, 5 SAY "This goes to printer text file."', cMemvar) 
  42. ToTxt('@ 3,38 SAY cMyMemvar', cMyMemvar) 
  43. ToTxt('@ 5, 5 SAY "And also this."', cMemvar) 
  44.  
  45. *--------
  46.  
  47. // At end of job, we add the last line to cText and tack on a carriage return:
  48. cText := cText + cNewLine+CRLF
  49.  
  50. // Then we write it to disk as a .TXT file:
  51. MEMOWRIT(cTxtfile, cText)
  52.  
  53.  
  54. RETURN
  55. *------------------------------- End Proc TestPrnt()
  56.  
  57. FUNCTION ToTxt(cLine,cMemvar)
  58.  
  59. // This function analyzes each @ SAY statement in order to position each piece
  60. // of text correctly on the page, building the text one line at a time, and
  61. // then adds each line to a string that will be written to a text file.
  62.  
  63. LOCAL nAt1,nAt2,nAt3,nCol,cBlanks
  64. LOCAL nBlanks := 0
  65.  
  66. nRowB := 0
  67.  
  68. // Find row number:
  69. nAt1 := AT("@", cLine)
  70. nAt2 := AT(",", cLine)
  71. nRowB := VAL( SUBSTR(cLine,nAt1+1,(nAt2-1-nAt1)) )
  72.  
  73. // Just at beginning of first pass:
  74. IF nRow = 0
  75.   DO WHILE nRow # nRowB
  76.    nRow := nRow + 1
  77.    IF nRowB > nRow 
  78.         cText := cText + CRLF
  79.    ENDIF
  80.   ENDDO
  81. ENDIF
  82.  
  83. // Find column number:
  84. nAt3 := AT("SAY", cLine)
  85. IF nAt3 = 0  // Try again if not found above - maybe upper & lower case:
  86.    nAt3 := AT("Say", cLine)
  87. ENDIF
  88. IF nAt3 = 0  // If still not found, maybe all lower case:
  89.    nAt3 := AT("say", cLine)
  90. ENDIF
  91. IF nAt3 = 0
  92.    MsgAlert('Error in finding "SAY" in line ' + STR(nRowB) )
  93.    RETURN nil
  94. ENDIF
  95.  
  96. nCol := VAL( SUBSTR(cLine,nAt2+1,(nAt3-1-nAt2)) )
  97.  
  98. // If moving to a new row, then add the line just finished to cText memvar,
  99. // and tack on a carriage return at end of the line:
  100. IF nRowB > nRow .AND. nRow > 0
  101.      cText := cText + cNewLine+CRLF
  102.   // Initialize a new line:
  103.   cNewLine := ""
  104.   // If next line to be printed is more than one line down the page, 
  105.   // then add appropriate # of carriage returns to get to it:
  106.   DO WHILE nRow # nRowB
  107.    nRow := nRow + 1
  108.    IF nRowB > nRow 
  109.       cText := cText + CRLF
  110.    ENDIF
  111.   ENDDO
  112. ENDIF
  113.  
  114. // If we need to space over to where next piece of text is to be added to a 
  115. // line, then determine # of blank spaces needed and add them onto the line:
  116. nBlanks := (nCol - 1) - LEN(cNewLine)
  117. cBlanks := SPACE(nBlanks)
  118. IF nBlanks > 0
  119.    cNewLine := cNewLine + cBlanks 
  120. ENDIF
  121. // If this piece of text to be added was passed here in cMemvar, then add it
  122. // to the line:
  123. IF !EMPTY(cMemvar)
  124.      cNewLine := cNewLine + cMemvar
  125.    ELSE // If text piece to be added is in a quote instead of cMemvar:
  126.      cNewLine := cNewLine + SUBSTR(cLine, nAt3 + 5, LEN(cLine)-(nAt3+5))
  127. ENDIF      
  128.  
  129. RETURN nil
  130.  
  131. *----------------------------- End ToText()
  132.