home *** CD-ROM | disk | FTP | other *** search
/ Megazine / Megazine-1.iso / PROGRAMA / CLIPPER / CALC223 / DEMO2.PRG < prev    next >
Encoding:
Text File  |  1994-01-23  |  4.7 KB  |  154 lines

  1.  
  2. // DEMO2.prg - Demo of the calculator showing UDFs and setkeys, etc
  3.  
  4. #include "inkey.ch"
  5.  
  6. #define F_BLOCKS  "█▀███▄██ "
  7.  
  8. Function CalcHard()
  9. Local getlist:={}, nInteger, nDontWork, nFloating, cText, nAnother, aColor
  10.  
  11.    If IsColor()
  12.       aColor := {"W+/B,W/R,,,W/R","W/R","W/B,W/R,,,W/B"}
  13.    Else
  14.       aColor := {"W/N,N/W,,,W/N"}
  15.    Endif
  16.  
  17.    Set Scoreboard OFF
  18.  
  19.    SetColor(aColor[1])
  20.    CLS
  21.    @ 0,0,24,79 Box F_BLOCKS
  22.  
  23.    CalcReg(00000)                  //insert your reg. no. here
  24.    Set Key K_ALT_O to Calculator
  25.  
  26.    CalcInit("W+/R")                //try a Red Calculator
  27.  
  28.    //This will cause F2 to multiply anything by 2
  29.    SetKey(K_F2,{|p,line,var,no| If(p="CALCULATOR", no * 2, NIL)})
  30.  
  31.    //This will cause F3 to do a square root
  32.    SetKey(K_F3,{|p,line,var,no| If(p="CALCULATOR", Sqrt(no), NIL)})
  33.  
  34.    //This will cause the $ dollar sign to set fixed decimals to 2
  35.    SetKey(Asc("$"),{|p|If(p="CALCULATOR", "F2", NIL)})
  36.  
  37.    //This will cause the calc to call CalcProc() when beginning and when
  38.    // ending to display a personalized help screen.
  39.    CalcUDF({|a,b,c,d,e,f,g,h|CalcProc(a,b,c,d,e,f,g,h)})
  40.  
  41.    nInteger :=7
  42.    nDontWork:=6
  43.    nAnother:=-5
  44.    nFloating:=1.23
  45.    cText    :=Space(8)
  46.  
  47.    @ 9,5 Get nInteger
  48.    @10,5 Get nDontWork
  49.    @11,5 Get nAnother
  50.    @12,5 Get nFloating
  51.    @13,5 Get cText
  52.  
  53.    @ 9,20 Say     "< The integer will transfer to the calculator."
  54.    @10,20 Say     "< You can disable the calculator on specific fields."
  55.    @11,20 Say     "< Negative."
  56.    @12,20 Say     "< Floating Point transfer and return (Ctrl-Enter)."
  57.    @13,20 Say     "< Text pasting. (press Ctrl-Enter inside calculator)."
  58.  
  59.    @15,5 Say "Press ALT-O to access the calculator"
  60.  
  61.    READ
  62.  
  63.    CLS
  64.    @ 2,0,24,79 Box F_BLOCKS
  65.  
  66.    @ 3,2 Say "There are hundreds of users of the calculator including:"
  67.  
  68.    @ 5,2 Say "UPS"
  69.    @ 6,2 Say "JPL"
  70.    @ 7,2 Say "Statewide Insurance"
  71.    @ 7,2 Say "Transamerica Insurance Group"
  72.    @ 8,2 Say "Marriott Services"
  73.    @ 9,2 Say "Interamerican Development Bank"
  74.    @10,2 Say "First National Bank"
  75.    @11,2 Say " and many more including software development firms"
  76.  
  77.    @13,2 Say "And we're happy that banks and insurance companies can trust this to be the"
  78.    @14,2 Say "'Best Calculator by far for Clipper.'"
  79.  
  80.    @16,2 Say "So if you want to put the calculator to use for your users,"
  81.    @17,2 Say "then (1) try it out by linking it to your program, and"
  82.    @18,2 Say "     (2) review REGISTER.DOC for receiving your license"
  83.  
  84.    @20,2 Say "And... you can even receive your registration number to"
  85.    @21,2 Say "       activate your copy (no copyright message) by phone!"
  86.  
  87.    @23,2 Say "Touchstone Business Creations (909) 679-3364 voice   (909) 672-2731 fax"
  88.  
  89.    SetColor("W/N")
  90.    Scroll(0,0,MaxRow(),MaxCol(),1)
  91.    SetCursor(1)
  92.    SetPos(MaxRow(),0)
  93.  
  94. Return NIL
  95.  
  96.  
  97. Function CalcProc(cProc, nVer, cVar, nDisp, cDisp, nMode, cColor, nKey)
  98. * cProc     = Procedure (always "CALCULATOR")
  99. * nVer      = Version number (10 through 21, for ver 1.0 through ver 2.1)
  100. * cVar      = Variable name of GET field called from
  101. * nDisp     = Numeric display of calculator
  102. * cDisp     = Character display of calculator
  103. * nMode     = Either 0 for INIT, 1 for ALLKEYS, or 2 for END
  104. * cColor    = Color when entering calculator
  105. * nKey      = Lastkey pressed
  106.  
  107. Static cSaveScreen
  108. Local xRetVal
  109.  
  110.    If nMode = 0 //INIT: called going into the calculator
  111.  
  112.       //First, if this variable is "nDontWork," then abort (no calculator)
  113.       If cVar = "NDONTWORK"
  114.          Return .T.           // True = ABORT CALC
  115.       Endif
  116.  
  117.       //Everything ok, change color to W+/B (if color display)
  118.       // Also, NO need to SAVE COLOR, calculator does that.
  119.       If(IsColor(),SetColor("W+/B"),NIL)
  120.  
  121.       //Everything ok, save screen, popup help screen
  122.       cSaveScreen:=SaveScreen(0,29,7,51)
  123.       @ 0,29 to 7,51 Double
  124.       @ 1,30 Say " F2 = Display x 2    "
  125.       @ 2,30 Say " F3 = Square Root    "
  126.       @ 3,30 Say "  $ = Fix 2 decimals "
  127.       @ 4,30 Say "  H = Calculator Help"
  128.       @ 5,30 Say " F9 = Add Tax to val "
  129.       @ 6,30 Say " F10= Put Tax in Mem "
  130.  
  131.       xRetVal := "F3" //fix decimals to 3 on INITIAL CALL
  132.  
  133.    Elseif nMode=3 //TERM: called going out of the calculator
  134.  
  135.       RestScreen(0,29,7,51,cSaveScreen)
  136.  
  137.    Elseif nMode=2 //Key Exception
  138.  
  139.       Do Case
  140.          Case nKey = K_F9   //multiply TAX to current value
  141.             xRetVal := nDisp * 1.0775
  142.  
  143.          Case nKey = K_F10  //stuff TAX into Memory!
  144.             CalcMemory( 1.0775 )
  145.  
  146.       Endcase
  147.  
  148.    Endif
  149.  
  150. // (On INITIAL call from the calculator, if you return a character string,
  151. //  it will be "keyboarded" into the calculator (remember Set Typeahead)).
  152.  
  153. Return xRetVal
  154.