Announcement

Collapse
No announcement yet.

Using OPEN "SCRN:" FOR OUTPUT AS #1

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mike Hounsome
    replied
    oops, for LPRINT read XPRINT in the comment.

    Leave a comment:


  • Mike Hounsome
    replied
    Yes Michael, formatting and output as separate statements is probably the way to go. But that involves a complete re-write of the program. I'm sure that I will do that as I get better at PBCC6 but in the mean time, just to get me up and running, here is my modification of your model:
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN () AS LONG
       LOCAL hCons AS DWORD,f$,fout$,i&
    
    REM **************************** ask the question *****************************
    
    l14:
        COLOR 0,7
        INPUT " Do you want to output to screen (s), printer (p), or disk (d) "; f$
    
    REM **************************** make the choice ******************************
    
        IF f$ = "S" OR f$ = "s" THEN
            hCons = GetStdHandle (%STD_OUTPUT_HANDLE)
            OPEN  HANDLE    hCons FOR OUTPUT AS #2
    
        ELSEIF f$ = "P" OR f$ = "p" THEN
            PRINT
            PRINT "I'm still trying to work out how to direct #2 to a printer."
            PRINT "In the mean time I can only repeat all 220 lines, replacing"
            PRINT "all the PRINT# statements with XPRINT ones.
            XPRINT ATTACH DEFAULT
            XPRINT "hello" 'plus 220 lines of code including 73 LPRINT statements
            XPRINT FORMFEED
            XPRINT CLOSE
    
        ELSEIF f$ = "D" OR f$ = "d" THEN
            INPUT"What do you want to call the file (include path) ";fout$
            PRINT
            PRINT"The output will be written to the file '";fout$;"'"
            OPEN fout$ FOR OUTPUT AS #2
    
        ELSE
            COLOR 6,7
            PRINT
            PRINT"                     answer with 's' or 'p' or 'd'
            PRINT
            WAITKEY$
            CLS
            GOTO l14
        END IF
    
    REM ************************ output the results *******************************
    
        PRINT #2,"hello" 'plus 220 lines of code including 73 PRINT# statements
        CLOSE #2
        WAITKEY$
    END FUNCTION
    This works perfectly for the screen and for a file but I still can't see a way of directing #2 to a printer. It seems as though I have to repeat all the output statements changing PRINT#2 to XPRINT. This would work but it would add another 220 lines of code. I'm sure that there must be a better way of doing it. I'll persevere until I find the correct way to do it. Thanks for your input.

    Leave a comment:


  • Michael Mattias
    replied
    Yea, verily, thou art now paying for thy bad habits of the past, putting thy formatting code inline with thy output statements, instead of performing thy formatting and output in separate statements.

    Leave a comment:


  • Mike Hounsome
    replied
    Thanks, Michael for that. It will take a bit of time to digest but my immediate thought is that it would be fine if I had only 'stext' to output. In reality there are possibly 100 lines of text and numbers to output with complex formatting. This is the reason I did it the way I did - I could have just one block of PRINT#2 commands (and PRINT#2 USING$) and they would go wherever I chose to send them. I'm sure there will be a way to do a similar thing using your idea as a basis. It just means thinking in a different way. Thanks.

    Leave a comment:


  • Michael Mattias
    replied
    I'll bet you are right now wishing you had isolated the writing of the output into a separate procedure in Ye Olde Turbo Basice program...

    Leave a comment:


  • Michael Mattias
    replied
    >thing in PBCC6 I need rather a lot of code.

    You do? I don't:

    Code:
    %OUTPUT_SCREEN = 1&
    %OUTPUT_FILE     =  2& 
    %OUTPUT_PRINTER = 4& 
    
    FUNCTION ManyOut _ 
        (sText AS STRING, BYVAL outMode AS LONG, OPT hFile AS LONG) AS LONG
    
      IF ISTRUE (Outmode AND %OUTPUT_SCREEN) THEN 
           ? stext 
      END IF 
      IF ISTRUE (Outmode AND %OUTPUT_DISK) THEN 
           PRINT #hFile,  stext 
      END IF 
     IF ISTRUE (outmode AND %OUTPUT_PRINTER) THEN 
         Lprint  sText
     END IF 
    
    END FUNCTION
    As written supports multiple simultaneous outputs. Tweak as desired.

    MCM

    Leave a comment:


  • Mike Hounsome
    replied
    I know that this an old (dead?) thread but I'm in a similar situation in that I'm translating my old TurboBasic programs into PBCC6. In TurboBasic I could do the following:
    Code:
    l14:
    INPUT "       Do you want to output to screen (s), printer (p), or disk (d)"; f$
    IF f$ = "S" OR f$ = "s" THEN
        f$ = "SCRN:"
    ELSEIF f$ = "P" OR f$ = "p" THEN
        f$ = "LPT1:"
    ELSEIF f$ = "D" OR f$ = "d" THEN
        INPUT"       What do you want to call the file (include path)";fout$
        f$ = fout$
        PRINT
        PRINT"     The output will be written to the file '";f$;"'"
        PRINT
    ELSE
        COLOR 6,7
        PRINT"                     answer with 's' or 'p' or 'd'
            PRINT
        CLS
        GOTO l14
    END IF
    OPEN f$ FOR OUTPUT AS #2 
    etc.......
    and it all worked fine. It seems that to do the same thing in PBCC6 I need rather a lot of code. Did you ever sort it out, Scott? Did Fred's solution satisfy you?

    Leave a comment:


  • Michael Mattias
    replied
    Cool.

    Fringe benefit... if output is redirected from command line ...
    Code:
    C:\MYFOLDER> start /C myprog.exe >anotherfile
    .. console output should be redirected, too.

    (You MUST use "START" on XP, known bug in Win/XP!)

    But if you already have provision for file output, that's probably not going to be necessary. Maybe someone else can use this idea for something.


    MCM

    Leave a comment:


  • Fred Buffington
    replied
    Very good Michael - it does seem to work in cc4,

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN () AS LONG
       LOCAL hCons AS DWORD,dv$
       dv$="SCRN:"
       IF dv$="SCRN:" THEN
         hCons            = GetStdHandle (%STD_OUTPUT_HANDLE)
         OPEN  HANDLE    hCons FOR OUTPUT AS #1
       ELSEIF dv$="LPT1:" THEN
           'do open printer port here
       ELSE 'assume file
          OPEN dv$ FOR OUTPUT AS #1
       END IF
       PRINT #1,"hello"
       CLOSE #1
       WAITKEY$
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    ????
    Code:
      hCons            = GetStdHandle (%STD_OUTPUT_HANDLE) 
      OPEN  HANDLE    hCons FOR OUTPUT AS #1
    This may not work but if nothing else does it's worth a try.

    Leave a comment:


  • Mel Bishop
    replied
    As noted in Fred's reply, dump the colon in "SCRN:" and your program should work as advertised.

    Leave a comment:


  • Fred Buffington
    replied
    As far as the LPT1. this may work if you have a printer actually attached to
    the LPT1 port. Failing that, you could use a network printer and use the NET USE command syntax in a bat file (for example) to make the program think it's
    going to LPT1 when really it's going to the network printer. That said, this will work for DOS programs and may work for pbcc but I have not tested that.

    The scrn: I'm not sure, and I am familiar with that kind of usage, having used it in QB programs for years.

    I Will see what I can come up with.

    And you should have no trouble, as you said, with printing to the file.

    A possible workaround for the scrn: might be something like below
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL LL$,dv$,FF%
        dv$="SCRN"
        OPEN dv$ FOR OUTPUT AS #1
        PRINT #1,"Hello"
        CLOSE #1
        IF dv$="SCRN" THEN GOSUB showit
        WAITKEY$
        EXIT FUNCTION
    showit:
        OPEN "SCRN" FOR INPUT AS #1
        WHILE NOT EOF(1)
        
          LINE INPUT #1,LL$
          IF INSTR(LL$,CHR$(12)) THEN
            FF%=INSTR(LL$,CHR$(12))
            IF FF%>1 THEN PRINT MID$(LL$,1,FF%-1);
            WAITKEY$
            CLS
          ELSE
            PRINT LL$
          END IF
        WEND
        CLOSE #1
        KILL dv$
        RETURN
    
    END FUNCTION
    Last edited by Fred Buffington; 2 Sep 2008, 10:32 PM.

    Leave a comment:


  • Scott Butler
    started a topic Using OPEN "SCRN:" FOR OUTPUT AS #1

    Using OPEN "SCRN:" FOR OUTPUT AS #1

    I am translating an old qbasic program and it uses the OPEN "SCRN:" FOR OUTPUT AS #1 statement to write to the screen, OPEN "LPT1:" FOR OUTPUT AS #1 for the printer, and OPEN FILE1$ FOR OUTPUT AS #1 for a file. This is actually nice as it abstracts the output from the output medium. However, it does not seem to work for the screen (I have not tested the printer or file output). My guess is that this code will only work for file output and not screen or printer. Can anyone confirm that the first two open statements are not supported in PBCC 4? Also, any ideas on how to abstract the output from the medium would be much appreciated.

    Scott
Working...
X