Integer "Overflow" Using SETMEM in Basic PDS and QuickBasic (84929)



The information in this article applies to:

  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q84929

SUMMARY

The SETMEM function in Basic returns the amount of memory available to Basic after any re-allocation from the SETMEM occurs. If you inadvertently try to assign this return value to an integer variable, an "Overflow" error may occur. The return value from SETMEM is a long integer, and may have a value greater then 32,767 (the maximum value for an integer variable).

This would normally only occur if you have a DEF type defined somewhere in your program, such as a DEFINT. A typing of the specific return variable would be required in this case.

MORE INFORMATION

If the following two lines of code are entered into QBX.EXE or QB.EXE, an "overflow" error will likely occur.
   DEFINT A-Z
   X = SETMEM(-1024)
				
The workaround is to either not use the DEFINT statement, or to use the following command for the SETMEM;
   X# = SETMEM(-1024)
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB84929