output to printer - please help

For issues with communication ports, protocols, etc.
Lee
Posts: 12
Joined: Feb 07, 2006 2:45

output to printer - please help

Post by Lee »

Here is a simple program I need to make an output chart:
  • ' Prg computes & displays % grades
    ' based on number of points missed (y)
    ' PP = points possible on assignment
    ' y = number of points missed by student
    'x for next to increment y (used b/c "STEP .5" command does not work)

    '*** setup ***
    dim x as double
    dim y as double
    dim pp as double
    dim sc as double
    dim total as double
    dim max, min, st as double
    max = 16
    min = .25
    st = .25

    '*** input ***
    input"assignment name";n$
    input "points possible";pp
    cls

    '** ouput and processing **
    ? "Percent grading scale for ";n$
    ? "Points Possible = ";pp
    for x = min to max step st
    sc=(pp-x)
    total=sc/pp
    lprint x, total ' here is the line that does not work!
    next x
    sleep
    end
Yes, I know there are ways to make this code much shorter, but I am interested in using it with beginning programmers. I need the chart as a hardcopy from the program. I do not want to output it to screen and then copy/paste into a word processor etc.

I am on a network where there is a laser printer attached. I can also set the default printer to a desktop printer. However, I really need this to work with the networked laser printer as various students (next semester) will be using boxes on the network and I want them to be able to make output tables on the printer also.

No matter which printer I make the default, I cannot get it to make a hardcopy. The program simply runs, no output is given, and then ends (upon keypress).

Is there someone out there who can modify the output area of my code to make it print on a printer?
Thanks,
Lee
Oz
Posts: 586
Joined: Jul 02, 2005 14:21
Location: Waterloo, Ontario, Canada
Contact:

Post by Oz »

Lprint should do the trick if it's just plain text

for more info, go to the wiki lprint page

Oz~
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@Lee

I believe that this is a bug, problem with "lprint" in fb v.17b. I thought this had been reported previously, but I can't find a ref to it. "lprint" is printing to stdout.

Your code works as-is using fb v.16b.
Fails fb17b "-lang deprecated" (prints to stdout)
Fails fb17b with code corrections (prints to stdout)

"lprint" is the problem, not your code, if you are using a flavor of fb v.17b. You are using.. what version?
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

The code works for me, prints to the default printer, v0.17b-july30, Windows 2000 SP4.
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@MichaelW

I'm using 17b compiled from September 2nd (approx) CVS. I know better than to use interim compiles, and now I miss them when they're gone. I shouldn't attempt to test/answer questions using an interim compile.

This code:

Code: Select all

lprint "Now is the time"
sleep
prints to the screen/stdout on Windows using 9/2 (approx) compile.

@Lee

When you say this:

lprint x, total ' here is the line that does not work!

what do you mean by "does not work!"? Sounds like an obvious question, but please provide a specific answer.

There is one problem in your code. This line:

dim max, min, st as double

only dims st as double, max and min default to integer types. This should be:

dim as double max, min, st

but your code still runs and lprints as-is (fb versions <= 17b 7/30).

You were having problems with "lprint" in February 2006 - did this single line of code:

lprint "Hello World!"

ever work for you?
coderJeff
Site Admin
Posts: 4386
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

Yeah, that's a bug introduced when -lang options were added. Fixed in CVS.

-lang deprecated or -lang qb must be used with LPRINT.
Lee
Posts: 12
Joined: Feb 07, 2006 2:45

output to printer - please help!

Post by Lee »

Thanks for all of the tips! I am sorry I wasunable to get back to this forum to get them all until today!

Zippy said:
SNIP
I believe that this is a bug, problem with "lprint" in fb v.17b. I thought this had been reported previously, but I can't find a ref to it. "lprint" is printing to stdout.
SNIP
I copied this from the HELP/ABOUT menu item:

FBIde 0.4.2
an open-source IDE for the FreeBASIC compiler
(www.freebasic.net)
made using c++ with wxWidgets and the scintilla text control

is the same bug still in this version?

Zippy also asked:
(about the following line of my code)

lprint x, total ' here is the line that does not work!
SNIP
what do you mean by "does not work!"? Sounds like an obvious question, but please provide a specific answer.
SNIP

In other words, the printer does not print anything. For that matter - nothing happens at all. When I then hit any key, the program ends.

I was also asked:
SNIP
You were having problems with "lprint" in February 2006 - did this single line of code:

lprint "Hello World!"

ever work for you?

SNIP


This line has never worked for me!

I just got a chance to download the latest version of FreeBASIC and am hoping it will correct the problem.

Thanks for the help - suggestions - and patience with my not being around a computer to follow this up!

If it does not work - I will post again.

Thanks also for the correction in my oversight of the dim satament.

Lee


SNIP
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@Lee

An upgrade may cure your ills.

A brief digression:

This: "FBIde 0.4.2" is the version of the IDE, the Integrated Development Environment you are using. An IDE in this case is a text editor (like "notepad", but this one is named "FBIde"), allowing you to compose + save + retrieve your BASIC source code. It can also help you to compile and execute your program, it does this by passing your code to the FreeBASIC compiler. This process, compile and execute, can be done entirely from commandline/console - the IDE is not necessary but it is helpful. That's a brief explanation..

Use this code to get the version of the FreeBASIC compiler (may not work with versions <0.15..):

Code: Select all

print __FB_VERSION__
sleep
end
FBIde 0.4.2 was packaged with FreeBASIC v.0.14 - "lprint" was not supported until v.0.15. An upgrade may cure your ills.
Lee
Posts: 12
Joined: Feb 07, 2006 2:45

Post by Lee »

Zippy,
I enetered the following:

Code: Select all

Print __FB_VERSION__
Sleep
End
When it ran, it did, indeed, say 0.14. So I upgraded and now it says 0.15

I then ran this program:

Code: Select all

Lprint "Hello World!"
Sleep
All I still get is the output window and a blinking cursor.

I set the default printer to a desktop one (instead of the one on the network) to see what would happen. The same results - nada.

Any ideas?

Thanks,
Lee
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@Lee

lprint does not close the printer device (handle) after the statement concludes. The translation is that nothing will print using lprint until you explicitly close the lprint internal file handle or your program ends/terminates normally.

So this code:

Code: Select all

lprint "Hello World!"
sleep
will-not-can-not print until you fall through the sleep (.. press a key other than ctrl+c or ctrl+Break), thus when your program ends/exits.

Please try this code, with your default printer set to your desktop printer (and confirm that you can print to it from any other application):

Code: Select all

'tested using fb v0.15b
lprint "Hello World!"
lprint chr(12)
close -1
print "Done, sleeping"
sleep
end
Some printers require a formfeed sequence, that's the "lprint chr(12)" in the code. You will know if you don't need this if 2 pages leave your printer (2nd blank). This: "close -1" forces the lprint file handle to close.

Please try the bit of code above. Upgrading to fb v0.15b was a good thing, but you are still a rev behind - now almost 2 revs behind. Eh, let's get this lprint issue resolved before you upgrade again..

If you have success, let us know. If you don't have success, return with this info:

1. What version/flavor of Windows are you using?
2. Make/model of network printer
3. Make/model of desktop printer

Cheers, Z.
Lee
Posts: 12
Joined: Feb 07, 2006 2:45

output to printer - please help

Post by Lee »

This program does not work either:

Code: Select all

'tested using fb v0.15b
Lprint "Hello World!"
Lprint Chr(12)
Close -1
Print "Done, sleeping"
Sleep
End
I copy/pasted into FREEBASIC and hit F5 - nada. The output screen opens displays, "Done sleeping" and a blinking cursor appears underneath this.

For the fun of it - I set the default to the laser printer w/same results.

Here are the specs asked for:
The system tells me it is Windows XP Professional Version 2002
Service Pack 2

It is running on a Dell DIMENSION DIM2300
Intel
Pentium 4 CPU 1.80 GHz
1.79 GHz, 256 MB RAM

The destop printer is an HP PSC 2355xi all-in-one printer - scanner - copier

The Networked laser printer is an HP color laserjet 4600

Thanks again!

Lee
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@Lee

You don't have a desktop "printer", you have a multi-function graphics device.. And the network printer is no less complex. lprint passes essentially plain text (ascii) to the device attached to lpt1 (printer port 1 on your computer), or if that doesn't work it attempts to print to the default system printer. Your desktop printer may be attached via USB which may be another issue (lprint might never fail over). Neither of your printers will understand the simple output from lprint.

There may still be a way you can print from a FreeBASIC program, but it would require the latest version of fb (v.17b test-release with a recent update from CVS). Then this code might work:

Code: Select all

Open Lpt "LPT:TITLE=Test,EMU=TTY" For Output  As #1
Print #1, "Hello World!" 
Close #1
print "Done, Sleeping..."
sleep
But even that might not work, and if it did the output is not pretty.

There are ways to print using the WinAPI directly, there is some code around the forums here for printing graphics (everything printed by Windows is a "graphic", per se), I'm not seeing that code ATM. The API is well-beyond the ease of lprint and open Lpt.

Perhaps someone else has other ideas?
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

@Zippy:

I have a Lexmark 7300 Series Printer,Faxer,Scanner,Copier, and puggled in to my laptop with USB and your first example works. Thanks for this.

Code: Select all

'tested using fb v0.15b
Lprint "Hello World!"
Lprint Chr(12)
Close -1
Print "Done, sleeping"
Sleep
End
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@axipher

You are using a current version of fb (noted from another post), that's prob why it works for you. Jeff fixed all this in June '06 (> v.16b). Good that it works with USB (fails over correctly).

Code almost verbatim from wiki, albeit wiki not clear that close -1 will cause/force an immediate print (if lprint works with your print config).
Lee
Posts: 12
Joined: Feb 07, 2006 2:45

ouput to printer - please help

Post by Lee »

Thanks for all of the help. I really do appreciate your time and effort in helping me with this problem.

I need a way that my students can use FreeBASIC at their own computer and put their output to the networked laser printer. The output would be simple sentences and text charts - nothing fancy. It is amazing how complex a thing this is!

There are times I sure miss the good old days of programming! It is amazing with all of our technological advantages/leaps/advancements from the 80's, how very complex it can be just to do a simple task!

The whole purpose for training these students in a grammatically simple language is to teach them structuring whilst simultaneously increasing their reasoning abilities (and them having fun while doing it). I guess I will have to get a simple printer and connect it to the network (if possible).

Maybe future versions of FreeBASIC will be able communicate with currently available "more complex" devices. I doubt that manufacturers will make their printers+ comprehend simple acsii.

Lee
Post Reply