Silverfrost Forums

Welcome to our forums

cannot connect to a file!

16 Apr 2012 9:30 #10006

hello guys! pls how can i connect a source code to a file? have this source code below but cannot connect to the file even when i have it locally. thanks

! a dummy program implicit none real:: sum, avg, score1, score2, score3 integer:: counter open(unit=5, file='in_scr.txt', status='old') open(unit=6, file='out_scr.txt', status='new') do 10 counter=1,3 sum=0.0 read(5,20)score1, score2, score3 sum=score1+score2+score3 avg=sum/3 write(6,30)counter, score1, score2, score3 write(6,40)sum, avg 10 continue stop 20 format(3(f5.2, 2x)) 30 format(//, 'student', i2,/, 'score1', 2x, f5.2,/, 'score2', 2x, f5.2,/, 'score3', 2x, f5.2) 40 format(/, 'total and average =', 2x, 2(f6.2, 2x), 'respectively', //)

end

16 Apr 2012 10:35 #10008

Use different UNIT numbers. 5 and 6 are reserved. Use values that are greater than 6.

16 Apr 2012 5:10 #10014

Here you go.

! a dummy program
implicit none
real:: sum, avg, score1, score2, score3
integer:: counter
open(unit=10, file='in_scr.txt', status='old')
open(unit=11, file='out_scr.txt', status='new')
do 10 counter=1,3
sum=0.0
read(10,20)score1, score2, score3
sum=score1+score2+score3
avg=sum/3
write(11,40)sum, avg
write(11,30)counter, score1, score2, score3
10 continue
stop
20 format(3(f5.2, 2x))
30 format(//, 'student', i2,/, 'score1', 2x, f5.2,/, 'score2', 2x, f5.2,/, 'score3', 2x, f5.2)
40 format(/, 'total and average =', 2x, 2(f6.2, 2x), 'respectively', //)

end
18 May 2012 2:39 #10185

The function 'open_printer@' returns a value of '1' which indicates the printer was opened but when trying to write to it I get the error not opened. If you use 'printer_open@' using WINIO@ everything works just fine. I would like to use the first example since it would not require additional interaction from the user. Please let me know what I need to do.


FIRST EXAMPLE WHICH DOESN'T WORK.......................


winapp
program testprint02
INCLUDE <windows.ins>
INTEGER HANDLE
HANDLE = 7

! ! ! i=(OPEN_PRINTER@(HANDLE)) if (i .eq. 1) then write (HANDLE,10) i 10 format (1x,i5,10x,'testprint02') endif close (7) END


SECOND EXAMPLE WHICH WORKS FINE.....................


winapp
program testprint01
INCLUDE <windows.ins>	
EXTERNAL printer

! ! ! i=winio@('Press this button to print a page: %nl&') i=winio@('%^bt[Print]&','PRINTER_OPEN',7,printer) i=winio@('%2nl%cn%bt[OK]') call testit close (7) END ! c----- INTEGER FUNCTION printer() write(7,15)'Hello' 15 format(1x,a5) do i = 1 , 10 print 10, i 10 format (5X,i5) write (7,10) i end do

! CLOSE(7) printer=2 END

subroutine testit print *,'subroutine testit' write (7,20) 20 format (1x,'subroutine testit')

end

18 May 2012 7:48 #10186

Your first example doesn't work for 2 reasons.

  1. Open_PRINTER@ opens a printer for output of graphics, not Fortran formatted text output. You would need to use graphics subroutines to write to it.
  2. Handle isn't a unit number, so it cannot be used where you used it in a WRITE statement.

Assuming that you have a standard printer connected via a parallel port (increasingly, printers are Windows-only and computers don't have parallel ports!) then you could try:

      OPEN (7, FILE='LPT:')

(and sometimes LPT1: works, or maybe PRN: - you would need to experiment).

If you do want to use the WINIO@ Clearwin approach, but you don't want the user to press a button, then use %sc instead of %bt.

Eddie

18 May 2012 8:45 #10189

I'm not quite sure I did this correctly but I still get a button to push (click on the (X)), no button and I get the printer to work. This is a windows printer. I don't think anyone uses LPT1 or PRN any more, except the real old stuff.

I commented out 2 of the WINIO calls and changed the middle one to %sc where the %bt was before and it still produces a window box which you have to click on the 'X' to get the printer output.

winapp
             program testprint01
INCLUDE <windows.ins>	
EXTERNAL printer

! ! ! ! i=winio@('Press this button to print a page: %nl&') i=winio@('%sc[Ready to Print?]','PRINTER_OPEN',7,printer) ! i=winio@('%2nl%cn%bt[OK]') call testit close (7) END ! c----- INTEGER FUNCTION printer() write(7,15)'Hello' 15 format(1x,a5) do i = 1 , 10 print 10, i 10 format (5X,i5) write (7,10) i end do

! CLOSE(7) printer=2 END

subroutine testit print *,'subroutine testit' write (7,20) 20 format (1x,'subroutine testit')

end

18 May 2012 9:19 #10191

Printing starts after you select a printer. Rather than CLOSE(7) I suggest

I = CLOSE_PRINTER@ (0)

or

CALL NEW_PAGE@

Otherwise output waits until you close the application with the red X (close box). The application would close automatically if you had returned

printer=0

That old LPT: stuff still works if the hardware supports it.

Eddie

19 May 2012 2:18 #10192

This is great! I used 'printer = 0' with no other change and the printer printed. How ever a box was still created on the screen which went away after printing was finished with out me clicking on the 'red X'. It would be nice if there was no box.

Thank you very much............

19 May 2012 11:49 #10193

You want no box (no window)? In that case you need to make it invisible. This needs 2 things: firstly the window itself has to be invisible, and also secondly you don't want it to appear on the taskbar either, so use the code:

%ww[invisible,toolwindow]

and you won't see it anywhere!

Eddie

19 May 2012 2:38 #10194

This is exactly what I wanted. Nice job!

Please login to reply.