Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/30397

From BetaArchive Wiki
Knowledge Base


Bad Math in EXE Using Dynamic Array of Long Integers: Use /D

Article ID: 30397

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS



This article was previously published under Q30397

SUMMARY

Microsoft recommends compiling with the debug option (BC /D) whenever arrays are being used. If a math problem involving arrays is corrected by compiling with the debug (/D) option, that program must be compiled with the debug option.

When using dynamic long-integer arrays in some math calculations in the EXE program, the results may not be correct unless you compile with the BC.EXE debug option (BC /D). The example below demonstrates this behavior.

Inside the QB.EXE environment, the debug option always is on (and cannot be disabled); this means the math problem does not occur when programs are run in QB.EXE.

The sample program below demonstrates the importance of the debug (BC /D) option, which does the following:

  1. Generates debugging code for run-time error checking
  2. Enables the CTRL+BREAK command to break a program
  3. Executes array-boundary checking

Compiling with the debug option in the sample program below is essential to making the program work correctly.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, and Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and OS/2.

MORE INFORMATION

The sample program is as follows:

DEFLNG A-Z
' $DYNAMIC
DIM a(100) as LONG, b(100) as long
a(1) = 25
b(1) = 100
r = 1
x = -3
CLS
PRINT (r - x) * b(1) + a(1)
PRINT a(1) + (r - x) * b(1)
END
                


Additional query words: QuickBas BasicCom

Keywords: KB30397