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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing quotation marks to a file

Status
Not open for further replies.

infinitysquadron

Programmer
Aug 2, 2002
20
CA
I'm trying to make a program where it takes information from the date and time, does a few calculations and then prints them out into a file. The proplem is, the file I'm printing to is in a code that an other program uses to run. The code uses quotation marks (") in the code, and I need to use the quotes to tell QBASIC what to write. The two sets of quotes (the ones QBASIC is using and the ones that the code I'm printing uses) conflict, and QBASIC starts to think part of what I'm writing (after the first quote) is part of the QBASIC syntax, and gives me tons of errors.

Example:
OPEN "Somefile.extention" FOR APPEND AS #1
PRINT #1, "code"more code"code"
CLOSE #1

The red quotes are what QBASIC uses, and the green ones are what the code uses. But QBASIC thinks that the first two quotes are what it's supposed to read, and then thinks the rest of the code is QBASIC code, and it's not. Can I get around this problem???
 
PRINT #1 "code" + CHR$(34) + "more code" + CHR$(34) + "code"

The double quotes trick.
 
Also, if you are going to be outputting a LOT of double-quotes, you should store the string returned by [tt]CHR$(34)[/tt] in a variable and add the variable in whenever you want it. Not only will this take less space, but it'll be faster and easier on the string heap. The reason is that even if the argument is a constant, the code [tt]CHR$(34)[/tt] will generate a function call which will create a new string and put it on the heap. Using a variable will prevent this from happening -- the same string will be re-used, instead of new strings being created.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top