Announcement

Collapse
No announcement yet.

Internal error 51

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

  • Internal error 51

    In a dll for a printer report I get an error 51 in my
    error handler. It doesn't always happen, however.

    I have a dialog that allows the user to choose a a print
    device (among other things) 1,2,3 for LPTn, or C for screen,
    or D for disk file, or W for windows only/network printer.

    Now I do not get the error when I choose C.
    This makes it open a file like "report.txt" then when
    the report is "printed" it does a shell "notepad report.txt"
    This works fine. But if i open the file as "LPT1:" for example
    (user chooses 1) then I get the error 51 although the report
    seems to print ok.

    Since the error routine is not called when the error occurs but
    rather at the end, I'm not sure how to proceed in trying to
    track this down. I can get around it using errclear but would
    rather not have to. Any suggestions. :0

    Thanks



    ------------------
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

  • #2
    Fred --
    I suggest to forgot about DOS-style programming and search BBS by words
    EnumPrinters StartDoc StartPage ...

    ------------------

    Comment


    • #3
      Semen I do use that when they select a windows only printer.
      I wrote a dll for that. It's just that printing to LPT port
      directly is so much faster if they can do it that i wanted
      to leave that option open to them. (my customers)

      ------------------
      Client Writeup for the CPA

      buffs.proboards2.com

      Links Page

      Comment


      • #4
        Buff --

        The PB/DOS and PB/DLL Help Files both say:

        Error 51: A malfunction occurred within the PowerBASIC run-time system.

        But that does not necessarily mean that PB itself malfunctioned. For example, at least in the case of PB/DOS, your program or "external forces" can cause an ERR 51. All you have to do is something like this...

        Code:
        OPEN "MYFILE" FOR OUTPUT AS #1
        PRINT #1,""
        KILL "MYFILE"
        CLOSE #1
        ...and the CLOSE line will (quite understandably) trigger an error. The PB "internals" won't be able to close the file normally.

        I don't know whether or not the meaning of ERR 51 was carried over from PB/DOS to PB/DLL, but IMO it would be worth looking for circumstances where something like OPEN/KILL/CLOSE can happen. It's very easy to do with Windows, since another program (or a network failure, etc.) can affect your program's access to a file while it is open.

        Have you been able to determine exactly which line of code is generating the error?

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>



        [This message has been edited by Eric Pearson (edited July 31, 2000).]
        "Not my circus, not my monkeys."

        Comment


        • #5
          I don't know whether this will help or not, but try using "LPT1" instead of "LPT1:" - the colon may be causing unnecessary problems.

          Typically an Error 51 means that PowerBASIC received an error message (from the O/S) that it does not recognize, so that may be the clue that you need to figure it out.

          I hope this helps.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Eric I had thought originally that a close was causing the
            problem specifically closing the printer file. But then
            I read that the error routine handling allows the program
            to continue rather that stopping like in QB or probably PB3.5
            too. So I wasn't so sure. I do know when the close occurs and
            I am printing to lptn the printer hasn't finished yet.
            And no I havent determined the line where it happens because
            since the program continues and only issues the message at the
            end, how am i to know (unless it's something obvious).
            I guess I could use message boxes in several places to check err
            (if that will work).

            Lance I will try the lpt1 instead also.

            ------------------
            Client Writeup for the CPA

            buffs.proboards2.com

            Links Page

            Comment


            • #7
              Fred --
              1) I think, that it's better to create a text file and to use API CopyFile, for example,
              lResult = CopyFile ("C:\autoexec.bat", "LPT1:", %FALSE)
              lResult (if successful, should be non-zero)
              2) I prefer to use PRN instead of LPTx


              ------------------

              Comment


              • #8
                Thanks Semen I will look at that.

                I took out the CLOSE statement and
                used close #5
                close #6 (data files)
                then closed #15 (printer or text file)
                if it was a text file. that stopped the error 51
                but probably semen's example is a better way to go
                since it should then allow me to close #15 in all cases
                without the error.


                ------------------
                Client Writeup for the CPA

                buffs.proboards2.com

                Links Page

                Comment


                • #9
                  I got the same error code with pb/cc 2.0 using MAILSLOTs:

                  open "\\server\mailslot\xyz" for output as #1
                  :
                  print #1,"abdef..."
                  :
                  close #1 ' triggers error 51

                  errapi is 0 at this time.

                  ------------------

                  Comment


                  • #10
                    Install the default text printer (1st in the selection box)
                    Use this one with plain commands..


                    ------------------
                    [email protected]
                    hellobasic

                    Comment

                    Working...
                    X