home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
dscalc.zip
/
DSCUSTOM.SC
< prev
next >
Wrap
Text File
|
1990-01-23
|
6KB
|
231 lines
Return "Read me first by selecting {Scripts} {Editor} {Edit}" +
" and then select DSCustom!"
;-- The following is an example of the way that custom procedures and formulas
;-- may be added into DSCalc by a programmer/user that will perform the
;-- calculation when [F10] is pressed and "Custom " selected from the menu.
;--
;--
;-- There are only two things required to make this work.
;--
;-- 1) The call to DSCalc(VariableList) must include the name of the library
;-- that contains the custom procedures.
;--
;-- 2) The main procedure in the custom library MUST BE NAMED
;-- DS.Custom.v().
;--
;--
;-- Now for the real stuff.
;--
;--
;-- Decide what to name the library.
;-- In this example, I decided to name it "MyLib" but you may name it any
;-- acceptable eight character filename (without an extension).
;-- WARNING! BE SURE THAT YOU ARE NOT OVERWRITING AN EXISTING LIBRARY.
;-- I.E. PARADOX HAS A LIBRARY NAMED "CUSTOM.LIB" USUALLY FOUND IN THE
;-- PARADOX DIRECTORY. IF YOU NAME YOUR LIBRARY "CUSTOM" AND ARE IN THE
;-- PARADOX DIRECTORY, PARADOX WILL CREATE A NEW "CUSTOM" LIBRARY,
;-- WIPING OUT THE ORIGINAL WITHOUT ASKING FOR CONFORMATION!
DSCustomLib = "MyLib"
;-- Create the library to write the procedures into.
CreateLib DSCustomLib
;-- Start the definition of the procedure. REMEMBER, THE FIRST PROCEDURE CALLED
;-- FROM DSCALC IS ds.custom.v()
Proc ds.custom.v()
;-- Standard programming technique to declare a variable as private so as not to
;-- alter a variable with the same name elsewhere in the stack.
Private Menu_Choice,
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;-- This procedure ds.custom.v() should always declare as Private to it the
;-- variable name ErrorProc.
;-- This should be done to overrule DSCalc's ErrorProc Procedure ("DS.Oops.1")
;-- as it is designed simply to detect if the Procedure ds.custom.v() actually
;-- exists. Without overriding DSCalc's ErrorProc, "DS.Oops.1" will take
;-- control and return some strange results.
ErrorProc
;-- I Strongly suggest if you know how to use ErrorProc that if there is the
;-- remotest possibility of an error occurring in your procedures that you
;-- install your own error trapping procedure into the custom procedures you
;-- create for DSCalc. I claim no responsibility for any system failure from any
;-- added in procedure or formulas into DSCalc.
;-- GENERAL INFO: MOST OF THE MATH FUNCTIONS IN PARADOX Version 2 WILL CRASH
;-- YOUR SYSTEM WITHOUT WARNING. DSCALC HAS PROTECTED AGAINST THESE
;-- POSSIBILITIES! IF YOU USE ANY OF PARADOX's MATH FUNCTIONS, MAKE SURE YOU
;-- THOROUGHLY TEST THEM BEFORE ADDING THEM TO DSCALC!
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;-- A little trick here to keep the bottom line from disappearing from the
;-- calculator.
;-- Display a blank message.
Message ""
;-- Even though you would think the length of the message should only be 1
;-- character long, Paradox makes it two characters long so:
@ 22,78 Clear EOL
;-- This clears the message from the screen and restores line 24.
;-- (Don't ask me to explain why, it just works.) By the way, the calculator
;-- does not use 22,78 or 22,79. If it did, instead of Clear EOL, I might have
;-- used @ 22,78 ?? " └└" or something that would restore that part of the
;-- screen.
;-- This does cause a slight flicker that is somewhat annoying on an "XT" but
;-- but it allows me the use of the entire screen. This flicker can be
;-- avoided using canvas off/canvas on
;-- For this example I decided to display a menu so that more than one custom
;-- choice might be added in later but this could be the actual formula
;-- procedure if desired.
ShowMenu
"Odds " : " Odds of picking a given set of items from a larger set.",
"Esc " : " Return to what you were doing before pressing [F10]."
To Menu_Choice
Message ""
@ 22,78 Clear EOL
Switch
Case Menu_Choice = "Odds " : Odds()
;-- You may return the answer to DSCalc for display in the calculator.
;-- This will overwrite any entry currently in the calculator window.
Return Retval
EndSwitch
;-- Return back to DSCalc
Return False ;-- user pressed [Esc]
;-- End definition of the procedure
EndProc
;-- Write it to the Library
WriteLib DSCustomLib ds.custom.v
;-- Release it from memory for now
Release Procs ds.custom.v
;-------------------------------------------------------------------------
;-- Here is the procedure that gathers the information and performs the actual
;-- formula
Proc Odds()
;-- Some more Private variables used only in this procedure.
Private x, y, looper, odds
;-- Clear the top two lines and leave the cursor at 0,0
@ 1,0 Clear EOL
@ 0,0 Clear EOL
;-- Turn the cursor on to assist the user.
Cursor Normal
;-- Display a message (Style may be altered to highlight or reverse text as desired)
?? "Enter the number of picks: "
;-- Gather the information
;-- Note the picture specification - whole numbers only will be accepted.
;-- You may wish to insert a Max into this as the variable x becomes the
;-- number of loops performed in a For .... EndFor loop.
Accept "N" Min 1 Picture "*[#]" To x
;-- Check to see if the user pressed [Esc] or did not enter a value.
If Not IsAssigned(x) or
IsBlank(x) then
Return False ;-- User cancelled
Endif
;-- Move the cursor back to 0,0
@ 0,0
;-- Display another message
?? "Enter the number of items to pick from: "
;-- Gather the other required data.
;-- Note the Min requirement here - there must be more items to pick from then
;-- are being picked
Accept "N" Min x+1 Picture "*[#]" To y
;-- Check for assignment to the variable
If Not IsAssigned(y) or
IsBlank(y) then
Return False ;-- User cancelled
Endif
;-- Set up the odds variable for the equation
odds = 1
;-- Calculate the answer
for looper from 1 to x
odds = odds * (y-looper+1)/(x-looper+1)
endfor
;-- Return the answer to the calling procedure.
Return odds
;-- End of procedure
EndProc
WriteLib DSCustomLib Odds
Release Procs Odds