PDA

Click to See Complete Forum and Search --> : QuickBasic - Error handling inside function


SlowCoder
Sep 22nd, 2008, 12:35 PM
It's been about ... forever ... since I've worked in QB. I Thought, for nostalgic reasons, I'd get back to playing with it and write something that *someone* might find useful. :)

Anyway, here's the issue ...

I've got the following function, which returns the highest number of rows available in the current resolution:

FUNCTION HighScreenRows
DIM ScreenMode(4)
'*** find maximum screen rows ***
ScreenMode(1) = 25: ScreenMode(2) = 43: ScreenMode(3) = 50: ScreenMode(4) = 60
FOR intRows = 1 TO 4
ResolutionGood = 1
ON ERROR GOTO ErrorHandler
WIDTH 80, ScreenMode(intRows)
ON ERROR GOTO 0
'
IF ResolutionGood = 1 THEN HighScreenRows = ScreenMode(intRows)
NEXT intRows
'
VIEW PRINT
EXIT FUNCTION

ErrorHandler:
'*** capture screenmode errors ***
ResolutionGood = 0
RESUME NEXT

END FUNCTION

The code relies on the error handling to determine rows. The problem is that it gives me a "Label not found" on the "ON ERROR GOTO ErrorHandler" line.

Any help here?

Peter Swinkels
Aug 7th, 2010, 09:24 AM
Labels pointed to by the ON ERROR statement should not be inside a procedure (SUB/FUNCTION), but globally available.

I'm not sure whether this properly answers your question, but:
To get the resolution of a specific graphics mode, the POINT() function can be used as follows:


SCREEN 12 'Sets a graphics mode.
VIEW 'Resets the graphics cursor without erasing the screen.
PRINT POINT(0) * 2 'The horizontal resolution.
PRINT POINT(1) * 2 The vertical resolution.


The above code uses the graphics cursor's initial position to calculate the screen resolution.

And for determining the number of available text rows:

SCREEN 0: CLS : WIDTH 80, 43
DIM Row AS LONG
ON ERROR GOTO ReachedLastRow
Row = 1
DO
LOCATE Row
Row = Row + 1
LOOP
EndOfRoutine:
ON ERROR GOTO 0
END

ReachedLastRow:
LOCATE 1, 1
PRINT "Number of rows available in the current screen mode: "; Row - 1
RESUME EndOfRoutine


(And yes, I've noticed this post is 2 years old.)