slight modifications to \doc\bmxlang\compatibility.html (added class="code" to all code examples)
<html> <head> <title></title> <link rel="styleSheet" href=bmxlang.css type="text/css"> </head> <body> <h1>BASIC Compatibility</h1> This section covers some of the differences between BlitzMax and 'classic' BASIC, and introduces features that help overcome some of classic BASIC's shortcomings.<br> <br> <h2>Strict mode</h2> Classic BASIC allows you to declare variables 'on the fly'. For example, consider a program consisting of: <pre class="code"> For k=1 To 10 sum=sum+k Next Print sum </pre> This program automatically creates 2 local variables: 'k' and 'sum'. However, this behaviour can often lead to unexpected bugs. For example, if you mistyped one of the 'sum' variables, the program would not work as expected. No error would be given - a new variable would simply be created.<br> <br> By default, BlitzMax will allow you to automatically declare variables like this. However, you can use the <font class=token>Strict</font> command to override this behaviour.<br> <br> <font class=token>Strict</font> must appear at the top of your program before any actual program code and puts your program into 'strict mode'. Strict mode forces you to declare all variables before use. For example, rewriting the above program in strict mode results in: <pre class="code"> Strict Local sum,k For k=1 To 10 sum=sum+k Next Print sum </pre> If you were to mistype one of the variable names in this program, you would receive an 'identifier not found' error when compiling, allowing you to easily find and correct the problem.<br> <br> <h2>Arrays</h2> Blitzmax does not support the Dim statement for array creation. Instead, arrays in BlitzMax are real types - they can be passed to functions, returned from functions and placed in variables.<br> <br> To create a classic BASIC style array in BlitzMax, use a global variable. For example: <pre class="code">Global my_array$[100] 'create a 100 element string array</pre> Also note that arrays in BlitzMax are not '1 bigger' than their dimensioned size - the 100 element array above contains 100 elements, numbered 0 through 99 inclusive.<br> <br> BlitzMax also does not support a 'Redim' operation. Instead, you can use <a href=slices.html>slices</a>. For example: <pre class="code">Global my_array$[100] 'create a 100 element string array my_array=my_array[..200] 'now a 200 element array!</pre><br> <h2>Goto and Gosub</h2> BlitzMax does not support the Gosub command. Use <a href=functions.html>functions</a> instead.<br> <br> The Goto command is supported, but only in non-strict mode. Goto labels should be prefixed with a <font class=token>#</font> character. For example: <pre class=code>For k=1 To 10 a=Rand(10) If a<5 Then Goto LessThan5 If a>5 Then Goto GreaterThan5 Print "a is equal to 5" Goto AllDone #LessThan5 Print "a is less than 5" Goto AllDone #GreaterThan5 Print "a is greater than 5" #AllDone Next</pre><br> <h2>Data, Read and Restore</h2> Data, Read and Restore are supported but have been renamed to <font class=token>DefData</font>, <font class=token>ReadData</font> and <font class=token>RestoreData</font>. Data labels must also be prefixed with a <font class=token>#</font> character.<br> <br> <h2>Object handles</h2> BlitzMax allows objects to be assigned to integer variables, and integer variables to be passed to functions expecting objects. This is mainly for the benefit of beginners, as it reduces the size and complexity of code, but is also great for lazy pro's! For example: <pre class=code>Graphics 640,480 image=LoadImage( "an_image.png" ) 'returned object is converted to an integer handle DrawImage image,0,0 'integer image parameter is converted back to an object Flip WaitKey</pre> This is achieved using an <i>object handle</i> system, and such handles should be released using the <font class=token>Release</font> command when they are no longer needed. For example: <pre class=code>Graphics 640,480 image=LoadImage( "an_image.png" ) 'returned object is converted to an integer handle DrawImage image,0,0 'integer image parameter is converted back to an object Release image 'image no longer needed - release it Flip WaitKey</pre> <br> Failing to release an object handle will result in memory leaks. However, all objects are released at program exit anyway, so for quick 'n' dirty jobs you don't have to bother.<br> <br> <h2>Type tag shortcuts</h2> When declaring variables and function return types, BlitzMax allows you to use BASIC style 'type tags'. These are as follows:<br> <br> <table> <tr><th>Shortcut</th><th>Equivalent type</th></tr> <tr><td><font class=token>%</font></td><td><font class=token>Int</font></td></tr> <tr><td><font class=token>#</font></td><td><font class=token>Float</font></td></tr> <tr><td><font class=token>!</font></td><td><font class=token>Double</font></td></tr> <tr><td><font class=token>$</font></td><td><font class=token>String</font></td></tr> </table> <br> For example, a string variable can be declared in two ways: <pre class="code"> Local a_string:String Local another_string$ </pre> Mac users whose keyboards do not feature the # character should use 'Alt 3'. </body> </html>