home *** CD-ROM | disk | FTP | other *** search
- ;
- ;The following scripts and script fragments are from the 20 sections in the
- ;ASPECT manual Tutorial (Chapter 4). Use the cut and paste features of your
- ;text editor to copy parts of these fragments into your own script files.
- ;
- ;Although some of these script files can run "as is", most are only fragments
- ;and are meant to be included in other script files.
- ;
-
- ;- Section 1 ------------------------------------------------------------------
-
- ; Recorded script. Editing may be required.
- proc main
- waitfor "Name: "
- transmit "Jane^M"
- waitfor "Password: "
- transmit "Cheetah^M"
- endproc
-
- ;- Section 2 ------------------------------------------------------------------
-
- #define BBS_NUMBER "555-1234"
- #define PASSWD "Rosebud^M"
- proc main ; Start of main procedure.
- transmit "ATDT" ; This is the dial command for the modem
- transmit BBS_NUMBER ; followed by the number to call.
- transmit "^M" ; Send a carriage return.
- waitfor "Name: " ; Wait for name prompt.
- transmit "Orson Welles^M" ; Send your name.
- waitfor "Password: " ; Now the password prompt.
- transmit PASSWD ; Send password.
- waitfor "again: " ; This system wants to confirm password.
- transmit PASSWD ; OK, why not.
- alarm 2 ; Wake up!
- usermsg "OK, you're in" ; You're on.
- endproc ; End of main procedure
-
- ;- Section 3 ------------------------------------------------------------------
-
- proc main ; Beginning of main procedure.
- string Name ; Declare string variable called "name".
-
- Name = "Fred^M" ; Assign the value of name
- transmit Name ; and send "Fred^M" out the port.
- endproc
-
- ;- Section 3 ------------------------------------------------------------------
-
- string Name ; Define the global string variable "Name".
-
- proc main ; Beginning of main procedure.
- Name = "Fred^M" ; Assign text to the variable.
- call SendData ; Call another procedure.
- endproc ; End of main procedure.
-
- proc SendData ; Procedure called by another procedure.
- transmit Name ; Send the value of the global variable "Name".
- usermsg "Done!" ; Put up a message box.
- endproc ; End of SendData procedure, execution
- ; returns to calling procedure.
-
- ;- Section 3 ------------------------------------------------------------------
-
- proc main ; Beginning of main procedure.
- string Name = "Fred^M" ; Define the local string variable "Name".
- call SendData with Name ; Call another procedure, passing it
- ; the value of name.
- endproc ; End of main procedure.
-
- proc SendData ; Procedure called by another proc.
- param string szText ; Define a local variable to
- ; contain the value passed from
- ; another procedure. In this case
- ; it's a string.
- transmit szText ; Send the value of the local variable
- ; "szText", which is equal to the value
- ; of name at this point.
- usermsg "Done!" ; Message box.
-
- endproc ; End of SendData procedure, execution
-
- ;- Section 3 ------------------------------------------------------------------
-
- ;*********************************************************************
- ; Main procedure.
- ; Calls: SendData.
- ; Called by:
- ; Modifies the value of the following globals:
- ;*********************************************************************
- proc main ; Beginning of main procedure.
- string FirstName = "Fred^M" ; Define local string variable "FirstName".
- string LastName = "Garvin^M" ; Define local string variable "LastName".
-
- call SendData with FirstName ; Call SendData procedure, passing it
- ; the value of FirstName.
- call SendData with LastName ; After execution returns to
- ; main, call SendData again
- ; passing it a different value.
- endproc ; End of main procedure.
-
- ;*********************************************************************
- ; SendData procedure.
- ; Calls:
- ; Called by: main.
- ; Modifies the value of the following globals:
- ;*********************************************************************
- proc SendData ; Procedure called by another proc.
- param string szText ; Define a local variable to
- ; contain the value passed from
- ; another procedure.
- transmit szText ; Send the value of the local variable
- ; "szText", which is equal to the value
- ; passed in from calling procedure.
- usermsg "Done!" ; Message box.
-
- endproc ; End of SendData procedure, execution
- ; returns to caller.
-
- ;- Section 5 ------------------------------------------------------------------
-
- string Names[10] ; Declare string array with 10 elements.
-
- proc main
- integer Ages[10] ; Declare integer array with 10 elements.
- .
- .
- endproc
-
- ;- Section 5 ------------------------------------------------------------------
-
- string Names[10] ; Declare string array with 10 elements.
-
- proc main
- integer Ages[10] ; Declare integer array with 10 elements.
-
- Names[0] = "Johnny B. G." ; Assign a value to the first element of
- ; our array of names.
- Ages[0] = 89 ; Assign a value to the first element of
- ; our array of ages.
- endproc
-
- ;- Section 5 ------------------------------------------------------------------
-
- string Names[10] ; Declare string array with 10 elements.
-
- proc main
- integer Ages[10] ; Declare integer array with 10 elements.
- integer Count = 0 ; Variable subscript used to reference our
- ; arrays.
- string szLine ; Variable to store line from file.
- string szTemp ; Temporary variable used for Age.
-
- if fopen 0 "NAMES.LST" READ ; Open name file for ready only.
- while not feof 0 ; Loop while we're not at end of the file.
- fgets 0 szLine ; Get a line from the file and extract the
- ; name and age.
- strtok Names[Count] szLine "," 1
- strtok szTemp szLine "," 1
- atoi szTemp Ages[Count] ; Convert the age to an integer and put
- ; it into our Ages array.
- if (Count += 1) == 10 ; Increment our array subscript and make
- exitwhile ; sure that we don't increment past the last
- endif ; elements in the two arrays .
- endwhile
- fclose 0 ; Close our file full of names.
- else ; Display a message if an error occurred.
- errormsg "Couldn't open NAMES.LST for input!"
- endif
- endproc
-
- ;- Section 6 ------------------------------------------------------------------
-
- proc main
- integer Test ; Declare a variable named "Test" of integer type.
- .
- . ; Some code that manipulates the value of Test.
- .
- if Test == 5 ; See if the variable now equals 5.
- call DoThis ; If true, call a particular procedure.
- endif ; End of the conditional.
- endproc
-
- ;- Section 6 ------------------------------------------------------------------
-
- #define TRUE 1
-
- proc main
- .
- . ; Other code here.
- .
- while TRUE ; Loop while true.
- endwhile
- endproc
-
- ;- Section 6 ------------------------------------------------------------------
-
- proc main
- integer Counter = 0 ; Initialize the variable "Counter" to 0.
- while Counter != 5 ; This means "while counter does *not* equal 5".
- Counter++ ; Increment the value of counter (add 1 to it)
- transmit "hi" ; and transmit "hi".
- endwhile
-
- transmit "^M" ; Send a carriage return
- transmit "bye" ; and then the word "bye".
- endproc
-
- ;- Section 6 ------------------------------------------------------------------
-
- proc main
- integer Test1 = 1 ; Declare integer variable "Test1".
- integer Test2 = 10 ; Notice that we can initialize a variable here.
-
- while test1 != 5 ; Outer loop.
- while test2 > 10 ; Inner loop. Notice use of "greater than".
- .
- .
- .
- endwhile ; End of inner loop.
- endwhile ; End of outer loop.
- endproc
-
- ;- Section 7 ------------------------------------------------------------------
-
- integer Num = 2
- Num = Square(Num) ; Assuming the user-defined function
- ; "Square" works to square an integer,
- ; it returns the value 4, so Num now has
- ; the value 4.
-
- ;- Section 7 ------------------------------------------------------------------
-
- func Square : integer ; The function returns an integer constant.
- param integer Number ; Variable for value passed to it.
-
- return Number * Number ; Return the new value of number.
- endfunc ; End of function.
-
- ;- Section 7 ------------------------------------------------------------------
-
- ;****************** MAIN PROCEDURE *******************
- proc main
- string FirstName = "Ebenezer" ; Declare string for first name.
- FirstName = AddCR(FirstName) ; Get "Ebenezer^M" from AddCR.
- waitfor "Name: " ; Now you can wait for prompt
- transmit FirstName ; and send string out.
- endproc
-
- ;****************** ADDCR FUNCTION ******************
- func AddCR : string ; Must include return type!
- param string szText ; Define variable "szText"
- ; for passed string.
- strcat szText "^M" ; Add a CR to received string
- return szText ; and return it to calling proc.
- endfunc
-
- ;- Section 9 ------------------------------------------------------------------
-
- proc main
- integer Number = 0 ; Declare a number variable.
- OtherStuff( &Number ) ; Pass the variable number "by reference".
- usermsg "%d" Number ; Display changed value. Should be 1 now.
- endproc
-
- proc OtherStuff
- param integer Num ; Variable for passed value.
- .
- . ; The procedure does some stuff...
- .
- Num++ ; One of the things it does is
- ; increment the value passed to it
- ; and automatically returns that to
- ; the variable used when calling
- ; this proc.
- endproc
-
- ;- Section 10 -----------------------------------------------------------------
-
- proc main
- waitfor "CONNECT 2400" 60 ; Wait 60 seconds for a connect
- ; message to appear at the port.
- if FAILURE ; If the waitfor doesn't succeed
- usermsg "Try again later!" ; let the user know.
- endif
- endproc
-
- ;- Section 10 -----------------------------------------------------------------
-
- proc Xfer
- sendfile zmodem "abc.zip" ; Send the file abc.zip by zmodem.
- if SUCCESS ; If the sendfile is successful,
- usermsg "Transmitting file..." ; say so.
- else
- usermsg "Sorry - try again!" ; Otherwise, put up error message.
- endif
- endproc
-
- ;- Section 10 -----------------------------------------------------------------
-
- proc main
- if not waitfor "CONNECT 2400" 60 ; Wait for a connect message.
- usermsg "Try again later!" ; If one isn't received, display
- endif ; an error message.
- endproc
-
- ;- Section 11 -----------------------------------------------------------------
-
- ;*********************************************************************
- ; Main procedure.
- ; Calls: SendData.
- ; Called by:
- ; Modifies the value of the following globals:
- ;*********************************************************************
- proc main
- string szPassword ; Local variable for string
- ; user enters in input box.
- ; Its value will then be
- ; passed to the SendData
- ; routine.
-
- ; The following line creates the box for user input. The first string
- ; appears in the title bar of the box; the second is the prompt
- ; string that appears right before the text entry field itself; the
- ; variable at the end will assume the value of the string the user
- ; enters.
-
- sdlginput "Password Entry" "Enter your password:" szPassword
- waitfor "Password: " ; Wait for password prompt.
- SendData( szPassword ) ; Call the SendData routine
- ; with the value of the local
- ; string variable "szPassword".
- ; SendData adds a
- ; carriage return and sends
- ; user's password out the port.
- endproc
-
- ;*********************************************************************
- ; SendData procedure. Adds a carriage return to passed string and
- ; then transmits it.
- ;
- ; Calls:
- ; Called by: main.
- ; Modifies the value of the following globals:
- ;*********************************************************************
- proc SendData
- param string szText ; Local variable to receive
- ; value passed from another
- ; procedure.
- strcat szText "^M" ; Strcat appends a string
- ; onto the end of another.
- ; In this case we stick "^M"
- ; onto the end of the
- ; password string.
- transmit szText ; then send what the user
- ; input followed by a
- ; carriage return.
- endproc
-
- ;- Section 12 -----------------------------------------------------------------
-
- integer WhichButton ; Variables used in dialog box commands
- ; must be global! This one takes on a
- ; particular value based on which radio
- ; button in the group has been selected.
-
- proc main ; Beginning of main procedure.
- call MakeDialog ; Call dialog procedure and when
- pause 5 ; execution returns pause for a bit
- endproc ; and exit the script file.
-
- proc MakeDialog
- dialogbox 0 0 0 200 100 11 "Test"
- radiogroup 1 WhichButton
- radiobutton 2 50 20 28 10 "One"
- radiobutton 3 50 38 28 10 "Two"
- radiobutton 4 50 56 28 10 "Three"
- endgroup
- pushbutton 5 130 59 40 14 "OK"
- enddialog
- endproc ; Return to proc main.
-
- ;- Section 12 -----------------------------------------------------------------
-
- #define TRUE 1
- integer WhichButton ; Global variable used for radio's.
- ;********************************************************************
- ; MAIN
- ; The main procedure calls MakeDialog to construct and display a
- ; dialog box. It waits in an endless loop for a dialog
- ; event. When a dialog event occurs (i.e. the user chooses a radio
- ; button or presses the pushbutton), the procedure CheckIt is
- ; called.
- ;
- ; Calls: MakeDialog, CheckIt, ShowIt
- ; Called by:
- ; Modifies global variables: None
- ;*********************************************************************
- proc main ; Start of main procedure.
- integer Event ; Variable used for dialog events.
- MakeDialog() ; Show the dialog box.
-
- while TRUE ; Sit and wait for something to happen.
- dlgevent 0 Event ; Get dialog event for our dialog box.
- switch Event ; Evaluate the dialog event.
- case 0 ; 0 indicates no dialog event.
- endcase
- case 1 ; These case statements indicate
- case 2 ; that one the radio buttons was
- case 3 ; selected.
- case 4
- endcase
- default ; This case corresponds to either an
- exitwhile ; exit case or the OK pushbutton.
- endcase
- endswitch
- endwhile
- ShowIt() ; Call routine to display radio selection.
- endproc ; End of main procedure.
-
- ;********************************************************************
- ; MAKEDIALOG
- ; This procedure constructs and displays the dialog
- ; box and returns to main.
- ;
- ; Calls:
- ; Called by: main
- ; Modifies global variables: WhichButton (initializes it to 0)
- ;*********************************************************************
- proc MakeDialog
- WhichButton = 0 ; Initialize WhichButton variable.
- dialogbox 0 0 0 200 100 11 "Test"
- radiogroup 1 WhichButton
- radiobutton 2 50 20 28 10 "One"
- radiobutton 3 50 38 28 10 "Two"
- radiobutton 4 50 56 28 10 "Three"
- endgroup
- pushbutton 5 130 59 40 14 "OK"
- enddialog
- endproc ; Return to proc main.
-
- ;********************************************************************
- ; SHOWIT
- ; The ShowIt procedure checks the value of the global variable
- ; WhichButton after the pushbutton is pushed. WhichButton
- ; is 1 if the first radio button in the group was selected,
- ; 2 if the second was selected, 3 if the third was selected. A
- ; different message is displayed based on this value.
- ;
- ; Calls:
- ; Called by: main
- ; Modifies global variables:
- ;*********************************************************************
- proc ShowIt
- string DisplayString ; Local variable for string to
- ; display in message box.
- switch WhichButton ; Evaluate the WhichButton variable.
- case 0
- DisplayString = "none"
- endcase
- case 1
- DisplayString = "one"
- endcase
- case 2
- DisplayString = "two"
- endcase
- case 3
- DisplayString = "three"
- endcase
- endswitch
-
- usermsg "Radio button %s was selected." DisplayString
- endproc
-
- ;- Section 13 -----------------------------------------------------------------
-
- #define TRUE 1
- string ABARLeft ; Name of the left icon bar.
-
- proc main
- fetch actionbar left ABARLeft ; Get the current left Action Bar.
- set actionbar left "" ; Turn off the left Action Bar.
-
- when USEREXIT call ResetAbar ; Wait for a user exit event.
- set aspect path $PWTASKPATH
-
- ; Create a user window on which to display our icons for our left
- ; icon bar. The NPW.DLL file is where <M>PROCOMM PLUS
- ; <M>for Windows gets its icons.
-
- uwincreate LEFT PIXELS 42 128 128 128 BITMAP
- iconbutton 1 0 0 "" "npw.dll" 6 BACKGROUND
- iconbutton 2 0 390 "" "npw.dll" 29 BACKGROUND
- iconbutton 3 0 780 "" "npw.dll" 26 BACKGROUND
- iconbutton 4 0 1170 "" "npw.dll" 86 BACKGROUND
- iconbutton 5 0 1560 "" "npw.dll" 74 BACKGROUND
- iconbutton 6 0 1950 "" "npw.dll" 75 BACKGROUND
- uwinpaint ; Draw the new user window.
-
- while TRUE ; Loop forever.
- switch $OBJECT ; Evaluate the uwin event.
- case 1 ; Dialing directory selected.
- sendkey ALT 'D'
- endcase
- case 2 ; Setup selected.
- sendkey ALT 'S'
- endcase
- case 3 ; Scrollback selected.
- sendvkey 0x0C26
- endcase
- case 4 ; Hangup selected.
- hangup
- endcase
- case 5 ; Send file selected.
- sendkey ALT 'O'
- sendkey 'S'
- endcase
- case 6 ; Receive file selected.
- sendkey ALT 'O'
- sendkey 'R'
- endcase
- endswitch
- endwhile ; Bottom of loop.
- endproc ; End of proc main.
-
- proc ResetAbar
- set actionbar left ABARLeft ; Restore the left Action Bar.
- exit
- endproc ; End of ResetAbar procedure.
-
- ;- Section 14 -----------------------------------------------------------------
-
- proc main
- ; Declare a when command that watches for the prompt and calls
- ; another procedure to send a carriage return.
-
- when TARGET 0 " Press Enter " call PressEnter
-
- while $CARRIER ; Loop while connected.
- endwhile
-
- when TARGET 0 CLEAR ; Clear the when clause.
- endproc
-
- proc PressEnter
- transmit "^M" ; Send a carriage return.
- endproc
-
- ;- Section 15 -----------------------------------------------------------------
-
- #define TRUE 1
- proc main
- PointerChanged() ; Display beginning message on the
- ; status line and set up our whens.
- when $POINTERX call PointerChanged ; Watch the $POINTERX value.
- when $POINTERY call PointerChanged ; Watch the $POINTERY value.
-
- while TRUE ; Loop forever.
- endwhile
- endproc
-
- proc PointerChanged ; Procedure that displays the mouse
- ; pointers location on the status line.
- statmsg "( %d, %d )" $POINTERX $POINTERY
- endproc
-
- ;- Section 16 -----------------------------------------------------------------
-
- #define RUNPATH "c:\windows\notepad phones.txt"
- proc main
- string szAreaCode = "314" ; String to search for.
- run RUNPATH ; Run "notepad phones.txt".
- sendkey ALT 'S' ; Alt S (for Search).
- sendkeystr "f" ; F for Find.
- sendkeystr szAreaCode ; What to look for
- sendkey 13 ; followed by Enter,
- sendkey 27 ; then Esc to get out
- ; of searching.
- endproc
-
- ;- Section 17 -----------------------------------------------------------------
-
- ; File MAIN.WAS
- proc main
- S0 = "hello" ; Assign S0 the value "hello"
- usermsg S0 ; and display it.
- execute "change.wax" ; Call the file that manipulates S0
- usermsg S0 ; and show the changed value.
- ; Should be "goodbye" now.
- endproc
-
- ; File CHANGE.WAS
- proc main
- S0 = "goodbye" ; Reassign S0 the value "goodbye"
- endproc ; and return to parent.
-
- ;- Section 19 -----------------------------------------------------------------
-
- #define _MAX_ROWS $TERMROWS ; Declare a macro that represents the
- ; maximum number of rows on the screen.
- proc main
- integer CurrentRow ; Declare an integer variable that we can
- ; use to count through each row on the
- ; screen.
- for CurrentRow = 0 upto _MAX_ROWS - 1 ; Loop through all of the rows on
- termputs CurrentRow 0 "Awesome!" ; the screen and display a text
- ; string.
- endfor
- endproc
-
- ;- Section 19 -----------------------------------------------------------------
-
- #define _DO_MSG( a ) sdlgmsgbox "Script Message" a STOP OK I0
-
- proc main
- _DO_MSG( "Display me!" ) ; Use our macro to display a message
- ; using the sdlgmsgbox command.
- endproc
-
- ;- Section 19 -----------------------------------------------------------------
-
- proc SendCommands
- long SysChan ; Variable used for link handle.
-
- ddeinit SysChan "excel" "system" ; Set up a link to Excel.
- ddeexecute SysChan "[APP.RESTORE()]" ; These are commands that
- ddeexecute SysChan "[APP.MOVE(0,0)]" ; Excel accepts to size
- ddeexecute SysChan "[APP.SIZE(530,180)]" ; its window, format
- ddeexecute SysChan "[FULL(TRUE)]" ; columns, etc.
- ddeexecute SysChan "[COLUMN.WIDTH(75)]"
- endproc
-
- ;- Section 19 -----------------------------------------------------------------
-
- long SysChan = 0 ; Handle to Excel system.
- long DDEChan = 0 ; Handle to DDE channel.
-
- ddeinit DDEChan "excel" "test.xls" ; Initiate DDE link with
- if DDEChan == 0 ; spreadsheet. If no link
- usermsg "Unable to establish link" ; established, tell user and
- exit ; leave.
- endif
- ddeinit SysChan "excel" "system" ; Establish execute channel.
- ddeexecute SysChan "[SELECT(`"R1C1`")]" ; Move active cell to A1.
- ; Notice the backticks (`)
- ; to indicate literal quote
- ; marks.
- ddepoke DDEChan "R1C1" "Test" ; A1 now contains "Test".
-
- ;- Section 19 -----------------------------------------------------------------
-
- #define TRUE 1
- long DDEChan ; Handle to the DDE channel.
-
- proc main
- .
- .
- ddeinit ddechan "excel" "sheet1" ; Establish DDE link.
- ddeadvise ddechan "R1C1" s0 ; Set up hot link to R1, C1.
- when $DDEADVISE call ShowMessage ; Call ShowMessage when the
- ; cell is updated in Excel.
- while TRUE ; Loop forever.
- .
- .
- .
- endwhile
- endproc
-
- proc ShowMessage
- usermsg "The value of cell A1 has changed."
- endproc
-
- ;- Section 19 -----------------------------------------------------------------
-
- integer UserCommand = 1 ; Command to pass to receiver.
- string szText = "This is the first command." ; Text to send to receiver.
- integer Len = 26 ; Length of string to send.
-
- pkmode ON 30 60 ; Turn on packet mode.
- pksend UserCommand szText Len ; Send packet to receiver.
-
- .
- when $PKSEND call ProcessSend ; When the status of the $PKSEND
- . ; system variable changes, letting
- . ; you know the status of the send,
- . ; call a proc to see what happened.
-
- proc ProcessSend ; Proc determines the status of the packet
- switch $PKSEND ; by checking system variable $PKSEND
- case 0 ; If $PKSEND == 0, send is in progress
- endcase ; or idle.
- case 1 ; If $PKSEND == 1, packet sent,
- SendNext() ; the receiver has the packet.
- endcase
- case 2 ; Timeout has occurred so warn user.
- DoTimeout() ; (The receiver is dead or lost)
- endcase
- case 3 ; Errors during transmission.
- Notify(_COMERROR) ; Tell us about the error.
- endcase
- case 4 ; Send cancelled by receiver.
- Notify(_CANCEL) ; Tell us about the cancel request.
- endcase
- endswitch
- endproc
-
- ;- Section 19 -----------------------------------------------------------------
-
- pkmode ON 30 120 ; Turn on packet mode.
- when $PKRECV call ProcessRecv ; Watch for incoming packets!
- while TRUE
- .
- .
- .
- endwhile
- .
- .
- .
-
- proc ProcessRecv ; Determines the status of the packet
- switch $PKRECV ; by checking system variable $PKSEND.
- case 0 ; If $PKRECV == 0, packet not received.
- endcase
- case 1 ; If $PKRECV == 1, packet received OK,
- ReadPacket() ; extract the information from it.
- endcase
- case 2 ; Timeout has occurred.
- Notify(_TIMEOUT) ; Warn user about the error.
- endcase
- case 3 ; Errors occurred during the receive.
- Notify(_COMERROR) ; Warn user about the problem.
- endcase
- endswitch
- endproc
-
- proc ReadPacket
- integer Command ; Command sent with packet.
- string RecvString ; String sent with packet.
- integer PktLength ; Length of the data in packet.
-
- switch Command ; Switch case to evaluate the
- . ; command passed with the packet.
- .
- endswitch
- ProcessData(RecvString) ; Look at the string sent with packet.
- switch PktLength ; Possibly evaluate the length of the
- . ; packet to perform some other actions.
- .
- endswitch
- endproc
-
-
-