Announcement

Collapse
No announcement yet.

#debug display

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

  • #debug display

    I use this function to open files and return the error code if needed.

    Other processes have acces to the file so the function allows for this and wait for a max of 20 seconds (more than enough time for other processes to finish)

    I added the statement #DEBUG DISPLAY ON

    I had an error display message today showing un untrapped error 70 in this function.

    Can't see why the code should produce this, an I using ON ERROR RESUME NEXT correctly?

    Code:
    FUNCTION Open_Seq_In( BYVAL Han AS LONG, BYVAL SharedMode AS LONG, FileSpec AS STRING ) AS LONG
    	'
    	' SharedMode = 1 if open in shared read
    	LOCAL ErrCount AS LONG
    	'
    	ErrCount = 0
    	DO
    		ERRCLEAR
    		ON ERROR RESUME NEXT
    		IF SharedMode = 0 THEN
    			OPEN FileSpec FOR INPUT ACCESS READ LOCK READ WRITE AS Han
    		ELSE
    			OPEN FileSpec FOR INPUT ACCESS READ LOCK SHARED AS Han
    		END IF
    		IF ERR = 0 OR ErrCount = 80 OR ERR <> 70 THEN
    			EXIT DO
    		END IF
    		INCR ErrCount
    		SLEEP 250
    	LOOP
    	'
    	FUNCTION = ERR
    	'
    END FUNCTION

  • #2
    You should get a display message showing an "untrapped error 70" up to as many as 80 times if SharedMode = 0 and the file is in use by another process for that many iterations of the loop.

    On Error Resume Next does nothing in this sub as error trapping (ON ERROR GOTO {label | line_number} ) hasn't been used to turn error trapping on..
    To disable error trapping, use ON ERROR GOTO 0 or ON ERROR RESUME NEXT. You can use this technique if an error occurs for which you have not defined a recovery path; you can also choose to display the contents of ERR or ERRCLEAR at this time.
    You can use this to test - run it twice (without clearing the first message box)..
    Code:
    Function PBMain()
     Dim sTest$
     Dim Han&
      Err = Open_Seq_in (Han, 0, EXE.Name$ + ".bas")
      sTest = Str$(Err) + " * " + Error$(Err)
      MsgBox sTest$,,"Result"
     
    End Function
    '------------------/PBMain
    Last edited by Dave Biggs; 3 Apr 2009, 11:10 AM. Reason: Show test function
    Rgds, Dave

    Comment


    • #3
      Changed the function using TRY & CATCH

      Code:
      FUNCTION Open_Seq_In( BYVAL Han AS LONG, BYVAL SharedMode AS LONG, FileSpec AS STRING ) AS LONG
      '
      ' SharedMode = 1 if open in shared read
      '
      LOCAL ErrCount AS LONG
      '
      DO
      '
      TRY ' <o><o><o><o> TRY ERROR TRAP <o><o><o><o>
      '
      ERRCLEAR
      '
      IF SharedMode = 0 THEN
      OPEN FileSpec FOR INPUT ACCESS READ LOCK READ WRITE AS Han
      ELSE
      OPEN FileSpec FOR INPUT ACCESS READ LOCK SHARED AS Han
      END IF
      '
      CATCH ' <o><o><o><o> CATCH ERROR TRAP <o><o><o><o>
      '
      IF ErrCount = 80 OR ERR <> 70 THEN
      FUNCTION = ERR
      EXIT FUNCTION
      END IF
      '
      INCR ErrCount
      SLEEP 250
      '
      FINALLY ' <o><o><o><o> FINALLY ERROR TRAP <o><o><o><o>
      '
      IF ERR = 0 THEN
      EXIT FUNCTION
      END IF
      '
      END TRY ' <o><o><o><o> TRY END ERROR TRAP <o><o><o><o>
      '
      LOOP
      '
      END FUNCTION
      Last edited by Steve Bouffe; 3 Apr 2009, 12:03 PM.

      Comment


      • #4
        No "Untrapped errors" now with my tests
        Rgds, Dave

        Comment

        Working...
        X