'===========================================================================
' Subject: Detect if /AH is enabled           Date: 09-15-02 (  :  )       
'  Author: Antoni Gual                        Code: QB, Qbasic, PDS        
'  Origin: agual@eic.ictnet.es              Packet: MEMORY.ABC
'===========================================================================
DECLARE FUNCTION IsAhEnabled! ()
SELECT CASE IsAhEnabled
CASE 0: PRINT "AH is not enabled"
CASE 1: PRINT "AH is enabled"
CASE -1: PRINT "No enough free memory to check. Use the function before DIMming your arrays"
CASE ELSE: PRINT "Curious result! Hmmm.."
END SELECT
END

IsAHEnabledError: errata% = ERR: RESUME NEXT

FUNCTION IsAhEnabled
'by Antoni Gual September-2001 agual@eic.ictnet.es
'----------------------------------------------------------------------------
'Checks if the program is run (or was compiled) with /ah enabled, thus allowing
'arrays bigger than 64K
'returns 1 if /ah is enabled, 0 if is not enabled, and -1 if it was not
'enough memory to perform the check
' To run this check you must add the line (without the leading quote):
'    IsAHEnabledError: errata% = ERR: RESUME NEXT
' after the END line of your main program.
'Tested in QB1.1 QB4.5 and PDS
'----------------------------------------------------------------------------

SHARED errata%
IF FRE(-1) < 65540 THEN IsAhEnabled = -1: EXIT FUNCTION
ON ERROR GOTO IsAHEnabledError
x% = 16384
REDIM a(0 to x%) AS LONG
SELECT CASE errata%
CASE 9: IsAhEnabled = 0
CASE ELSE: IsAhEnabled = 1
END SELECT
ON ERROR GOTO 0
END FUNCTION

