home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / kpwdemo.zip / DDESHOWD.SRC < prev    next >
Text File  |  1990-06-28  |  4KB  |  140 lines

  1. w1 is window (,15,2,50,23,,[popup,showChildren,Siblings,DialogFrame]).
  2. text ( '
  3.  This KB provides an example of using
  4.  DDE with Microsoft Excel.  In the example
  5.  Excel is loaded, KnowledgePro asks the
  6.  user to enter a value, the value is written
  7.  to an Excel spreadsheet and, an Excel 
  8.  graph is displayed.
  9.  
  10.  The KB assumes that Excel and ddeshow.xls
  11.  can be reached from the current path.  If not,
  12.  you should change the KB to list the correct
  13.  path before running the KB. 
  14.  
  15.  Be sure Excel is enabled to receive DDE 
  16.  requests. This is done from the Options
  17.  menu of Excel.').
  18.  
  19. b1 is button ('Continue',continue,9,19).
  20. button ('Cancel',cancel,30,19,11).
  21. show_window (?w1).
  22. set_focus (?b1).
  23. wait ().
  24. resize_window (?w1, 50, 10).
  25. move_window (?w1,3,2).
  26. set_text (,'#e
  27.  
  28.  
  29.      One moment ..... Loading Microsoft Excel
  30.                 and current sales figures').
  31.  
  32. (***** Load Excel and save its task handle. Use TASK_WINDOWS to find the
  33.        main window of Excel. Next, open two DDE channels to Excel.
  34.        The first channel lets you read and write from a spreadsheet.
  35.        The second channel lets you execute commands in Excel.
  36. *****)
  37. current is current_directory ().
  38. ExcelTask is load_program ('EXCEL ddeshow.xls',0).
  39. if ?excelTask < 32 
  40.    then error ().
  41. ExcelWindow is first (task_windows (?ExcelTask)).  
  42. Macro1 is dde_open (ExcelTopic,Excel,System). 
  43.  
  44. (***** Here we ask the user of the knowledge base for a figure for this
  45.        month's unit sales. The value is written into the spreadsheet DDESHOW,
  46.        the sales from the last period is read from the spreadsheet and,
  47.        if the monthly figure has dropped, KnowledgePro tells Excel to
  48.        display a graph of the figures. 
  49. *****)
  50.  
  51. Sales is dde_open (ExcelTopic,Excel,'ddeshow.xls'). 
  52. dde_execute (?Macro1,['[APP.MOVE(120,130)]','[APP.SIZE(360,200)]']).
  53. dde_execute (?Macro1,['[SELECT("R1C1:R2C7")]','[NEW(2)]','[FULL(TRUE)]']).
  54. wait (,1).
  55. show_window (?ExcelWindow,1).
  56. set_display_window (?w1).
  57. set_active_window (?w1).
  58. ask ('
  59.  
  60.      What are the unit sales for July?
  61.  
  62.                
  63.  
  64.      KnowledgePro will tell Excel to graph the
  65.      new sales figures.#x5#y5',NewSales).
  66. dde_write (?Sales,r2c7,?NewSales).
  67. dde_request (?Sales,'r2c6').
  68. wait ().
  69. newRequest ().
  70.  
  71. topic newRequest.
  72.    set_display_window (?w1).
  73.    down is ' This month''s unit sales have #fred DECREASED#d.
  74.  
  75.   Re-Enter unit sales:  '.
  76.    up is ' This month''s unit sales have #fblue INCREASED#d.
  77.  
  78.   Re-Enter unit sales:  '.
  79.    if ?newSales < ?lastMonth
  80.        then text (#e,?down)
  81.        else text (#e,?up).
  82.    ed1 is edit_line (?newSales).
  83.    button (Ok,ok,15,6,6).
  84.    button (Quit,quit,25,6).
  85.    set_focus (?ed1).
  86.  
  87.    topic ok.
  88.       newSales is get_text (?ed1).
  89.       set_display_window (?w1).
  90.       if ?newSales < ?lastMonth 
  91.           then set_text (?w1,?down) 
  92.           else set_text (?w1,?up).
  93.       dde_write (?Sales,r2c7,?newSales).
  94.       set_focus (?ed1).
  95.    end.
  96.  
  97.    topic Quit.
  98.       set_text (?w1,'#e
  99.  
  100.  
  101.      One moment ..... Unloading Microsoft Excel').
  102.       dde_close (?Sales).
  103.       dde_execute (?Macro1,['[CLOSE(FALSE)]','[CLOSE(FALSE)]','[QUIT()]']).
  104.       wait (,1).
  105.       new_kb ('demo.ckb').
  106.    end.        
  107.   
  108. end. (* newRequest *)  
  109.  
  110.  
  111. (**** This is the DDE Topic which is defined when the DDE channel is
  112.         opened using dde_open.  Whenever a DDE event occurs, this topic
  113.         is called and is passed information about the event. 
  114. *****)
  115.  
  116. topic ExcelTopic (info,event, handle).
  117.   if element (?info,2) is r2c6
  118.      then lastMonth is first (?info) and
  119.              continue ().
  120. end.
  121.  
  122. topic error.
  123.   window (,27.42,5.187,37,10.93,,[popup,showChildren,siblings,DialogFrame]).
  124.   warn is load_icon (exclamation_icon).
  125.   text ('
  126.     Excel cannot be found. Please
  127.     put its directory in your path
  128.     before running this example.
  129.  ').
  130.   icon (?warn,8,7).
  131.   b1 is button ('Continue',continue,21,7,).
  132.   show_window ().
  133.   set_focus (?b1).
  134.   wait ().
  135.   new_kb ( concat (?current,'demo.ckb')).
  136. end.
  137.  
  138. topic cancel.
  139.   new_kb ('demo.ckb').
  140. end.