AboutAlex Barry Expertise I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.
Experience Hobby programming since 2000
I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++
Question QUESTION: Hi Alex,I've made quite a lot of programs in QB,they still run as EXE prog.in XP & Vista but since USB printers no
longer seem to understand DOS I can't get a print-out on
paper. Do you know of any routine that would work like
"PrtScrn" that I could call from anywhere in the prog.?
Thanks and greetings from Antwerp. L.
ANSWER: Hi, Laurent,
Yes, it is true, DOS has some trouble communicating with USB printers, but there is a handy trick you can use. First, make sure anything you print on the screen also gets printed into a file. Here is an easy way of doing that:
DECLARE SUB Print2( text AS STRING, fileHandle AS INTEGER )
DIM f AS INTEGER
f = FREEFILE
OPEN "tmp.txt" FOR RANDOM AS #f
' Instead of using: PRINT "text", now do Print2 "text", f
Print2 "This is a test", f
CLOSE #f
END
SUB Print2( text AS STRING, fileHandle AS INTEGER )
PRINT text
PRINT #fileHandle, text
END SUB
Now, after you have that, here is what I would do. Note, this ONLY works for TEXT...if you are drawing graphics
So, in the part of the code that looks like this:
CLOSE #f
END
Inbetween that, put this:
SHELL "notepad.exe /P tmp.txt"
This opens and prints it through windows' notepad program. This is a bit of a cheap hack way of doing it, but it works, and it will use Windows' printer-usb drivers, so you won't have any problems.
I hope that helps,
-Alex
---------- FOLLOW-UP ----------
QUESTION: hi, Alex,
what I really wanted was a replacement for the following
routine that I used so far : GOSUB 6000
6000' Outprintroutine
FOR V = 1 TO 18
FOR H = 1 TO 80
LPRINT CHR$(SCREEN(V, h));
NEXT H
NEXT V
RETURN
Which did the trick quite well, as long as one uses the PRN
port. Any suggestions ? Greetings. Laurent
Answer So, if your question is how to make that code work with a usb printer:
6000
DIM toprint AS STRING
DIM ascii AS INTEGER
DIM x AS INTEGER
FOR V = 1 TO 18
FOR H = 1 TO 80
ascii = SCREEN( V, H )
IF ascii <> 0 THEN
toprint = toprint + CHR$( ascii )
END IF
NEXT H
toprint = toprint + CHR$( 13 )
NEXT V
x = FREEFILE
OPEN "tmp.txt" FOR OUTPUT AS #x
PRINT #x, toprint
CLOSE #x
SHELL "notepad /p tmp.txt"
KILL "tmp.txt"
That should work on anything from windows95 all the way to vista