home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AxoCalculator Package / AxoCalculator Documentation / Programming in Basic / Example Programs < prev    next >
Encoding:
Text File  |  1993-03-14  |  4.8 KB  |  170 lines  |  [TEXT/AxoC]

  1. LocalLanguage Basic
  2. '    -------------------------------------------------
  3. '    The following 6 programs demonstrate various aspects of 
  4. '    AxoCalculator's Basic programming language. 
  5. '
  6. '    •  To load all 6 programs, choose "Select All" under 
  7. '        the "Edit" menu, then press "enter". 
  8. '
  9. '    •  To run a program, either select it under the 
  10. '        "Calculator" menu, or type its name and press "enter".
  11. '
  12. '    •  After the programs are loaded, this file does not need
  13. '        to remain open in order to use them.
  14. '    --------------------------------------------------
  15.  
  16. '    ----------------- Global Variables  ------------------
  17. '    The following 1 line section demonstrates how to declare
  18. '    global arrays. See "The Programming Language" for more
  19. '    on array declaration. 
  20. '    -----------------------------------------------------
  21.     DIM globalArr(10)
  22.  
  23.  
  24. '    ------------------- DoCount ------------------------
  25. '    A very simple program which counts to 10.
  26. '    It demonstrates how to declare a program, and assign it a 
  27. '    menu string (Count To 10) with a command key option (/1).
  28. '    ----------------------------------------------------
  29.     program DoCount "Count To 10/4"
  30.     For i = 1 to 10 
  31.         write (i)
  32.     next i
  33.     Print ""
  34.     end
  35.  
  36. '    ---------------- Factorial -----------------------
  37. '    A slightly more complex program which calculates
  38. '    all the factorial numbers from 1 to 15.
  39. '    It uses a multi-parameter "Print" statement.
  40. '    -------------------------------------------------
  41.     program Fact "Factorial 1 to 10/5"
  42.     f = 1
  43.     For i = 1 to 10
  44. '    • Calculate the factorial •
  45.         f = f * i
  46.         Print ("Factorial ",i," = ",f)
  47.     Next i
  48.     end
  49.  
  50.  
  51. '    ------------------ Trigonometry ------------------
  52. '    This program uses an internal trigonometric function.
  53. '    -------------------------------------------------
  54.     program Trig "Cos 0 to 90/6"
  55. '    • Calculate the cosine of angles from 0 to 90 in steps of 10 •
  56.     For i = 0 to 9
  57.         degrees = i * 10
  58.         cosResult = cos (degrees)
  59.         print ("cos ( ",degrees,") = ",cosResult)
  60.     Next i
  61.     end
  62.  
  63.  
  64. '    ------------ String Variables -----------------
  65. '    This program shows how to create and initialize
  66. '    string variables. It shows how to pass them as 
  67. '    arguments to a procedure or function.
  68. '    ---------------------------------------------
  69.     Sub Print2Strings (aString, bString)
  70.     Print ("1) ", aString)
  71.     Print ("2) ", bString)
  72.     end
  73.  
  74.     program DemoString "String Variable Example/7"
  75. '     Strings created "on the fly".
  76.     aString = "Anhydrohydroxyprogesterone"
  77.     bString = "synthetic female hormone"
  78.     
  79. '     The "Concat" function combines 2 or more strings
  80.     cString = concat (aString,":  ",bString)
  81.     
  82.     aString = "Trinitrophenylmethylnitramine"
  83.     bString = "a type of explosive."
  84.     
  85. '     String created procedurally.
  86.     NewString (dString)
  87.     dString = concat (aString,":  ",bString)
  88.     
  89. '    Strings passed as arguments to a subroutine.
  90.     Print2Strings (cString, dString)
  91.     end
  92.  
  93.  
  94. '    -------------- Test Array Arithmetic ------------
  95. '    This program initialize the global array, "globalArr", and
  96. '    creates and initializes a local array, "localArr".
  97. '    It adds, the two arrays, and outputs the result.
  98. '    -----------------------------------------------
  99.     program testArr "Array Example/8"
  100.     DIM localArr(10)
  101.  
  102. '    • Initialize the local and global arrays •
  103.     For i = 1 to 10
  104.         localArr(i) = 100
  105.         globalArr(i) = i
  106.     Next i
  107.     
  108. '    • Add the two arrays •
  109.     globalArr = globalArr + localArr
  110.     writeArr (globalArr)
  111.     end
  112.  
  113.  
  114. '    -------------- Sphere Volume and S.A. ----------------
  115. '    This program demonstrates the "poseDialog" and "Alert"
  116. '    commands. It uses poseDialog to prompt the user for
  117. '    a sphere's radius, then calculates the volume and
  118. '    surface area of the sphere, and returns the results
  119. '    to the user in an alert dialog.
  120. '    ----------------------------------------------------
  121.     program sphere "Volume and S.A. of Sphere/9"
  122. '    • Ask the user for the radius of the sphere •
  123.     poseDialog ("\rCalculate the volume and surface area of a sphere", 
  124. &                        "Radius of sphere ",radius)
  125.  
  126. '    • Calculate the surface area and volume •
  127.     theSA = 4 * pi * radius ^ 2
  128.     theVolume = (4 / 3) * pi * radius ^ 3
  129.  
  130. '    • Send the results to an alert dialog •
  131.     Alert ("The volume and surface area of a \r sphere with radius ", 
  132. &                    radius," are : \r Volume = ",theVolume,
  133. &                      "\r Surface area = ",theSA)
  134.     end
  135.  
  136.  
  137. '    ------------------- Count Down ----------------------
  138. '    This program demonstrates the "FlushOutput" and "Beep"
  139. '    commands. It counts down from 10 to 0 beeping at each
  140. '    count. A pause is introduces between each count by
  141. '    performing several hundred exponential calculations.
  142. '    -----------------------------------------------------
  143.     program CountDown "Lift Off/0"
  144.     Print ("Prepare for count down.")
  145.     FlushOutput
  146. '    • Pause •
  147.     For k = 1 to 50
  148.         a = exp(2.0)
  149.     Next k
  150. '    • Start the Count down •
  151.     For m = 0 to 10
  152.         j = 10 - m
  153.         if (j = 3) Print ("Ignition.")
  154.         if (j = 0) then
  155.             Print ("Lift Off !!")
  156.         else
  157.             Print (j)
  158.         endif
  159.         FlushOutput
  160.         Beep
  161.         j = j - 1
  162.  
  163. '    • Slow down the count •
  164.         For k = 1 to 20
  165.             a = exp(2.0)
  166.         Next k
  167.     Next m
  168. end
  169.  
  170.