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!

If - Then Question 1

Status
Not open for further replies.

MyFlight

Technical User
Feb 4, 2002
193
I have a script file that runs and I need to choose between 2 possibilities. I tried using the When Target Command, However, this will not work. If I use the WHEN TARGET Command, the script does not completly process the Last Extension. In addtion if I receive an ERROR, because ONE extension is not in the System. I cannot hit Enter to continue, because then when the file is finished it keeps scrolling.

I want to accomplish the Following while reading Values from a File (i.e. within a while not feof command).

If I receieve the following from the Port: "No Valid Match"
Go to the Next entry in the file (fgets 1 sLine) and continue processing script.

If the Extenison is (Valid) Found I want to finish the steps within the while feof.

NOTE: the WHEN TARGET Commands cover all of the Prompt I receeive after a Valid Extension is Found, upto and After the PassWord Prompt.

Example:
Code:
proc main
string CapPath ="C:\Program File\Procomm Plus\Download\"
string szNewPswd,szSiteName,sTok1,sLine
string sEnter = "^M"
integer sNext
sdlginput "Site Name" "Enter Site Name:" szSiteName                         ; Assigns Site Name to the Variable szSiteName
pause 1
sdlginput "New Password" "Enter the New DEFAULT Password:" szNewPswd        ; Assisgns Password to szNewPswd
pause 1
strcat szNewPswd sEnter                                                     ; Adds and Enter to the szNewPswd Variable
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

; Verifies that My Site.txt File does Exist.
if isfile "C:\Temp Data Files\Raw Data\My Site.txt"                            

; Opens Text File My Site.txt
fopen 1 "C:\Temp Data Files\Raw Data\My Site.txt" READ TEXT

; This will bring you to the PhoneMail Modify prompt in the system
   waitfor "Function: " FOREVER              
   transmit "PROFILE^M"                     
   waitfor "Action: "                        
   transmit "MODIFY^M"
;HERE IS WHERE THE PROBLEM IS
while not feof 1
setjmp 0 sNext
fgets 1 sLine
strtok sTok1 sLine "," 1
; Assigns Text in First Field (in Text File) to Variable sTok1.
strreplace sLine " " " "
waitfor "Subscriber Name or Extension: "

; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
transmit sTok1
transmit "^M"
if waitfor "PhoneMail Password : (Previous = ##########): "
transmit szNewPswd
Pause 1
endif
endwhile
endif

fclose 1
transmit ";^M"
waitfor "Function: " forever
transmit "LOG^M"
waitfor "Action: " forever
transmit "LOG^M"
capture OFF
hangup
endproc
proc Announce
pause 1
transmit "F T F^M"
endproc

proc Exit_MailBox
pause 1
transmit ";^M"
endproc
proc New_MailBox
integer sNext = 0
sNext = 0
longjmp 0 sNext
endproc
proc Press_Enter
pause 1
transmit "^M"
endproc

If this does not make sense and/or you need more information, please let me know.

You assistance is greatly appreciated.
 
CLARIFICATION;

I have a List of PhoneMail Extensions (Provided in a Text File). I want to send These extensions to the PhoneMail System I am Currently Connected to. BAsically I am Changing the PhoneMAil Boxes Password and Clearing Failed Access Attempts. I used WHEN TARGET's to step though the Prompts Recieved (As sometimes the Number of Prompts Varies).

1. I can read the Values from the Text File.

2. I can Step through the Prompts receieved after sending
(sToK1), using all of the WHEN TARGET Commands.

3. After the Last Value is read from the Text File, and
Sent to the PhoneMail System, The script stops (at the
Password Prompt), I.e. the WHEN TARGET Commands will
not execute since the Script believes it has finished
processing all Values from the Text File.

4. If an Extension (Value) in the Text File is NOT found
in the PhoneMail, I want to Skip to the Next Entry in
the Text File.

5. If the Extension (Value) in the Text File is Found I
want to Process this Extension, then move to the Next
Extension (Value) in the Text File.

So Far I can Accomplish Either Step-4 or Step-5, But NOT BOTH Together. I tried and "IF WAITFOR", and WHEN TARGET, but could NOT get either to work correctly. ANy Assistance will be greatly appreciated.
 
I haven't had a chance to really dig into your script, but you could try using something like:

if waitfor "...."
do the commands you already have
else
transmit any necessary comands to get back to the proper
state before you read the next value from the file and
begin again at the top of the while loop
endif

The if waitfor command and the commands you currently have under it will remain the same, you'll just need to make sure that you send whatever keystrokes are needed to clear an error condition for an extension that does not exist. Since you are at the end of the while loop, once you are done doing this, execution will return to the top of the while loop, the next line of data will be read, etc.

I'll look at this again tonight at home to make sure I understood the problem correctly, but hopefully this gives you something to work on now.
aspect@aspectscripting.com
 
KNOB

There are no keystrokes required to clear the error. The PhoneMail System returns the "Subscriber Name or Extension: " prompt so that script processing may continue. I have the "If waitfor" command in my Script already while looking for the Password prompt ("if waitfor "PhoneMail Password : (Previous = ##########): "). I tried changing the command so it looked for the ERROR first. However, It seems to wait 30 seconds before continuing (like it is waiting for the command to time out). I tried adding the IF WAITFOR "Cannot find this form.[/]" First, However then it sits for 30 seconds and of course NEVER sees the Password Prompt.
 
You can specify a timeout value to override the default 30 second timeouts by placing the value at the end of the waitfor command like this:

waitfor "string to look for" 5

The above command would only wait five seconds for the specified string instead of the full 30 seconds.

Something else I noticed is that you are waiting on the string "PhoneMail Password : (Previous = ##########): " Is this string, including the # characters, exactly as it appears on the screen each time? You might want to consider watching for a subset of this string, such as "PhoneMail Password", then use a mspause 500 command to wait half a second for the remainder of the string to be received, then continue on in your script. aspect@aspectscripting.com
 
KNOB,

The "PhoneMail Password : (Previous = ##########): " Is correct and when used alone works fine. I cannot reduce the time on this waitfor command because: almost all of the WHEN TARGET commands prececed or follow this statement.

I gues I could use the Waitfor "Cannot find this form." 5. However, if this is not found and I continue to the Waitfor "PhoneMail Password" prompt, will ProComm see this since it probably will already have been received. If not, the I will have to wait for the 30 seconds. If I change this value and I connect to a busy system, I run the risk of sending the password at the wrong time.

Here is the Updated Script I have:

proc main
string CapPath ="C:\Program File\Procomm Plus\Download\"
string szNewPswd,szSiteName,sTok1,sLine
string sEnter = "^M"
string Fname = "Completed"
string Sname = ".txt"
integer sNext
sdlginput "Site Name" "Enter Site Name:" szSiteName ; Assigns Site Name to the Variable szSiteName
pause 1
sdlginput "New Password" "Enter the New DEFAULT Password:" szNewPswd ; Assisgns Password to szNewPswd
pause 1
strcat Fname szSiteName
strcat fname Sname
strcat szNewPswd sEnter ; Adds and Enter to the szNewPswd Variable
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 Press_Enter
When Target 9 "Cannot find this form." call Exit_MailBox
When Target 10 "Alt Greeting Active?: (Previous =" call Press_Enter
When Target 11 "Software Mailbox ? : (Previous =" call Press_Enter
When Target 12 "Failed Acc Attempt : (Previous =" call Press_Zero

if isfile "C:\Temp Data Files\Raw Data\My Site.txt" ; Verifies that AS00.txt File does Exist.
fopen 1 "C:\Temp Data Files\Raw Data\My Site.txt" READ TEXT ; Opens Text File AS00.txt
fopen 2 Fname CREATE ; Create and open a file.
capture OFF
waitquiet 1
set capture path CapPath
set capture file szSiteName
set capture overwrite ON
set capture query OFF
capture ON
PAUSE 5
transmit "^M"
Execute "Log-SA.wax" ; Logs you into the PhoneMail System and gets you to the Function Prompt.
while not feof 1
setjmp 0 sNext
fgets 1 sLine
strtok sTok1 sLine "," 1 ; Assigns Text in First Field (From Text File) to Variable sTok1.
strreplace sLine " " " "
waitfor "Function: " FOREVER
transmit "PROFILE^M"
waitfor "Action: "
transmit "PURGE^M"
waitfor "Subscriber Name or Extension: "
transmit sTok1 ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
transmit "^M"
if waitfor "Function: " 10
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"
if waitfor "PhoneMail Password : (Previous = ##########): " 10
transmit szNewPswd
fputs 2 sTok1 ; Put lines into file with FPUTS.
fputs 2 "Purged "
fputs 2 szNewPswd
else
transmit ";^M"
fputs 2 "Exten Not Found"
fputs 2 "No Password Change"
endif
else
transmit ";^M"
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"
if waitfor "PhoneMail Password : (Previous = ##########): " 10
transmit szNewPswd
fputs 2 sTok1 ; Put lines into file with FPUTS.
fputs 2 "Purged "
fputs 2 szNewPswd
else
transmit ";^M"
fputs 2 sTok1 ; Put lines into file with FPUTS.
fputs 2 "NOT Purged "
fputs 2 "NO PASSWORD CHANGE"
endif
endif
endwhile
endif
fclose 1
fclose 2
transmit ";^M"
waitfor "Function: " forever
transmit "LOG^M"
waitfor "Action: " forever
transmit "LOG^M"
capture OFF
hangup
endproc
proc Announce
pause 1
transmit "F T F^M"
endproc
proc Exit_MailBox
pause 1
transmit ";^M"
endproc
proc New_MailBox
integer sNext = 0
sNext = 0
longjmp 0 sNext
endproc
proc Press_Enter
pause 1
transmit "^M"
endproc
proc Press_Zero
pause 1
transmit "0;^M"
pause 1
transmit ";^M"
endproc


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top