Microsoft KB Archive/42857
Article ID: 42857
Article Last Modified on 11/21/2006
- Microsoft QuickBasic 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBasic 4.5 for MS-DOS
- Microsoft BASIC Professional Development System 7.0
This article was previously published under Q42857
When CALLing a C function from QuickBasic and passing a C-format string that contains C escape sequences, the escape sequence does not execute, but rather displays as part of the string. When the following example is used, the C "\n" escape sequence for carriage return/linefeed will not be executed from the C function as expected; the "\n" will simply be displayed as part of the string:
FORMAT$ = "number1= %d number2= %d\n" + CHR$(0) CALL CROUTINE(SADD(FORMAT$),LEN(FORMAT$)
This information applies to QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b, and to Microsoft Basic PDS Version 7.00.
Escape sequences, such as "\n", are replaced with the carriage return/linefeed characters when the C code is compiled. Therefore, if they are passed to a C program at run time, "\n" is not recognized as anything more than part of the string to be displayed.
For the C program to execute an escape sequence passed to it from a QuickBasic program, the actual characters for the desired operation must be appended to the passed string, as in the following example:
FORMAT$ = "number1= d% number2= d%" + CHR$(13) + CHR$(10) + CHR$(0) CALL CROUTINE(SADD(FORMAT$),LEN(FORMAT$)
This passes the carriage return/linefeed sequence to the C function.
Additional query words: QuickBas BasicCom