QBasic WRITE

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Afrow_UK
Newbie
Posts:8
Joined:Sun Sep 21, 2003 9:36 pm
QBasic WRITE

Post by Afrow_UK » Sun Sep 21, 2003 9:44 pm

I am trying to write multi-character strings to a file, in this case writing an html doc containing the output of my program.

Now, the problem is, html contains " in them, and also < >
The compiler takes these as open quotes for new parts and operators, but I want them to be just part of the same string.

E.g.
WRITE #1, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>

The compiler stops due to both the < > and ".
If I place "" around the string, I also get them written to the file aswell.
This also writes
"</table><p></p></body></html>" and not
</table><p></p></body></html>

WriteText$ = "</table><p></p></body></html>"
WRITE #1, WriteText$

Help!

-Stu :)

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: QBasic WRITE

Post by frankiebaby » Mon Sep 22, 2003 2:04 am

Your problem is fairly simple. You are using an inappropriate command for what u are doing. Check out the Online help for WRITE and for PRINT #

heres an important part about write

The WRITE # statement, unlike the PRINT # statement, inserts commas between items as they are written to the file. You do not have to put explicit delimiters in the list. A new line is inserted once the last item in the list has been written to the file.

what u should do instead is:

Code: Select all

PRINT "<!DOCTYPE HTML PUBLIC " + CHR$(34) + "-//W3C//DTD HTML 4.01 Transitional//EN" + CHR$(34) + "><html><head>"
the chr$(34) inserts a "

Afrow_UK
Newbie
Posts:8
Joined:Sun Sep 21, 2003 9:36 pm

Re: QBasic WRITE

Post by Afrow_UK » Mon Sep 22, 2003 2:58 am

Thanks!

So PRINT will become write while it sits in OPEN and CLOSE?

Edit: Print #1 works perfectly.
I've been reading a book on QB, which didn't refer to using the PRINT statement for file writes.

-Stu

John_Schofield
Full Member
Posts:36
Joined:Tue Mar 18, 2003 3:04 am
Location:Lancashire, UK
Contact:

Re: QBasic WRITE

Post by John_Schofield » Tue Sep 30, 2003 3:08 am

Just to clarify, you need a routine like this (which I use in my program for the same purpose):
a$ = "C:\race\web\" + LCASE$(fil$) + ".htm": OPEN a$ FOR OUTPUT AS 4

PRINT #4, "<!DOCTYPE HTML PUBLIC "; CHR$(34); "-//W3C//DTD HTML 3.2 Final//EN"; CHR$(34); ">"

PRINT #4, "<HTML>"
PRINT #4, "<HEAD>"

etc...

The print statement sends text output to the named file (you can number it how you want as long as it's not already open - mine just happens to be 4) - characters like "" are special characters and have to be sent as their ascii code rather than the viewed version.

Post Reply