Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to handle different results.

Status
Not open for further replies.

allhandlesareused

Technical User
Oct 9, 2002
2
US
First of all I want to thank many people who contributed to this forum - I've gained quite a bit of insight to perform many different functions. From the code attached you can see I checked a few past postings, but I couldn't find good examples how to branch the code based on different results. I first started in a very linear fashion - but based on examples in the forums, I used the "Target" method to accomplish what I needed.

The script reads a text file of extensions and makes the same change to each one. My problem is that I need to handle different results, like entries that don't exist ("Cannot find this form"), and multiple lined entries (It will list "Extension [" multiple times.) Could someone show me how to handle this in a more logical manner? Possibly even two different ways to handle it? I can't seem to get my head around the code.

I have two examples...
Here is my original Linear method with comments where I have the problems:

-----------------start example 1---------------------
Code:
   waitfor "Subscriber Name or Extension:  "
   ; type exten number from file ---------
   transmit s1
   transmit "^M"
   
   ; At this point I have to check if the mailbox exists...
   ; look for "Cannot find this form"
   ; start again if it shows - continue if it doesn't.

   waitfor "Name (last first)   :"
   transmit "^M"
   waitfor "Class Number        :"
   transmit "^M"
   waitfor "Extension            [1]"
   transmit "^M"
   waitfor "Extension            [2]"
   transmit "^M"
   
   ; At this pont I need to make sure no other extensions exist for the system.
   ; look for "Extension            [3]"
   ; keep hitting enter until I get the line: ""PhoneMail Password  :"
      
   waitfor "PhoneMail Password  : (Previous = ##########):  "
   transmit "^M"
   waitfor "Group Name          :"
   transmit "^M"
   waitfor "Referral Extension  :"
   transmit "^M"
   waitfor "Volume Level        :"
   transmit "^M"
   waitfor "Speed level         :"
   transmit "^M"
   waitfor "  Enter T or F for each field):  "
   transmit "T T T^M"
   waitfor "Abbreviated Prompts?: "
   transmit ";^M"	; Done with this record
-----------------end example 1-----------------------


Here is the working result using the Target method:

-----------------start example 2----------------------
Code:
integer flag=0
string sEnter = "^M"
string Fname = "file.txt"       ; File name to be opened.
integer nJumps
string sLine
string sTok1

proc main

when Target 0 "Extension            [" call Press_Enter


when Target 1 "Name (last first)   :" call Press_Enter
when Target 2 "Class Number        :" call Press_Enter
When Target 3 "  Enter T or F for each field):  " call Announce
When Target 4 "Group Name          :" call Press_Enter
When Target 5 "Referral Extension  : " call Press_Enter
When Target 6 "Volume Level        : " call Press_Enter
When Target 7 "Speed level         : " call Press_Enter
When Target 8 "Abbreviated Prompts?: " call Exit_MailBox
When Target 9 "Cannot find this form." call Press_Next
When Target 10 "PhoneMail Password  :" call Press_Enter

   ; set txpace=100
   
   if fopen 0 fname READ TEXT     ; Open file for read only.
	; dial the number
	; log into the system -------
      while not feof 0         	; Loop while not end of file.
	setjmp 0 nJumps		; This is a Jump Mark Point
       	fgets 0 sLine       	; Get line from file.
	strtok sTok1 sLine " " 1                 ; Assigns Text in First Field (From Text 

File) to Variable sTok1.
	strreplace sLine " " ""
	; Debug message possibly here... check variable after string replace.

	waitfor "Subscriber Name or Extension:  " 10
      	transmit sTok1                           ; Sends the Text Value (Assigned to 

Variable sTok1) to the PhoneMail System.
      	transmit "^M"
      	if waitfor "Function:  " 
        	transmit "PROFILE^M"
        	waitfor "Action:  "
         	transmit "MODIFY^M"
         	waitfor "Subscriber Name or Extension:  "
         	transmit sTok1                           ; Sends the Text Value (Assigned to 

Variable sTok1) to the PhoneMail System.
         	transmit "^M"         
      	else
         	; do nothing? let Target handle it?
      	endif

      endwhile
      setjmp 1 nJumps
      fclose 0                 	; Close file opened for read.

	; Logout Procedure ----------
	waitfor "Subscriber Name or Extension:  "
	transmit ";^M"
	waitfor "Function:  "
	transmit "logo^M"
	waitfor "Action: "
	transmit "logo^M"

   else
      errormsg "Couldn't open file `"%s`"." Fname
   
   endif
       
endproc


proc Announce
   ;pause 1
   transmit "T T T^M"
endproc
proc Exit_MailBox
   ;pause 1
   transmit ";^M"
endproc
proc Press_Enter
   ;pause 1
   transmit "^M"
endproc   

proc Press_Next
   ; this is not very elegant(to say the least)
   ; It's suppossed to handle when a mailbox doesn't exist.
   ;pause 1
   nJumps = 0
   longjmp 0 nJumps	; jump to start of loop 
   
endproc
-----------------end example 2-----------------------------
 
In cases this like, it's sometimes easier to break out the work into different procedures that are executed using the call command. Your main script basically becomes a list of calls to subprocedures. Each subprocedure does error-checking on the functions it is supposed to perform, popping up a dialog box and exiting the script if necessary, or repeatedly trying the same steps for some set numbr of iterations. That is the method you've taken with your second script it appears, due to using the when target commands. With your first script, you could success/failure checking of the waitfor commands. This would let you determine if the text you were waiting for was found or not, and then try to workaround the situation if necessary.
aspect@aspectscripting.com
 
Thanks for the reply - I took the advice of staying away from when target commands and trying the waitfor and setup a test environment. What are the tricks to test for success failure? The waitfor command is not picking up my main test - and is skipping every other line in the datafile... After the code I have the debug output.

Here is the code:
------------------------------------------------------------------------

integer flag=0
string sEnter = "^M"
string FnameRead = "c:\temp\list1.txt" ; File name to be opened.
string FnameWrite = "c:\temp\list2.txt" ; File name to be written to.
string sLine
string sTok1
string sData
string sNewData

proc main

if fopen 0 fnameRead READ TEXT ; Open file for read only.
; list1.txt it in the format of
; 9950
; 9951
; 9952
; just lists exten numbers to list for profiles.

; dial the number
while $DIALING ; Loop while dialing.
yield
endwhile
fopen 3 fnameWrite CREATE TEXT ; create / overwrite output file.

; log into the system -------

while not feof 0 ; Loop while not end of file.
yield
fgets 0 sLine ; Get line from file.
strtok sTok1 sLine " " 1 ; Assigns Text in First Field (From Text File) to Variable sTok1.
strreplace sLine " " ""
sNewData = "" ; Reinitialize input string

; Debug message possibly here... check variable after string replace.
strcat sNewData sTok1 ; Combine Extension
strcat sNewData " loaded ---" ; Combine comma
fputs 3 sNewData
sNewData = "" ; Reinitialize input string

yield
yield
waitfor "Subscriber Name or Extension: " 10
if success
; success on "Subscriber Name or Extension:"
; extension exists
fputs 3 "xmit exten -- " ; debug text
transmit sTok1 ; Sends the Text Value
transmit "^M"
yield

waitfor "Referral"
if success
rget sData 25
; massage the data into one string
strcat sNewData sTok1 ; Combine Extension
strcat sNewData "," ; Combine comma
strcat sNewData sData ; Referral Exten

fputs 3 sNewData ; write to the file with CR

else
fputs 3 "failure on Referral capture text"
endif
else
; failed on "Subscriber Name or Extension:"
; extension does not exist
; fail here - insert code
; No extension (or Profile) exists
; probably get the message "Cannot find this form"

fputs 3 "enter failure on node capture text" ; debug text
waitfor "Function" 3
if success
strcat sNewData sTok1 ; Combine Extension
strcat sNewData ", NO PROFILE" ; Combine comma
fputs 3 sNewData ; write to the file with CR

pause 1
transmit "pro^M"
yield
pause 1
transmit "li^M"
else
fputs 3 "fail on function else" ; debug text
endif
endif
endwhile

fclose 0 ; Close file opened for read.
fclose 3 ; close the output file
; Logout Procedure -
transmit "logo^M"
yield
hangup
else
errormsg "Couldn't open file `"%s`"." fnameRead
endif
endproc

------------------------------------------------------------------------


The result - debug file looks like this:

1101 loaded ---
xmit exten --
1101, Extension 1103

1102 loaded ---
enter failure on node capture text
fail on function else
1103 loaded ---
xmit exten --
1103, Extension 0

1104 loaded ---
enter failure on node capture text
fail on function else
1105 loaded ---
xmit exten --
1105, Extension 1101

1106 loaded ---
enter failure on node capture text
fail on function else
loaded ---
xmit exten --
failure on Referral capture text


I confirmed that the system IS displaying the "Subscriber Name or Extension" line, it just seems like it's missing it.
 
I haven't had a chance to run through your entire script, but if the expected string is appearing, then make sure your waitfor command has the correct string in it. For example, if your string has one extra space than the transmitted string, then the waitfor command would fail. You might also want to verify that the 10 second timeout you specified is sufficiently long enough for the system you are calling into.
aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top