home *** CD-ROM | disk | FTP | other *** search
/ Program Metropolis - Software Boutique 95 / SOFTWARECD.iso / procomm2 / disk2 / samples.tx_ / samples.bin
Encoding:
Text File  |  1994-06-09  |  31.4 KB  |  752 lines

  1. ;
  2. ;The following scripts and script fragments are from the 20 sections in the
  3. ;ASPECT manual Tutorial (Chapter 4). Use the cut and paste features of your
  4. ;text editor to copy parts of these fragments into your own script files.
  5. ;
  6. ;Although some of these script files can run "as is", most are only fragments
  7. ;and are meant to be included in other script files.
  8. ;
  9.  
  10. ;- Section 1 ------------------------------------------------------------------
  11.  
  12. ; Recorded script. Editing may be required.
  13. proc main
  14.    waitfor "Name: "
  15.    transmit "Jane^M"
  16.    waitfor "Password: "
  17.    transmit "Cheetah^M"
  18. endproc
  19.  
  20. ;- Section 2 ------------------------------------------------------------------
  21.  
  22. #define BBS_NUMBER "555-1234"
  23. #define PASSWD "Rosebud^M"
  24. proc main                              ; Start of main procedure.
  25.    transmit "ATDT"                     ; This is the dial command for the modem
  26.    transmit BBS_NUMBER                 ; followed by the number to call.
  27.    transmit "^M"                       ; Send a carriage return.
  28.    waitfor "Name: "                    ; Wait for name prompt.
  29.    transmit "Orson Welles^M"           ; Send your name.
  30.    waitfor "Password: "                ; Now the password prompt.
  31.    transmit PASSWD                     ; Send password.
  32.    waitfor "again: "                   ; This system wants to confirm password.
  33.    transmit PASSWD                     ; OK, why not.
  34.    alarm 2                             ; Wake up!
  35.    usermsg "OK, you're in"             ; You're on.
  36. endproc                                ; End of main procedure
  37.  
  38. ;- Section 3 ------------------------------------------------------------------
  39.  
  40. proc main                              ; Beginning of main procedure.
  41.    string Name                         ; Declare string variable called "name".
  42.  
  43.    Name = "Fred^M"                     ; Assign the value of name
  44.    transmit Name                       ; and send "Fred^M" out the port.
  45. endproc
  46.  
  47. ;- Section 3 ------------------------------------------------------------------
  48.  
  49. string Name                            ; Define the global string variable "Name".
  50.  
  51. proc main                              ; Beginning of main procedure.
  52.    Name = "Fred^M"                     ; Assign text to the variable.
  53.    call SendData                       ; Call another procedure.
  54. endproc                                ; End of main procedure.
  55.  
  56. proc SendData                          ; Procedure called by another procedure.
  57.    transmit Name                       ; Send the value of the global variable "Name".
  58.    usermsg "Done!"                     ; Put up a message box.
  59. endproc                                ; End of SendData procedure, execution
  60.                                        ; returns to calling procedure.
  61.  
  62. ;- Section 3 ------------------------------------------------------------------
  63.  
  64. proc main                              ; Beginning of main procedure.
  65.    string Name = "Fred^M"              ; Define the local string variable "Name".
  66.    call SendData with Name             ; Call another procedure, passing it
  67.                                        ; the value of name.
  68. endproc                                ; End of main procedure.
  69.  
  70. proc SendData                          ; Procedure called by another proc.
  71. param string szText                    ; Define a local variable to
  72.                                        ; contain the value passed from
  73.                                        ; another procedure.  In this case
  74.                                        ; it's a string.
  75.    transmit szText                     ; Send the value of the local variable
  76.                                        ; "szText", which is equal to the value
  77.                                        ; of name at this point.
  78.    usermsg "Done!"                     ; Message box.
  79.  
  80. endproc                                ; End of SendData procedure, execution
  81.  
  82. ;- Section 3 ------------------------------------------------------------------
  83.  
  84. ;*********************************************************************
  85. ; Main procedure.
  86. ; Calls: SendData.
  87. ; Called by:
  88. ; Modifies the value of the following globals:
  89. ;*********************************************************************
  90. proc main                              ; Beginning of main procedure.
  91.    string FirstName = "Fred^M"         ; Define local string variable "FirstName".
  92.    string LastName = "Garvin^M"        ; Define local string variable "LastName".
  93.  
  94.    call SendData with FirstName        ; Call SendData procedure, passing it
  95.                                        ; the value of FirstName.
  96.    call SendData with LastName         ; After execution returns to
  97.                                        ; main, call SendData again
  98.                                        ; passing it a different value.
  99. endproc                                ; End of main procedure.
  100.  
  101. ;*********************************************************************
  102. ; SendData procedure.
  103. ; Calls:
  104. ; Called by: main.
  105. ; Modifies the value of the following globals:
  106. ;*********************************************************************
  107. proc SendData                          ; Procedure called by another proc.
  108. param string szText                    ; Define a local variable to
  109.                                        ; contain the value passed from
  110.                                        ; another procedure.
  111.    transmit szText                     ; Send the value of the local variable
  112.                                        ; "szText", which is equal to the value
  113.                                        ; passed in from calling procedure.
  114.    usermsg "Done!"                     ; Message box.
  115.  
  116. endproc                                ; End of SendData procedure, execution
  117.                                        ; returns to caller.
  118.  
  119. ;- Section 5 ------------------------------------------------------------------
  120.  
  121. string Names[10]                       ; Declare string array with 10 elements.
  122.  
  123. proc main
  124.    integer Ages[10]                    ; Declare integer array with 10 elements.
  125.    .
  126.    .
  127. endproc
  128.  
  129. ;- Section 5 ------------------------------------------------------------------
  130.  
  131. string Names[10]                       ; Declare string array with 10 elements.
  132.  
  133. proc main
  134.    integer Ages[10]                    ; Declare integer array with 10 elements.
  135.  
  136.    Names[0] = "Johnny B. G."           ; Assign a value to the first element of
  137.                                        ; our array of names.
  138.    Ages[0] = 89                        ; Assign a value to the first element of
  139.                                        ; our array of ages.
  140. endproc
  141.  
  142. ;- Section 5 ------------------------------------------------------------------
  143.  
  144. string Names[10]                       ; Declare string array with 10 elements.
  145.  
  146. proc main
  147.    integer Ages[10]                    ; Declare integer array with 10 elements.
  148.    integer Count = 0                   ; Variable subscript used to reference our
  149.                                        ; arrays.
  150.    string szLine                       ; Variable to store line from file.
  151.    string szTemp                       ; Temporary variable used for Age.
  152.  
  153.    if fopen 0 "NAMES.LST" READ         ; Open name file for ready only.
  154.       while not feof 0                 ; Loop while we're not at end of the file.
  155.          fgets 0 szLine                ; Get a line from the file and extract the
  156.                                        ; name and age.
  157.          strtok Names[Count] szLine "," 1
  158.          strtok szTemp szLine "," 1
  159.          atoi szTemp Ages[Count]       ; Convert the age to an integer and put
  160.                                        ; it into our Ages array.
  161.          if (Count += 1) == 10         ; Increment our array subscript and make
  162.             exitwhile                  ; sure that we don't increment past the last
  163.          endif                         ; elements in the two arrays .
  164.       endwhile
  165.       fclose 0                         ; Close our file full of names.
  166.    else                                ; Display a message if an error occurred.
  167.       errormsg "Couldn't open NAMES.LST for input!"
  168.    endif
  169. endproc
  170.  
  171. ;- Section 6 ------------------------------------------------------------------
  172.  
  173. proc main
  174.    integer Test                        ; Declare a variable named "Test" of integer type.
  175.    .
  176.    .                                   ; Some code that manipulates the value of Test.
  177.    .
  178.    if Test == 5                        ; See if the variable now equals 5.
  179.       call DoThis                      ; If true, call a particular procedure.
  180.    endif                               ; End of the conditional.
  181. endproc
  182.  
  183. ;- Section 6 ------------------------------------------------------------------
  184.  
  185. #define TRUE 1
  186.  
  187. proc main
  188.    .
  189.    .                                   ; Other code here.
  190.    .
  191.    while TRUE                          ; Loop while true.
  192.    endwhile
  193. endproc
  194.  
  195. ;- Section 6 ------------------------------------------------------------------
  196.  
  197. proc main
  198.    integer Counter = 0                 ; Initialize the variable "Counter" to 0.
  199.       while Counter != 5               ; This means "while counter does *not* equal 5".
  200.       Counter++                        ; Increment the value of counter (add 1 to it)
  201.       transmit "hi"                    ; and transmit "hi".
  202.    endwhile
  203.  
  204.    transmit "^M"                       ; Send a carriage return
  205.    transmit "bye"                      ; and then the word "bye".
  206. endproc
  207.  
  208. ;- Section 6 ------------------------------------------------------------------
  209.  
  210. proc main
  211.    integer Test1 = 1                   ; Declare integer variable "Test1".
  212.    integer Test2 = 10                  ; Notice that we can initialize a variable here.
  213.  
  214.    while test1 != 5                    ; Outer loop.
  215.       while test2 > 10                 ; Inner loop.  Notice use of "greater than".
  216.          .
  217.          .
  218.          .
  219.       endwhile                         ; End of inner loop.
  220.    endwhile                            ; End of outer loop.
  221. endproc
  222.  
  223. ;- Section 7 ------------------------------------------------------------------
  224.  
  225.    integer Num = 2
  226.    Num = Square(Num)                   ; Assuming the user-defined function
  227.                                        ; "Square" works to square an integer,
  228.                                        ; it returns the value 4, so Num now has
  229.                                        ; the value 4.
  230.  
  231. ;- Section 7 ------------------------------------------------------------------
  232.  
  233. func Square : integer                  ; The function returns an integer constant.
  234. param integer Number                   ; Variable for value passed to it.
  235.  
  236.    return Number * Number              ; Return the new value of number.
  237. endfunc                                ; End of function.
  238.  
  239. ;- Section 7 ------------------------------------------------------------------
  240.  
  241. ;****************** MAIN PROCEDURE *******************
  242. proc main
  243.    string FirstName = "Ebenezer"       ; Declare string for first name.
  244.    FirstName = AddCR(FirstName)        ; Get "Ebenezer^M" from AddCR.
  245.    waitfor "Name: "                    ; Now you can wait for prompt
  246.    transmit FirstName                  ; and send string out.
  247. endproc
  248.  
  249. ;****************** ADDCR FUNCTION ******************
  250. func AddCR : string                    ; Must include return type!
  251. param string szText                    ; Define variable "szText"
  252.                                        ; for passed string.
  253.    strcat szText "^M"                  ; Add a CR to received string
  254.    return szText                       ; and return it to calling proc.
  255. endfunc
  256.  
  257. ;- Section 9 ------------------------------------------------------------------
  258.  
  259. proc main
  260.    integer Number = 0                  ; Declare a number variable.
  261.    OtherStuff( &Number )               ; Pass the variable number "by reference".
  262.    usermsg "%d" Number                 ; Display changed value.  Should be 1 now.
  263. endproc
  264.  
  265. proc OtherStuff
  266. param integer Num                      ; Variable for passed value.
  267.    .
  268.    .                                   ; The procedure does some stuff...
  269.    .
  270.    Num++                               ; One of the things it does is
  271.                                        ; increment the value passed to it
  272.                                        ; and automatically returns that to
  273.                                        ; the variable used when calling
  274.                                        ; this proc.
  275. endproc
  276.  
  277. ;- Section 10 -----------------------------------------------------------------
  278.  
  279. proc main
  280.    waitfor "CONNECT 2400" 60           ; Wait 60 seconds for a connect
  281.                                        ; message to appear at the port.
  282.    if FAILURE                          ; If the waitfor doesn't succeed
  283.       usermsg "Try again later!"       ; let the user know.
  284.    endif
  285. endproc
  286.  
  287. ;- Section 10 -----------------------------------------------------------------
  288.  
  289. proc Xfer
  290.    sendfile zmodem "abc.zip"           ; Send the file abc.zip by zmodem.
  291.    if SUCCESS                          ; If the sendfile is successful,
  292.       usermsg "Transmitting file..."   ; say so.
  293.    else
  294.       usermsg "Sorry - try again!"     ; Otherwise, put up error message.
  295.    endif
  296. endproc
  297.  
  298. ;- Section 10 -----------------------------------------------------------------
  299.  
  300. proc main
  301.    if not waitfor "CONNECT 2400" 60    ; Wait for a connect message.
  302.       usermsg "Try again later!"       ; If one isn't received, display
  303.    endif                               ; an error message.
  304. endproc
  305.  
  306. ;- Section 11 -----------------------------------------------------------------
  307.  
  308. ;*********************************************************************
  309. ; Main procedure.
  310. ; Calls: SendData.
  311. ; Called by:
  312. ; Modifies the value of the following globals:
  313. ;*********************************************************************
  314. proc main
  315.    string szPassword                   ; Local variable for string
  316.                                        ; user enters in input box.
  317.                                        ; Its value will then be
  318.                                        ; passed to the SendData
  319.                                        ; routine.
  320.  
  321.    ; The following line creates the box for user input.  The first string
  322.    ; appears in the title bar of the box; the second is the prompt
  323.    ; string that appears right before the text entry field itself; the
  324.    ; variable at the end will assume the value of the string the user
  325.    ; enters.
  326.  
  327.    sdlginput "Password Entry" "Enter your password:" szPassword
  328.    waitfor "Password: "                ; Wait for password prompt.
  329.    SendData( szPassword )              ; Call the SendData routine
  330.                                        ; with the value of the local
  331.                                        ; string variable "szPassword".
  332.                                        ; SendData adds a
  333.                                        ; carriage return and sends
  334.                                        ; user's password out the port.
  335. endproc
  336.  
  337. ;*********************************************************************
  338. ; SendData procedure.  Adds a carriage return to passed string and
  339. ; then transmits it.
  340. ;
  341. ; Calls:
  342. ; Called by: main.
  343. ; Modifies the value of the following globals:
  344. ;*********************************************************************
  345. proc SendData
  346. param string szText                    ; Local variable to receive
  347.                                        ; value passed from another
  348.                                        ; procedure.
  349.    strcat szText "^M"                  ; Strcat appends a string
  350.                                        ; onto the end of another.
  351.                                        ; In this case we stick "^M"
  352.                                        ; onto the end of the
  353.                                        ; password string.
  354.    transmit szText                     ; then send what the user
  355.                                        ; input followed by a
  356.                                        ; carriage return.
  357. endproc
  358.  
  359. ;- Section 12 -----------------------------------------------------------------
  360.  
  361. integer WhichButton                    ; Variables used in dialog box commands
  362.                                        ; must be global!  This one takes on a
  363.                                        ; particular value based on which radio
  364.                                        ; button in the group has been selected.
  365.  
  366. proc main                              ; Beginning of main procedure.
  367.    call MakeDialog                     ; Call dialog procedure and when
  368.    pause 5                             ; execution returns pause for a bit
  369. endproc                                ; and exit the script file.
  370.  
  371. proc MakeDialog
  372.    dialogbox 0 0 0 200 100 11 "Test"
  373.       radiogroup 1 WhichButton
  374.          radiobutton 2 50 20 28 10 "One"
  375.          radiobutton 3 50 38 28 10 "Two"
  376.          radiobutton 4 50 56 28 10 "Three"
  377.       endgroup
  378.       pushbutton  5 130 59 40 14 "OK"
  379.    enddialog
  380. endproc                                ; Return to proc main.
  381.  
  382. ;- Section 12 -----------------------------------------------------------------
  383.  
  384. #define TRUE 1
  385. integer WhichButton                    ; Global variable used for radio's.
  386. ;********************************************************************
  387. ; MAIN
  388. ; The main procedure calls MakeDialog to construct and display a
  389. ; dialog box.  It waits in an endless loop for a dialog
  390. ; event.  When a dialog event occurs (i.e. the user chooses a radio
  391. ; button or presses the pushbutton), the procedure CheckIt is
  392. ; called.
  393. ;
  394. ; Calls: MakeDialog, CheckIt, ShowIt
  395. ; Called by:
  396. ; Modifies global variables: None
  397. ;*********************************************************************
  398. proc main                              ; Start of main procedure.
  399.    integer Event                       ; Variable used for dialog events.
  400.    MakeDialog()                        ; Show the dialog box.
  401.  
  402.    while TRUE                          ; Sit and wait for something to happen.
  403.       dlgevent 0 Event                 ; Get dialog event for our dialog box.
  404.       switch Event                     ; Evaluate the dialog event.
  405.          case 0                        ; 0 indicates no dialog event.
  406.          endcase
  407.          case 1                        ; These case statements indicate
  408.          case 2                        ; that one the radio buttons was
  409.          case 3                        ; selected.
  410.          case 4
  411.          endcase
  412.          default                       ; This case corresponds to either an
  413.             exitwhile                  ; exit case or the OK pushbutton.
  414.          endcase
  415.       endswitch
  416.    endwhile
  417.    ShowIt()                            ; Call routine to display radio selection.
  418. endproc                                ; End of main procedure.
  419.  
  420. ;********************************************************************
  421. ; MAKEDIALOG
  422. ; This procedure constructs and displays the dialog
  423. ; box and returns to main.
  424. ;
  425. ; Calls:
  426. ; Called by: main
  427. ; Modifies global variables: WhichButton (initializes it to 0)
  428. ;*********************************************************************
  429. proc MakeDialog
  430.    WhichButton = 0                     ; Initialize WhichButton variable.
  431.    dialogbox 0 0 0 200 100 11 "Test"
  432.       radiogroup 1 WhichButton
  433.          radiobutton 2 50 20 28 10 "One"
  434.          radiobutton 3 50 38 28 10 "Two"
  435.          radiobutton 4 50 56 28 10 "Three"
  436.       endgroup
  437.       pushbutton  5 130 59 40 14 "OK"
  438.    enddialog
  439. endproc                                ; Return to proc main.
  440.  
  441. ;********************************************************************
  442. ; SHOWIT
  443. ; The ShowIt procedure checks the value of the global variable
  444. ; WhichButton after the pushbutton is pushed.  WhichButton
  445. ; is 1 if the first radio button in the group was selected,
  446. ; 2 if the second was selected, 3 if the third was selected.  A
  447. ; different message is displayed based on this value.
  448. ;
  449. ; Calls:
  450. ; Called by: main
  451. ; Modifies global variables:
  452. ;*********************************************************************
  453. proc ShowIt
  454.    string DisplayString                ; Local variable for string to
  455.                                        ; display in message box.
  456.    switch WhichButton                  ; Evaluate the WhichButton variable.
  457.       case 0
  458.          DisplayString = "none"
  459.       endcase
  460.       case 1
  461.          DisplayString = "one"
  462.       endcase
  463.       case 2
  464.          DisplayString = "two"
  465.       endcase
  466.       case 3
  467.          DisplayString = "three"
  468.       endcase
  469.    endswitch
  470.  
  471.    usermsg "Radio button %s was selected." DisplayString
  472. endproc
  473.  
  474. ;- Section 13 -----------------------------------------------------------------
  475.  
  476. #define TRUE 1
  477. string ABARLeft                        ; Name of the left icon bar.
  478.  
  479. proc main
  480.    fetch actionbar left ABARLeft       ; Get the current left Action Bar.
  481.    set actionbar left ""               ; Turn off the left Action Bar.
  482.  
  483.    when USEREXIT call ResetAbar        ; Wait for a user exit event.
  484.    set aspect path $PWTASKPATH
  485.  
  486.    ; Create a user window on which to display our icons for our left
  487.    ; icon bar.  The NPW.DLL file is where <M>PROCOMM PLUS
  488.    ; <M>for Windows gets its icons.
  489.  
  490.    uwincreate LEFT PIXELS 42 128 128 128 BITMAP
  491.       iconbutton 1 0 0 "" "npw.dll" 6 BACKGROUND
  492.       iconbutton 2 0 390 "" "npw.dll" 29 BACKGROUND
  493.       iconbutton 3 0 780 "" "npw.dll" 26 BACKGROUND
  494.       iconbutton 4 0 1170 "" "npw.dll" 86 BACKGROUND
  495.       iconbutton 5 0 1560 "" "npw.dll" 74 BACKGROUND
  496.       iconbutton 6 0 1950 "" "npw.dll" 75 BACKGROUND
  497.    uwinpaint                           ; Draw the new user window.
  498.  
  499.    while TRUE                          ; Loop forever.
  500.       switch $OBJECT                   ; Evaluate the uwin event.
  501.          case 1                        ; Dialing directory selected.
  502.             sendkey ALT 'D'
  503.          endcase
  504.          case 2                        ; Setup selected.
  505.             sendkey ALT 'S'
  506.          endcase
  507.          case 3                        ; Scrollback selected.
  508.             sendvkey 0x0C26
  509.          endcase
  510.          case 4                        ; Hangup selected.
  511.             hangup
  512.          endcase
  513.          case 5                        ; Send file selected.
  514.             sendkey ALT 'O'
  515.             sendkey 'S'
  516.          endcase
  517.          case 6                        ; Receive file selected.
  518.             sendkey ALT 'O'
  519.             sendkey 'R'
  520.          endcase
  521.       endswitch
  522.    endwhile                            ; Bottom of loop.
  523. endproc                                ; End of proc main.
  524.  
  525. proc ResetAbar
  526.    set actionbar left ABARLeft         ; Restore the left Action Bar.
  527.    exit
  528. endproc                                ; End of ResetAbar procedure.
  529.  
  530. ;- Section 14 -----------------------------------------------------------------
  531.  
  532. proc main
  533.    ; Declare a when command that watches for the prompt and calls
  534.    ; another procedure to send a carriage return.
  535.  
  536.    when TARGET 0 " Press Enter " call PressEnter
  537.  
  538.    while $CARRIER                      ; Loop while connected.
  539.    endwhile
  540.  
  541.    when TARGET 0 CLEAR                 ; Clear the when clause.
  542. endproc
  543.  
  544. proc PressEnter
  545.    transmit "^M"                       ; Send a carriage return.
  546. endproc
  547.  
  548. ;- Section 15 -----------------------------------------------------------------
  549.  
  550. #define TRUE 1
  551. proc main
  552.    PointerChanged()                    ; Display beginning message on the
  553.                                        ; status line and set up our whens.
  554.    when $POINTERX call PointerChanged  ; Watch the $POINTERX value.
  555.    when $POINTERY call PointerChanged  ; Watch the $POINTERY value.
  556.  
  557.    while TRUE                          ; Loop forever.
  558.    endwhile
  559. endproc
  560.  
  561. proc PointerChanged                    ; Procedure that displays the mouse
  562.                                        ; pointers location on the status line.
  563.    statmsg "( %d, %d )" $POINTERX $POINTERY
  564. endproc
  565.  
  566. ;- Section 16 -----------------------------------------------------------------
  567.  
  568. #define RUNPATH "c:\windows\notepad phones.txt"
  569. proc main
  570.    string szAreaCode = "314"           ; String to search for.
  571.    run RUNPATH                         ; Run "notepad phones.txt".
  572.    sendkey ALT 'S'                     ; Alt S (for Search).
  573.    sendkeystr "f"                      ; F for Find.
  574.    sendkeystr szAreaCode               ; What to look for
  575.    sendkey 13                          ; followed by Enter,
  576.    sendkey 27                          ; then Esc to get out
  577.                                        ; of searching.
  578. endproc
  579.  
  580. ;- Section 17 -----------------------------------------------------------------
  581.  
  582. ; File MAIN.WAS
  583. proc main
  584.    S0 = "hello"                        ; Assign S0 the value "hello"
  585.    usermsg S0                          ; and display it.
  586.    execute "change.wax"                ; Call the file that manipulates S0
  587.    usermsg S0                          ; and show the changed value.
  588.                                        ; Should be "goodbye" now.
  589. endproc
  590.  
  591. ; File CHANGE.WAS
  592. proc main
  593.    S0 = "goodbye"                      ; Reassign S0 the value "goodbye"
  594. endproc                                ; and return to parent.
  595.  
  596. ;- Section 19 -----------------------------------------------------------------
  597.  
  598. #define _MAX_ROWS     $TERMROWS        ; Declare a macro that represents the
  599.                                        ; maximum number of rows on the screen.
  600. proc main
  601.    integer CurrentRow                  ; Declare an integer variable that we can
  602.                                        ; use to count through each row on the
  603.                                        ; screen.
  604.    for CurrentRow = 0 upto _MAX_ROWS - 1  ; Loop through all of the rows on
  605.       termputs CurrentRow 0 "Awesome!" ; the screen and display a text
  606.                                        ; string.
  607.    endfor
  608. endproc
  609.  
  610. ;- Section 19 -----------------------------------------------------------------
  611.  
  612. #define _DO_MSG( a )     sdlgmsgbox "Script Message" a STOP OK I0
  613.  
  614. proc main
  615.    _DO_MSG( "Display me!" )            ; Use our macro to display a message
  616.                                        ; using the sdlgmsgbox command.
  617. endproc
  618.  
  619. ;- Section 19 -----------------------------------------------------------------
  620.  
  621. proc SendCommands
  622.    long SysChan                        ; Variable used for link handle.
  623.  
  624.    ddeinit SysChan "excel" "system"    ; Set up a link to Excel.
  625.    ddeexecute SysChan "[APP.RESTORE()]"   ; These are commands that
  626.    ddeexecute SysChan "[APP.MOVE(0,0)]"   ; Excel accepts to size
  627.    ddeexecute SysChan "[APP.SIZE(530,180)]"  ; its window, format
  628.    ddeexecute SysChan "[FULL(TRUE)]"      ; columns, etc.
  629.    ddeexecute SysChan "[COLUMN.WIDTH(75)]"
  630. endproc
  631.  
  632. ;- Section 19 -----------------------------------------------------------------
  633.  
  634.    long SysChan = 0                    ; Handle to Excel system.
  635.    long DDEChan = 0                    ; Handle to DDE channel.
  636.  
  637.    ddeinit DDEChan "excel" "test.xls"  ; Initiate DDE link with
  638.    if DDEChan == 0                     ; spreadsheet.  If no link
  639.       usermsg "Unable to establish link"  ; established, tell user and
  640.       exit                             ; leave.
  641.    endif
  642.    ddeinit SysChan "excel" "system"    ; Establish execute channel.
  643.    ddeexecute SysChan "[SELECT(`"R1C1`")]"   ; Move active cell to A1.
  644.                                        ; Notice the backticks (`)
  645.                                        ; to indicate literal quote
  646.                                        ; marks.
  647.    ddepoke DDEChan "R1C1" "Test"       ; A1 now contains "Test".
  648.  
  649. ;- Section 19 -----------------------------------------------------------------
  650.  
  651. #define TRUE 1
  652. long DDEChan                           ; Handle to the DDE channel.
  653.  
  654. proc main
  655.    .
  656.    .
  657.    ddeinit ddechan "excel" "sheet1"    ; Establish DDE link.
  658.    ddeadvise ddechan "R1C1" s0         ; Set up hot link to R1, C1.
  659.    when $DDEADVISE call ShowMessage    ; Call ShowMessage when the
  660.                                        ; cell is updated in Excel.
  661.    while TRUE                          ; Loop forever.
  662.    .
  663.    .
  664.    .
  665.    endwhile
  666. endproc
  667.  
  668. proc ShowMessage
  669.    usermsg "The value of cell A1 has changed."
  670. endproc
  671.  
  672. ;- Section 19 -----------------------------------------------------------------
  673.  
  674.    integer UserCommand = 1             ; Command to pass to receiver.
  675.    string szText = "This is the first command." ; Text to send to receiver.
  676.    integer Len = 26                    ; Length of string to send.
  677.  
  678.    pkmode ON 30 60                     ; Turn on packet mode.
  679.    pksend UserCommand szText Len       ; Send packet to receiver.
  680.  
  681.    .
  682.    when $PKSEND call ProcessSend       ; When the status of the $PKSEND
  683.    .                                   ; system variable changes, letting
  684.    .                                   ; you know the status of the send,
  685.    .                                   ; call a proc to see what happened.
  686.  
  687. proc ProcessSend                       ; Proc determines the status of the packet
  688.    switch $PKSEND                      ; by checking system variable $PKSEND
  689.       case 0                           ; If $PKSEND == 0, send is in progress
  690.       endcase                          ; or idle.
  691.       case 1                           ; If $PKSEND == 1, packet sent,
  692.          SendNext()                    ; the receiver has the packet.
  693.       endcase
  694.       case 2                           ; Timeout has occurred so warn user.
  695.          DoTimeout()                   ; (The receiver is dead or lost)
  696.       endcase
  697.       case 3                           ; Errors during transmission.
  698.          Notify(_COMERROR)             ; Tell us about the error.
  699.       endcase
  700.       case 4                           ; Send cancelled by receiver.
  701.          Notify(_CANCEL)               ; Tell us about the cancel request.
  702.       endcase
  703.    endswitch
  704. endproc
  705.  
  706. ;- Section 19 -----------------------------------------------------------------
  707.  
  708.    pkmode ON 30 120                    ; Turn on packet mode.
  709.    when $PKRECV call ProcessRecv       ; Watch for incoming packets!
  710.    while TRUE
  711.       .
  712.       .
  713.       .
  714.    endwhile
  715.    .
  716.    .
  717.    .
  718.  
  719. proc ProcessRecv                       ; Determines the status of the packet
  720.    switch $PKRECV                      ; by checking system variable $PKSEND.
  721.       case 0                           ; If $PKRECV == 0, packet not received.
  722.       endcase
  723.       case 1                           ; If $PKRECV == 1, packet received OK,
  724.          ReadPacket()                  ; extract the information from it.
  725.       endcase
  726.       case 2                           ; Timeout has occurred.
  727.          Notify(_TIMEOUT)              ; Warn user about the error.
  728.       endcase
  729.       case 3                           ; Errors occurred during the receive.
  730.          Notify(_COMERROR)             ; Warn user about the problem.
  731.     endcase
  732.  endswitch
  733. endproc
  734.  
  735. proc ReadPacket
  736.    integer Command                     ; Command sent with packet.
  737.    string RecvString                   ; String sent with packet.
  738.    integer PktLength                   ; Length of the data in packet.
  739.  
  740.    switch Command                      ; Switch case to evaluate the
  741.       .                                ; command passed with the packet.
  742.       .
  743.    endswitch
  744.    ProcessData(RecvString)             ; Look at the string sent with packet.
  745.    switch PktLength                    ; Possibly evaluate the length of the
  746.       .                                ; packet to perform some other actions.
  747.       .
  748.    endswitch
  749. endproc
  750.  
  751.  
  752.