Page 1 of 1

Error-handler

Posted: Fri Oct 19, 2012 8:57 am
by SMcClouth
Hey all,

I'm using an error-handler, entirely based upon Novix's error handler.
But since a couple of weeks I'm experiencing a problem.

To explain things a bit, I'm working with modules and in the following issue I have:

Code: Select all

[u]qbinux.bi[/u]
DECLARE FUNCTION FindFATFile% (fil AS STRING)

COMMON SHARED FileFound AS STRING * 1

ON ERROR GOTO OnError

Code: Select all

[u]handle.err[/u]

DEFINT A-Z
'$DYNAMIC
OnError:
IF ERR <> 0 THEN
	IF ERR = 53 THEN
		FileFound = "0"
	END IF
	RESUME NEXT
END IF

Code: Select all

[u]fs\fs.bas[/u]
'$DYNAMIC
DEFINT A-Z

FUNCTION FindFATFile (fil AS STRING)
FileFound = "1"
ff = FREEFILE
OPEN fil FOR INPUT AS #ff
CLOSE #ff
FindFATFile = VAL(FileFound)
END FUNCTION
FindFATFile is to see if a file exist. But for some reason it doesn't seem to return from the error handler and just exits.

Anyone has a clue wot the issue could be?[/u][/code]

Posted: Fri Oct 19, 2012 11:25 am
by burger2227
Why test it with VAL("0")?

Code: Select all

OnError: 
IF ERR <> 0 THEN 
 FileFound = CHR$(ERR)   
END IF
RESUME NEXT 
Read the error value with ASC.

Where would it go if you GOTO it and ERR = 0? RESUME was inside the IF statement. It always needs to return.

Posted: Fri Oct 19, 2012 1:31 pm
by SMcClouth
Still the problem remains that even though I have RESUME NEXT, it doesn't resume (returning to the SUB FindFATFile) and continue the program.

Posted: Fri Oct 19, 2012 1:57 pm
by burger2227
COMMON is used to pass values to other modules when you use CHAIN. The statement must be in every module and lists must match variable types.

In QB you need BRUN45.EXE to use with the program. You can't just jump from one module to the next.

QB64 can INCLUDE code from other modules, but the compiler just adds the code to the main program.

Posted: Sat Oct 20, 2012 3:22 pm
by SMcClouth
I'm using PDS 7.1. If I understand you, you'd say that I could (or would have) to use DIM SHARED instead of COMMON SHARED?

Posted: Sun Oct 21, 2012 10:52 am
by burger2227
You can't just jump from code in one module to another module.

SHARED allows sub-procedures INSIDE the same module to share values globally in that module only.

COMMON allows sharing from one module to another.

COMMON SHARED does both, but how do you get to the other module? You can LINK modules, but that is another story.

Posted: Wed Nov 07, 2012 12:16 pm
by SMcClouth
I compile the source manually with

Code: Select all

bc source1.bas;
bc source2.bas;

link source1+source2,,nul,lib.lib;
Thx so far!

Posted: Mon Mar 04, 2013 10:30 pm
by SMcClouth
Back on the matter.

So it is linked, it uses COMMON SHARED.

For some reason it can't return to the FUNCTION, which caused the ERROR, namely FindFATFile. When trying to change RESUME NEXT to RESUME or RESUME 0, it just continues to loop in handle.err. I checked this with a print command.

So any clues on how to solve this?

Thx!

Posted: Tue Mar 05, 2013 12:45 am
by burger2227
What is handle.err? It appears that you have code in 3 files.

A BI file must be used as an $INCLUDE file at start of program.

You can't just go to the err file

Posted: Tue Mar 05, 2013 12:56 am
by SMcClouth
It's also a .bi-file. I'll post an update later, since I resolved the matter in the last hour.

Posted: Wed Mar 06, 2013 4:39 am
by SMcClouth
@burger2227 you're correct. I should've added the '$INCLUDE:'bi-file' in my first post. On my computer I have that.

Right now I left out the 'handle.err'

Code: Select all

FUNCTION FindFATFile (fil AS STRING)
FileFound = "1"
IntFileName$ = fil + CHR$(0)
RegsX.AX = &H4E00
'RegsX.CX = 39
RegsX.DX = SADD(IntFileName$)
RegsX.DS = VARSEG(IntFileName$)
InterruptX &H21, RegsX, RegsX

CarryFlag& = (RegsX.AX AND 1)
IF CarryFlag& = 1 THEN
        FileFound = "0"
END IF
FindFATFile = VAL(FileFound)
END FUNCTION
It seems to work and does the same without the error-handler.

If you think the code can be refurbished or enhanced lemme know please!