home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / AMOSPRO4.DMS / in.adf / Tutorials / Arrays.AMOS / Arrays.amosSourceCode
Encoding:
AMOS Source Code  |  1992-09-28  |  3.7 KB  |  133 lines

  1. '*************************** 
  2. '*    AMOS Professional    * 
  3. '*                         * 
  4. '*         ARRAYS          * 
  5. '*                         * 
  6. '* (c) Europress Software  * 
  7. '*                         * 
  8. '*     Ronnie Simpson      * 
  9. '*************************** 
  10. '
  11. '------------------------------------------- 
  12. 'SETTING UP
  13. '------------------------------------------- 
  14. '        +----->The command (reserves the memory required) 
  15. '        |  +----->The variable    
  16. '        |  |  +----->The number of elements   
  17. '        |  |  | 
  18. '        ^  ^  ^   
  19. '       Dim A(10)
  20. '
  21. '------------------------------------------- 
  22. 'GIVING AN ARRAY ELEMENT A VALUE 
  23. '------------------------------------------- 
  24. '       +----->The array variable    
  25. '       | +----->The element number    
  26. '       | |   +----->The value to be stored      
  27. '       | |   |
  28. '       ^ ^   ^
  29. '       A(5)=100 
  30. '  
  31. '------------------------------------------- 
  32. 'EXAMPLE USAGE 
  33. '------------------------------------------- 
  34. '      +----->Print the value stored in 2nd. element of array A()  
  35. '      |   +----->The array variable 
  36. '      |   | +----->The element number 
  37. '      |   | | 
  38. '      ^   ^ ^ 
  39. '    Print A(2)
  40. '
  41. '------------------------------------------- 
  42. 'NOTES 
  43. '------------------------------------------- 
  44. 'Use the Dim command at the start of your program (reserves memory). 
  45. 'Do not try to re-dimension an array that already exists.  
  46. 'Element numbers start from 0 eg. Dim A(10) gives 11 elements A(0)-A(10).  
  47. 'Array variables may be any legal name eg. A(),NAME$(),HIGH_SCORE().     
  48. 'Arrays can be of any type of variables eg. string$ A$(), real numbers N#().     
  49. 'Maximum of 65,000 elements per dimension. 
  50. '  
  51. '------------------------------------------- 
  52. 'WORKING EXAMPLE 
  53. '------------------------------------------- 
  54. 'The following program sets up the array SQUARES(8,5) and fills the elements 
  55. 'with random numbers between 0 and 9.
  56. 'A grid is drawn on the screen showing the contents of the array reading 
  57. 'horizontally and vertically.
  58. 'The computer then uses this array to calculate and display the totals of  
  59. 'each line both across and down. 
  60. '
  61. '------------------------------------------- 
  62. '
  63. Rem *** Dimension the array and reserve the memory 
  64. '
  65. Dim SQUARES(8,5)
  66. '
  67. '
  68. Rem *** Tidy up the screen 
  69. '
  70. Curs Off : Flash Off : Hide : Paper 0 : Cls 0 : Set Paint 1
  71. Palette $0,$F00,$F0,$F,$FF0,$F0F,$FF,$F70,$7F,$70F,$F07,$333,$666,$999,$CCC,$FFF
  72. '
  73. '  
  74. Rem *** Start of loop to repeat the program  
  75. '
  76. Repeat 
  77.    '
  78.    '
  79.    Rem *** Print out instructions 
  80.    '
  81.    Pen 4 : Locate 0,0 : Centre "RIGHT mouse key to stop program"
  82.    Pen 5 : Locate 0,2 : Centre "LEFT mouse key for another grid"
  83.    '
  84.    '
  85.    Rem *** Fill the array with random numbers and show them on screen 
  86.    '
  87.    For HORIZONTAL=1 To 8
  88.       For VERTICAL=1 To 5
  89.          NUMBER=Rnd(9)
  90.          SQUARES(HORIZONTAL,VERTICAL)=NUMBER
  91.          Ink 3,3,4 : Bar HORIZONTAL*30,VERTICAL*30 To HORIZONTAL*30+30,VERTICAL*30+30
  92.          Ink 6 : Text HORIZONTAL*30+3,VERTICAL*30+18,Str$(NUMBER)
  93.       Next 
  94.    Next 
  95.    '
  96.    '
  97.    Rem *** find the totals of the vertical columns
  98.    '
  99.    For HORIZONTAL=1 To 8
  100.       ANSWER=0
  101.       For VERTICAL=1 To 5
  102.          ANSWER=ANSWER+SQUARES(HORIZONTAL,VERTICAL)
  103.       Next 
  104.       Ink 8,0 : Text HORIZONTAL*30,192,Str$(ANSWER)+" "
  105.    Next 
  106.    '
  107.    '
  108.    Rem *** now find the totals of the horizontal lines
  109.    '
  110.    For VERTICAL=1 To 5
  111.       ANSWER=0
  112.       For HORIZONTAL=1 To 8
  113.          ANSWER=ANSWER+SQUARES(HORIZONTAL,VERTICAL)
  114.       Next 
  115.       Text 271,VERTICAL*30+18,Str$(ANSWER)+" "
  116.    Next 
  117.    '
  118.    '
  119.    Rem *** wait for the user to click a mouse button
  120.    '
  121.    Do 
  122.       Exit If Mouse Key
  123.    Loop 
  124.    '
  125.    '
  126.    Rem *** If left mouse key then repeat
  127.    '
  128. Until Mouse Key=2
  129. '
  130. '
  131. Rem *** return to editor when right mouse key has been pressed 
  132. '
  133. Edit