home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / DATABASE / DSCALC.ZIP / DSCUSTOM.SC < prev    next >
Text File  |  1990-01-23  |  6KB  |  231 lines

  1. Return "Read me first by selecting {Scripts} {Editor} {Edit}" + 
  2.        " and then select DSCustom!"
  3.  
  4. ;-- The following is an example of the way that custom procedures and formulas
  5. ;-- may be added into DSCalc by a programmer/user that will perform the
  6. ;-- calculation when [F10] is pressed and "Custom " selected from the menu.
  7. ;--
  8. ;--
  9. ;-- There are only two things required to make this work.
  10. ;--
  11. ;--   1) The call to DSCalc(VariableList) must include the name of the library
  12. ;--      that contains the custom procedures.
  13. ;--
  14. ;--   2) The main procedure in the custom library MUST BE NAMED
  15. ;--      DS.Custom.v().
  16. ;--
  17. ;--
  18. ;-- Now for the real stuff.
  19. ;--
  20. ;--
  21.  
  22.  
  23. ;-- Decide what to name the library.
  24. ;-- In this example, I decided to name it "MyLib" but you may name it any
  25. ;-- acceptable eight character filename (without an extension).
  26. ;-- WARNING! BE SURE THAT YOU ARE NOT OVERWRITING AN EXISTING LIBRARY.
  27. ;-- I.E. PARADOX HAS A LIBRARY NAMED "CUSTOM.LIB" USUALLY FOUND IN THE
  28. ;-- PARADOX DIRECTORY. IF YOU NAME YOUR LIBRARY "CUSTOM" AND ARE IN THE
  29. ;-- PARADOX DIRECTORY, PARADOX WILL CREATE A NEW "CUSTOM" LIBRARY,
  30. ;-- WIPING OUT THE ORIGINAL WITHOUT ASKING FOR CONFORMATION!
  31.  
  32. DSCustomLib = "MyLib"
  33.  
  34.  
  35. ;-- Create the library to write the procedures into.
  36.  
  37. CreateLib DSCustomLib
  38.  
  39.  
  40. ;-- Start the definition of the procedure. REMEMBER, THE FIRST PROCEDURE CALLED
  41. ;-- FROM DSCALC IS ds.custom.v()
  42.  
  43. Proc ds.custom.v()
  44.  
  45.  
  46. ;-- Standard programming technique to declare a variable as private so as not to
  47. ;-- alter a variable with the same name elsewhere in the stack.
  48.  
  49. Private Menu_Choice,
  50.  
  51. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  52. ;-- This procedure ds.custom.v() should always declare as Private to it the
  53. ;-- variable name ErrorProc.
  54. ;-- This should be done to overrule DSCalc's ErrorProc Procedure ("DS.Oops.1")
  55. ;-- as it is designed simply to detect if the Procedure ds.custom.v() actually
  56. ;-- exists.  Without overriding DSCalc's ErrorProc, "DS.Oops.1" will take 
  57. ;-- control and return some strange results.
  58.  
  59. ErrorProc
  60.  
  61. ;-- I Strongly suggest if you know how to use ErrorProc that if there is the
  62. ;-- remotest possibility of an error occurring in your procedures that you
  63. ;-- install your own error trapping procedure into the custom procedures you
  64. ;-- create for DSCalc. I claim no responsibility for any system failure from any
  65. ;-- added in procedure or formulas into DSCalc.
  66. ;-- GENERAL INFO: MOST OF THE MATH FUNCTIONS IN PARADOX Version 2 WILL CRASH
  67. ;-- YOUR SYSTEM WITHOUT WARNING. DSCALC HAS PROTECTED AGAINST THESE
  68. ;-- POSSIBILITIES!  IF YOU USE ANY OF PARADOX's MATH FUNCTIONS, MAKE SURE YOU
  69. ;-- THOROUGHLY TEST THEM BEFORE ADDING THEM TO DSCALC!
  70. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  71.  
  72.  
  73. ;-- A little trick here to keep the bottom line from disappearing from the
  74. ;-- calculator.
  75. ;-- Display a blank message.
  76.  
  77. Message ""
  78.  
  79.  
  80. ;-- Even though you would think the length of the message should only be 1
  81. ;-- character long, Paradox makes it two characters long so:
  82.  
  83. @ 22,78 Clear EOL
  84.  
  85. ;-- This clears the message from the screen and restores line 24.
  86. ;-- (Don't ask me to explain why, it just works.) By the way, the calculator
  87. ;-- does not use 22,78 or 22,79. If it did, instead of Clear EOL, I might have
  88. ;-- used @ 22,78 ?? " └└" or something that would restore that part of the
  89. ;-- screen.
  90. ;-- This does cause a slight flicker that is somewhat annoying on an "XT" but
  91. ;-- but it allows me the use of the entire screen.  This flicker can be
  92. ;-- avoided using canvas off/canvas on
  93.  
  94.  
  95.  
  96. ;-- For this example I decided to display a menu so that more than one custom
  97. ;-- choice might be added in later but this could be the actual formula
  98. ;-- procedure if desired.
  99.  
  100.    ShowMenu
  101.  
  102.    "Odds " : " Odds of picking a given set of items from a larger set.",
  103.    "Esc " : " Return to what you were doing before pressing [F10]."
  104.  
  105.     To Menu_Choice
  106.  
  107.         Message ""
  108.         @ 22,78 Clear EOL
  109.  
  110.         Switch
  111.  
  112.            Case Menu_Choice = "Odds " :  Odds()
  113.  
  114. ;-- You may return the answer to DSCalc for display in the calculator.
  115. ;-- This will overwrite any entry currently in the calculator window.
  116.  
  117.                                          Return Retval
  118.         EndSwitch
  119.  
  120.  
  121. ;-- Return back to DSCalc
  122.  
  123. Return False   ;--  user pressed [Esc]
  124.  
  125. ;-- End definition of the procedure
  126.  
  127. EndProc
  128.  
  129.  
  130. ;-- Write it to the Library
  131.  
  132. WriteLib DSCustomLib ds.custom.v
  133.  
  134.  
  135. ;-- Release it from memory for now
  136.  
  137. Release Procs ds.custom.v
  138.  
  139.  
  140. ;-------------------------------------------------------------------------
  141.  
  142. ;-- Here is the procedure that gathers the information and performs the actual
  143. ;-- formula
  144.  
  145. Proc Odds()
  146.  
  147. ;-- Some more Private variables used only in this procedure.
  148.  
  149. Private x, y, looper, odds
  150.  
  151.  
  152. ;-- Clear the top two lines and leave the cursor at 0,0
  153.  
  154.  @ 1,0 Clear EOL
  155.  @ 0,0 Clear EOL
  156.  
  157.  
  158. ;-- Turn the cursor on to assist the user.
  159.  
  160. Cursor Normal
  161.  
  162. ;-- Display a message (Style may be altered to highlight or reverse text as desired)
  163.  
  164.  ?? "Enter the number of picks: "
  165.  
  166.  
  167. ;-- Gather the information
  168. ;-- Note the picture specification - whole numbers only will be accepted.
  169. ;-- You may wish to insert a Max into this as the variable x becomes the
  170. ;-- number of loops performed in a For .... EndFor loop.
  171.  
  172.  Accept "N" Min 1 Picture "*[#]" To x
  173.  
  174.  
  175. ;-- Check to see if the user pressed [Esc] or did not enter a value.
  176.  
  177.  If Not IsAssigned(x) or
  178.     IsBlank(x) then
  179.     Return False         ;-- User cancelled
  180.  Endif
  181.  
  182.  
  183. ;-- Move the cursor back to 0,0
  184.  
  185.  @ 0,0
  186.  
  187.  
  188. ;-- Display another message
  189.  
  190.  ?? "Enter the number of items to pick from: "
  191.  
  192.  
  193. ;-- Gather the other required data.
  194. ;-- Note the Min requirement here - there must be more items to pick from then
  195. ;-- are being picked
  196.  
  197.  Accept "N" Min x+1 Picture "*[#]" To y
  198.  
  199.  
  200. ;-- Check for assignment to the variable
  201.  
  202.  If Not IsAssigned(y) or
  203.     IsBlank(y) then
  204.     Return False         ;-- User cancelled
  205.  Endif
  206.  
  207.  
  208. ;-- Set up the odds variable for the equation
  209.  
  210. odds = 1
  211.  
  212.  
  213. ;-- Calculate the answer
  214.  
  215. for looper from 1 to x
  216.  odds = odds * (y-looper+1)/(x-looper+1)
  217. endfor
  218.  
  219.  
  220. ;-- Return the answer to the calling procedure.
  221.  
  222. Return odds
  223.  
  224.  
  225. ;-- End of procedure
  226.  
  227. EndProc
  228.  
  229.  
  230. WriteLib DSCustomLib Odds
  231. Release Procs Odds