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
SMcClouth
Coder
Posts: 32 Joined: Wed Jun 06, 2012 11:45 am
Post
by SMcClouth » Fri Oct 19, 2012 8:57 am
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]
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Fri Oct 19, 2012 11:25 am
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.
SMcClouth
Coder
Posts: 32 Joined: Wed Jun 06, 2012 11:45 am
Post
by SMcClouth » Fri Oct 19, 2012 1:31 pm
Still the problem remains that even though I have RESUME NEXT, it doesn't resume (returning to the SUB FindFATFile) and continue the program.
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Fri Oct 19, 2012 1:57 pm
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.
SMcClouth
Coder
Posts: 32 Joined: Wed Jun 06, 2012 11:45 am
Post
by SMcClouth » Sat Oct 20, 2012 3:22 pm
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?
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Sun Oct 21, 2012 10:52 am
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.
SMcClouth
Coder
Posts: 32 Joined: Wed Jun 06, 2012 11:45 am
Post
by SMcClouth » Wed Nov 07, 2012 12:16 pm
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 » Mon Mar 04, 2013 10:30 pm
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!
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Tue Mar 05, 2013 12:45 am
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
SMcClouth
Coder
Posts: 32 Joined: Wed Jun 06, 2012 11:45 am
Post
by SMcClouth » Tue Mar 05, 2013 12:56 am
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 » Wed Mar 06, 2013 4:39 am
@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!