Announcement

Collapse
No announcement yet.

ERR weirdness

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

  • ERR weirdness

    Howdy,

    I'm getting different values from the ERR function, depending on how it's used. For example:

    FILECOPY file1, file2

    sets ERR to 183 if 'file2' exists (listed in WINAPI.INC as "File exists"). If I try and test for it, it fails:

    FILECOPY file1, file 2
    IF ERR = 183 THEN
    ...Alert the user...
    END IF

    But the IF statement evaluates FALSE. Huh??? Even in the debugger the ERR value is 183.

    However, if I assign ERR to a variable and try again, it turns out that ERR is also reporting 75! Like so:

    LOCAL lErrorCode AS LONG, lApiError as LONG
    FILECOPY file1, file 2
    lErrorCode = ERR
    lApiError = ERRAPI
    IF lErrorCode = 75 THEN
    ...Alert the user...
    END IF

    Now the 'lErrorCode' variable is 75 and the 'lApiError' variable is 183, as they should be, so the IF statement evaluates TRUE and everything is correct. I don't understand; shouldn't the ERR and ERRAPI functions return the correct values without having to assign them to a variable?

    Thanks,



    -------------
    ---
    Mark Newman
    Mark Newman

  • #2
    Hello,

    The ERR system variable values are described under the help file in this location:

    Reference Guide -> Error Codes -> Error Codes

    This has a complete list of the PB run time errors, and “File Exists” is not one of them.

    Also, the help file states for the FILECOPY statement that: “If the destination file already exists, it will be overwritten.” Thus the FILECOPY statement doesn’t return any errors if the file already exists.

    What I would do is check for the file your self before the file copy using a generic function like this:

    Code:
    FUNCTION FileNotExists_Or_Overwrite (pFileName AS STRING) AS LONG
        IF DIR$(pFileName) <> "" THEN
            IF MSGBOX("Do you wish to overwrite the file " _
            + pFileName + "?", %MB_YESNO, "Copy File") _
            = %IDYES THEN
                FUNCTION = %True
            ELSE
                FUNCTION = %False
            END IF
        ELSE
            FUNCTION = %True
        END IF
    END FUNCTION
    Colin Schmidt

    ------------------
    Colin Schmidt & James Duffy, Praxis Enterprises, Canada

    Comment


    • #3
      Thanks for the reply; looking back at my post I may have focused too much on the FILECOPY aspect, which really isn't the problem. My problem is that after the FILECOPY completes (and correctly overwrites the destination file, which is what I want), the ERR value is 183. The docs say that isn't a valid number for ERR, however it is defined in WINAPI32.INC as:

      %ERROR_ALREADY_EXISTS = 183&

      Okay, fine, but that should be reflected in the ERRAPI function, not ERR.

      But when I assign variables to ERR and ERRAPI:

      LongVar1& = ERR
      LongVar2& = ERRAPI

      The correct values are in the variables: LongVar1& = 75 (path/file access error), LongVar2& = 183 (already exists). The big issue is why do I have to assign the ERR and ERRAPI system variables to local variables to get the correct values?

      My guess right now is that my system (NT4/SP6, Pent III/400, PB6, VB6 SP3, Office 2K) is somehow at fault, but I wanted to see if anyone might have seen this or have an explanation.

      Hope this is a better explanation!


      ------------------
      Mark Newman

      [This message has been edited by Mark Newman (edited March 20, 2000).]
      Mark Newman

      Comment


      • #4
        Hello,

        I hope this helps then. When I run this with the two files c:\a.a and c:\b.b already existing I don't get any error messages what so ever. I am running Win98SE.

        Code:
        #COMPILE EXE
        
        FUNCTION PBMAIN
            LOCAL lerr AS LONG
            LOCAL lerrapi AS LONG
            'So that we know for sure what directory we are working in
            CHDIR "c:\"
            FILECOPY "a.a", "b.b"
            MSGBOX STR$(ERR)
            MSGBOX STR$(ERRAPI)
            
            lerr = ERR
            lerrapi = ERRAPI
            
            MSGBOX STR$(ERR)
            MSGBOX STR$(ERRAPI)
            MSGBOX STR$(lerr)
            MSGBOX STR$(lerrapi)
            
        END FUNCTION
        Colin Schmidt

        ------------------
        Colin Schmidt & James Duffy, Praxis Enterprises, Canada

        Comment


        • #5
          Colin --

          On NT4 I see errors 75 and 183. On 98 I see zero and zero.

          -- Eric

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



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

          Comment


          • #6
            It's a bug in PowerBASIC when FileCopy is used in Windows NT.

            Windows NT returns the error 183 and PowerBASIC is "supposed" to ignore it, but it doesn't.

            --Dave


            ------------------
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Home of the BASIC Gurus
            www.basicguru.com

            Comment


            • #7
              Thanks to all of you for your help. It is most appreciated!


              ------------------
              Mark Newman
              Mark Newman

              Comment

              Working...
              X