Results 1 to 2 of 2

Thread: QuickBasic - Error handling inside function

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    37

    QuickBasic - Error handling inside function

    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:
    Code:
    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?

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: QuickBasic - Error handling inside function

    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:

    Code:
    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:
    Code:
    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.)
    Last edited by Peter Swinkels; Aug 7th, 2010 at 11:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width