Dim.htm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>Dim array_name(index1[,index2][,index3][,...])</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. array_name - array name <br />
  13. index1 - index number of last variable to be created within that particular index-range <br />
  14. index2 (optional) - index number of last variable to be created within that particular index-range <br />
  15. index3 (optional) - index number of last variable to be created within that particular index-range <br />
  16. ... (optional) - and so on
  17. </td>
  18. </tr>
  19. </table>
  20. <h1>Description</h1>
  21. <table>
  22. <tr>
  23. <td>
  24. Creates an array of the specified type. For example, Dim tiles(10) creates an integer array, Dim tiles#(10) creates a float array and Dim tile$(10) creates a string array. <br />
  25. <br />
  26. <br />
  27. The contents of an array can be accessed using the index notation: 0 - indexn, giving indexn+1 number of elements for that particular index range. You should not attempt to access a non-existent element of the array. In debug mode this will cause an error stating 'index out of bounds'. With debug off however, you may get 'illegal memory access' errors, or worse no immediate errors at all. <br />
  28. <br />
  29. Arrays are global, and must be defined in the main program. <br />
  30. <br />
  31. Arrays can be re-dimmed by using the Dim statement again with the same array name, but the contents of the array will be lost. <br />
  32. <br />
  33. ----------------------------------------------------------- <br />
  34. <br />
  35. *NEW* BLITZ ARRAYS *NEW* <br />
  36. <br />
  37. Since a recent Blitz update you can now do what are called 'blitz arrays'. These are very different to a Dim'd array, in the following ways: <br />
  38. <br />
  39. They use square brackets [] instead of the normal round ones (). <br />
  40. <br />
  41. You declare them like you do Local or Global variables, example: Local myArray[10] <br />
  42. <br />
  43. They cannot be multi-dimensional, and cannot be resized. <br />
  44. <br />
  45. They can be stored in Type objects. <br />
  46. <br />
  47. They can be passed to functions. <br />
  48. <br />
  49. -----------------------------------------------------------
  50. <br>
  51. <br>
  52. See also: <a class=small href=Global.htm>Global</a>, <a class=small href=Local.htm>Local</a>.
  53. </td>
  54. </tr>
  55. </table>
  56. <h1><a href=../2d_examples/Dim.bb>Example</a></h1>
  57. <table>
  58. <tr>
  59. <td>
  60. ; Dim Example <br />
  61. ; Create a collection of 100 random numbers <br />
  62. <br />
  63. ; Create array <br />
  64. Dim nums(99) <br />
  65. <br />
  66. ; Fill each element with a random number <br />
  67. For i = 0 to 99 <br />
  68. nums(i) = Rand(1,1000) <br />
  69. Next
  70. </td>
  71. </tr>
  72. </table>
  73. <br>
  74. <a target=_top href=../index.htm>Index</a><br>
  75. <br>
  76. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Dim&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  77. </html>