Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHR() all commands

Status
Not open for further replies.

acorbally

Programmer
Jan 9, 2001
65
US
How can I find out what the 0-255 character codes are for the CHR() function. I am trying to build a make-shift multiple detail line report by reporting the data to a memo field with formatting. I want each record to be on it's own line. So I am looking for a carriage return. I want the memo field to store a string with all the records but I will need to insert the records into the memo field one at at time.
 
To start with, you can use chr(13) + chr(10) for CR/LF. [smile]
You can look up the ascii table using System->ASCII chart if you're using Foxpro DOS.
Otherwise, go to the web and you'll find something there.




-Dave S.-
[cheers]
Even more Fox stuff at:
 
The back of any old dot matrix prointer will likely give you the code.

Common ones:
8 = bell,
12 (0C) = form feed ?

Try this for characters above 31 (starts with a space)
x = 32
For i = 1 to 14
?
for j = 1 to 16
?? chr(x) + " "
x = x + 1
end for && next j
?
endfor && next i

Add a title and you are through.

End
 
Don't confuse the "0-255 character codes are for the CHR() function" with the various printer responses to these codes.

If you want the CHR() "variables", just look at an ASCII chart since by looking at your Foxpro Help for the CHR() command you will see that the CHR() command merely sends a character associated with a specific numeric ASCII code.

However if you want the Printer Codes and/or how the printer will respond to these CHR() commands (a non-Foxpro question), you need to look to your Printer's specific Programming Command Language (PCL) manual - generally available via the web.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
DSummZZZ is right that CHR(13)+CHR(10) represent CR/LF but sometime I've seen that CHR(13) alone is sufficient to break lines in many cases such as in display windows, etc. So CHR(10) may be optional if not actually printing.
 
CHR(13) may do a carriage return without a line feed. In this case, the print head (or cursor) will return to the beginning of the line and overwrite the text currently there. It is safer to use both.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
I need to use the CHR(10)+chr(13)in a string. What I am wanting to do is to create a string of variables and then add the chr(10)+chr(13) to the end to give it a carriage return. Or perhaps I am going about this all wrong. What I need to do is report with multiple detail bands, and since I can't I am going to gather all of the data into a memo field. This is why I am inquiring about the carriage returns. I want to fill the memo field with each record on a different line. To look something like:

1 John Doe 123 easy street 555-555-5555
2 Jane Doe 666 Elm Street 555-555-1234
3 Jim Doe 112 hickory ave 555-555-3333

This way I can display the memo field and it can look formated as in a report but I can make the field to stretch and then I can display multiple variable length table results in the one report. Any other suggestions?
 
Acorbally:

Here is a relatively simple code snippet that will work in all version of foxpro and on dos.

It includes some testing code which you'd need to strip out.

Unfortunately, in newer versions of FoxPro it would be much simpler.

I'm sure it will require some more error trapping, esp.
regarding the creation of the temporary files.

Also, if you want more granular control of field
positioning - etc., that will require much more code and/or
a different approach.

Hope it helps.

Darrell

[tt]
#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE LineNumPadding SPACE(3)

PRIVATE cOldCentury, cOldSafety, cTempCurs, cTempTbl
PRIVATE cTempFile, nFlHndl, bFail
PRIVATE cNextLine, cText, cLineNum, nLineNumPad

cOldCentury = SET("century")
cOldSafety = SET("safety")
SET CENTURY ON
SET SAFETY OFF


cTempCurs = "_"+SUBSTR(SYS(2015), 4, 10)

* Loop until temp name changes.
* Especially important on fast machines
DO WHILE "_"+SUBSTR(SYS(2015), 4, 10) == cTempCurs
ENDDO

cTempTbl = "_"+SUBSTR(SYS(2015), 4, 10)

cTempFile = SYS(2023)+"\"+SUBSTR(SYS(2015), 4, 10)+".txt"

CREATE TABLE (SYS(2023)+"\"+cTempTbl) (MemFld M)

* This is where your source table/cursor should be selected
* This is just an example on my system

SELECT accountno,invoicenum,compname,phone ;
FROM c:\dev\clients\abs\testtbls\accounts ;
WHERE datesold > CTOD("11/30/2003") ;
ORDER BY invoicenum DESC INTO CURSOR (cTempCurs)

nLineNumPad = LEN(ALLT(STR(RECCOUNT()))) && Line number padding to be used later

* Output table lines to a text file
LIST TO FILE (cTempFile) NOCONSOLE

nFlHndl = FOPEN(cTempFile) && Low level open of output file

bFail = .F. && Set conditional on open failure

IF nFlHndl == -1
bFail = .T.
WAIT "Error opening output file!" WINDOW TIMEOUT 3
ENDIF

IF !bFail
cText = "" &&
* Get header first
DO WHILE UPPER(LEFT(FGETS(nFlHndl),7)) <> &quot;RECORD#&quot; .AND. !FEOF(nFlHndl)
ENDDO

DO WHILE !FEOF(nFlHndl)

* Next line of text
cNextLine = LTRIM(FGETS(nFlHndl))

* Get line number and pad it!
cLineNum = PADL(LEFT(cNextLine,AT(&quot; &quot;,cNextLine)-1),nLineNumPad,LineNumPadding)

* Trim line number from cNextLine
cNextLine = LTRIM(SUBSTR(cNextLine,AT(&quot; &quot;,cNextLine)))

* Concatanate cText with - padded line number, some extra space,
* the next line of text, and a CRLF
cText = cText + cLineNum + LineNumPadding + cNextLine + CRLF

ENDDO

=FCLOSE(nFlHndl)

DELETE FILE (cTempFile)

* cText holds value to be inserted into memo fields

INSERT INTO (cTempTbl) (MemFld) VALUES (cText)

SELECT (cTempTbl)
BROW
USE
DELETE FILE (SYS(2023)+&quot;\&quot;+cTempTbl+&quot;.dbf&quot;)
ENDIF

SET CENTURY &cOldCentury
SET SAFETY &cOldSafety
[/tt]
 
Acorbally:

This line should be change from:
[tt]
* Get line number and pad it!
cLineNum = PADL(LEFT(cNextLine,AT(&quot; &quot;,cNextLine)-1),nLineNumPad,LineNumPadding )[/tt]

To:

[tt]* Get line number and pad it!
cLineNum = PADL(LEFT(cNextLine,AT(&quot; &quot;,cNextLine)-1),nLineNumPad,Space(1))[/tt]

It didn't hurt anything, but it's logically incorrect.

Darrell
 
acorbally, I saw on your January 14 post that you typed the CR/LF sequence as CHR(10)+CHR(13). It should always be CHR(13)+CHR(10). I don't know whether it makes a difference, but that's the way it is always sequenced.

DSummZZZ, I agree that both characters in the sequence are have officialy been required for printing in the past. On January 14 I said that in some cases I've found that only CHR(13) is present. For example, memo fields require only CHR(13) to break a line and display properly in a text window. No, I have not gone so far as to print such memo fields...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top