Error-handler

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Error-handler

Post 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]
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post 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.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post 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?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post 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!
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post 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!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post by SMcClouth »

It's also a .bi-file. I'll post an update later, since I resolved the matter in the last hour.
SMcClouth
Coder
Posts: 32
Joined: Wed Jun 06, 2012 11:45 am

Post 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!
Post Reply