Announcement

Collapse
No announcement yet.

Error Code

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

  • Error Code

    I've got a really anoying bug.

    I get an error code 52

    Error 52: Bad file name or number

    The file number you gave in a file statement doesn't match one given
    in an OPEN statement, or the file number may be out of the valid range
    of file numbers.

    OPEN NWD$ + "PLU.DAT" for RANDOM Access READ WRITE Lock READ WRITE as #30 len = 140

    What conditions cause error 52??


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

  • #2
    Steve,

    Gotta see some more code. Like the GET statement.

    Usually you'll have less problems if you assing a variable or
    constant as the file number instead of using a literal. At any
    rate it's a good habit to get into.

    DIM FileNo AS LOCAL LONG

    FileNo = FREEFILE ' This is safest
    OPEN "MyFile.dat" FOR BINARY AS #FileNo
    GET #FileNo, , Whatever
    CLOSE #FileNo



    ------------------
    C'ya
    Don
    don at DASoftVSS dot com
    C'ya
    Don

    http://www.ImagesBy.me

    Comment


    • #3
      The program is very big!

      It seems to me that the error code does not apply to the statement or am I mistaken?


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

      Comment


      • #4
        Do you have too many files open at one time? You may have to increase the files= statement in your config.sys to allow for more file handles.

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

        Comment


        • #5
          >It seems to me that the error code does not apply to the statement or am I mistaken?

          Under PB/DOS, you can be sure... Compile/Find Error (from the "pc:nnnn" you get when the program terminates, just enter the 'nnnn').

          Also, what is the value of NWD$ at point of call? Could be you are using an illegal file name. (e.g., something with a * or / or ? in it)


          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            NWD$ is either empty or "Z:"

            I'm running the program under windows 2000 DOS box

            What's the default for the number of files open? I dont think that I'm opening more than 6 at a time.

            Also checked to see thet the error address I'm entering is correct using the compile find error menu.



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

            Comment


            • #7
              > NWD$ is either empty or "Z:"

              That's your problem, then.

              Your open statement specifies the filename as NWD$ + "PLU.DAT".

              Z:PLU.DAT is an illegal filename.

              Z:\PLU.DAT is a legal filename that will read and write PLU.DAT on drive Z:

              Specify your filename in your open statement as NWD$ + "\PLU.DAT" and all will be well (assuming that you really want to write to drive Z, that is.)

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

              Comment


              • #8
                Hmmm?

                There is nothing illegal about "Z:PLU.DAT" although, the error 52 does
                suggest that the default directory on drive Z: is not what Steve thinks
                it is.

                CHDIR.

                ------------------
                Tom Hanlin, PowerBASIC Staff
                Opinions expressed may not be those of my employer or myself

                Comment


                • #9
                  > There is nothing illegal about "Z:PLU.DAT"

                  D'uh. You're right, of course; it would write into whatever the current default directory on drive Z: happens to be.

                  That takes a good deal more on faith than I would want to myself, though. It's best to always specify the full path of any file.

                  In my humble opinion, of course.

                  ------------------
                  PB/DOS 3.5 on Fedora Linux

                  Comment


                  • #10
                    The reference to "Z lu.dat" is called without problem all over the code.

                    I've had this before when an error does not match the statement. Usually caused by some other sort of error elsewhere in the code.



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

                    Comment


                    • #11
                      Possibly your file number "#30" exceeds the number of file handles (set by the FILES= directive in CONFIG.SYS) available in DOS? Try using FREEFILE instead.

                      ------------------
                      If you try to make something idiot-proof, someone will invent a better idiot.
                      If you try to make something idiot-proof, someone will invent a better idiot.

                      Comment


                      • #12
                        No, that cant be the problem. I'm using #89 & #101

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

                        Comment


                        • #13
                          You can increase the number of files that DOS will handle, at least
                          in the DOS variations I've known. If you are running this in a pure
                          DOS box, it is set in the CONFIG.SYS file per my recall. I've been
                          running OS/2 now since version 2.1 and in the case of DOS under OS/2,
                          that is set in the CONFIG.SYS file during the boot run for OS/2 as
                          a generalized case. And, since you can have a different environment
                          for each and every instance of a DOS-VDM session under OS/2, each
                          and every different one of them can have a different number for the
                          maximum number of files each session is to use.

                          In the OS/2 desktop operation, each DOS-VDM session has a complete setup
                          folder for it. In it are what are called SESSION PARAMETERS. In that
                          sub-folder are a complete panel of the things that are DOS control
                          issues from the complete management of upper memory and video controls
                          for the session - to the number of allowable file handles max is to be
                          enabled for that session.

                          A long time ago I standardized on FILES=50 for all my normal DOS
                          sessions in OS/2, even using that for a standard parameter direct in
                          the OS/2 CONFIG.SYS file for each box. It is true that there are
                          errors that get thrown in PB 3.5 for DOS running under OS/2 if the
                          file handle count exceeds the allowable total. But as has been
                          suggested, the safest thing is to use the FREEFILE technique. At
                          that point the error, if it is an issue of maxed out session, comes
                          back right there where you can trap it.

                          A suggestion .. Each time you do a FREEFILE use in PB for DOS, and
                          then as well for the OPEN statement that will follow it, be sure to
                          use a LINE NUMBER for that line. In that the error trap tools for
                          PB are keyed to numeric line number errors, it makes it a lot easier
                          to figure out which exact line is giving you errors come run time
                          and debugging an application. The same technique is, as far as I know,
                          a smart idea for file I/O command lines too. Much easier to get the
                          ERR line number that takes you right to the messup, than trying to
                          single step through a whole program to find out the bad line.

                          Hope this helps.



                          ------------------
                          Mike Luther
                          [email protected]
                          Mike Luther
                          [email protected]

                          Comment


                          • #14
                            Have you considered setting your Lastdrive setting in Config.sys.
                            As I recall, in order to access a drive value such as Z: you would
                            have to have the following line in your Config.sys

                            Lastdrive=z

                            The MSDOS help on Lastdrive reveals the following info:

                            Specifies the maximum number of drives you can access. You can use this
                            command only in your CONFIG.SYS file.

                            The value you specify represents the last valid drive MS-DOS is to
                            recognize.

                            Comment


                            • #15
                              Possibly your file number "#30" exceeds the number of file handles (set by the FILES= directive in CONFIG.SYS) available in DOS? Try using FREEFILE instead
                              The file number has nothing to do with number of files possible. Only
                              if you have 1, 2,3...29, 30 total files open. You can use any number, as long
                              as each OPEN uses a unused number, and they do not have to be in
                              order, but as others have stated, it is best to use a variable and
                              assign it with FREEFILE.


                              ------------------
                              Barry

                              Comment

                              Working...
                              X