If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
4 posts • Page 1 of 1
We use qbasic to do some engineering for us and at the end of the program it asks to print. i would like instead of printing to save it or send it to word so i can save the file and print when i want. i would love to send someone the program so they can tell me how to do this.
- Patz QuickBASIC Creations
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
If I understand you correctly, the program already prints some results. You didn't say whether it prints to the screen on to the printer, but it's basically the same thing.boominz28 wrote:We use qbasic to do some engineering for us and at the end of the program it asks to print. i would like instead of printing to save it or send it to word so i can save the file and print when i want. i would love to send someone the program so they can tell me how to do this.
To print these results to a file, I'll give you some simple ideas.
1) Near the top of the program, before the code for the main program starts, issue an OPEN statement for the file that will contain the results, like so:
OPEN "RESULTS.TXT" FOR APPEND AS #6
I chose a file extension of .TXT to make it simpler to import the file into NOTEPAD or WORD.
I chose OPEN FOR APPEND so that you can run the program several times and see the results of these several runs, one right after the other. To identify these separate runs with a date and time, right after the OPEN you can print the date and time to the results file as follows:
PRINT #6,DATE$;" ";TIME$
2) Now, find where in the program it is now printing results. You can either leave the existing printing as is, or you can replace it. Take each existing PRINT or LPRINT statement and copy it, substituting the PRINT or LPRINT part with PRINT #6,
3) That's it. You really don't need to close file #6. It will be closed automatically when your program terminates with an END or SYSTEM.
You now have a running backup of your results in the RESULTS.TXT file which you can save, or load into NOTEPAD or WORD. When you don't want anymore results added on the end of the file, just delete the RESULTS.TXT file before running the program.