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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waitfor forever substitute with 'Else" type statement.

Status
Not open for further replies.

jeditom

IS-IT--Management
Dec 3, 2003
23
0
0
US
In the below excerpt, is there a way to remove the "Forever" from the waitfor statement and replace it with an "else" statement that would send us back to the start of the script?

THANKS!


waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit sShelf
transmit "^M"
 
Jeditom,

Try this. Substitute the forever statement for the amount of time you want to wait (i.e. 30 seconds in the below example). Then, use the 'if SUCCESS' statement to see if the expected response was seen in that amount of time. If the response is not seen, use the else statement to direct the script flow elsewhere.

waitfor "ENTER SHELF : ^[[24;28H" 30 ;waits 30 seconds
if SUCCESS
transmit sShelf
transmit "^M"
else
;place your call, goto, or exexute statement here....
endif



Hope that helps! Eddie.
 
That's great. Next question:

How do I use the ELSE statement with a GOTO statement that would point m,e back to the top of this script? (Where do I GOTO?)

proc main
string sLine
string sShelf
string sSlot
string sStored

if fopen 0 "d:modems1-4.txt" READ TEXT
while not feof 0
fgets 0 sLine

strextract sShelf sLine "," 0
strextract sSlot sLine "," 1
strextract sStored sLine "," 2
; TELNET INTO THE CONTROLLER
connectmanual telnet "192.168.51.103"

; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"
 
Jeditom,

You can set a goto location by naming a section "AnyName:" and then using a "goto AnyName" comment. In the example below, the section name is 'Restart', and - if the waitfor command fails, you are sent to that section. The section can be anywhere AFTER your variable declarations, so if you need to begin from scratch with all of the variables at a null value, you will need to reset the variables before you call the ‘Restart’ section.

Is that what you were looking for? If not, let me know.
Eddie

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

proc main

string sLine
string sShelf
string sSlot
string sStored

Restart:

if fopen 0 "d:modems1-4.txt" READ TEXT
while not feof 0
fgets 0 sLine

strextract sShelf sLine "," 0
strextract sSlot sLine "," 1
strextract sStored sLine "," 2
; TELNET INTO THE CONTROLLER
connectmanual telnet "192.168.51.103"

; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" 30 ;Wait 30 Seconds

if SUCCESS ;If received in 30 seconds
transmit "1"
transmit "^M"
else
;sLine = "" ;Use these only if you need to reset the strings
;sShelf = "" ; since the 'Restart' section cannot come before
;sSlot = "" ; the variable declaration
;sStored = ""
goto Restart ;Else goto section 'Restart'
endif

endwhile ;do not know if this is where it needs to be, but I had to add it to compile and test
endif ;same as above

endproc
 
No matter where I place the Restart: the script does not pick up where the variables left off. It keeps restarting at the beginning.

Am I missing something obvious?
 
I'm not sure what you mean by where the variables left off. The 'goto Restart' sends the scripting to the exact place where the section name "Restart:" is. It sends it there and forgets about it. It will not automatically return to the point of the goto statement. Post your entire script with the "Restart:" and "goto Restart" statements where you need them, and describe what exactly you need and what is failing to happen. (i.e. - if you don't see "ENTER SELECTION..." in 30 seconds, do you want to restart at the file open, or at the Telnet connect?)
I'll take a look and see what I can find.
 
This is the script I am trying to adjust. The variables sShelf, sSlot, and sStored are pulled off a text file. When I implement the if/else statement it keeps inputting the first variable from the text file.

I need it to get to a point where it will pick up with teh next set of numbers.

Your help is GREATLY appreciated!!!

proc main
string sLine
string sShelf
string sSlot
string sStored

if fopen 0 "d:modems1-4.txt" READ TEXT
while not feof 0
fgets 0 sLine

strextract sShelf sLine "," 0
strextract sSlot sLine "," 1
strextract sStored sLine "," 2
; TELNET INTO THE CONTROLLER
connectmanual telnet "192.168.51.103"

; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO CHANGE THE SHELF
waitfor "SHELF=" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; ENTER THE SHELF NUMBER
waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit sShelf
transmit "^M"


; CHOOSE 2 TO CHANGE THE SLOT
waitfor "ENTER SELECTION : " Forever
transmit "2"
transmit "^M"

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever
transmit sSlot
transmit "^M"


; CHOOSE 3 TO ENTER THE SHELF AND SLOT CHOSEN
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "3"
transmit "^M"

; CHOOSE 7 FOR DIAL BACKUP
waitfor "DIAL BACKUP" forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "7"
transmit "^M"

; CHOOSE 1 TO GO TO DIAL BACKUP
waitfor " GO TO DIAL BACKUP" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"


; CHOOSE 1 TO DIAL STORED NUMBER
waitfor " DIAL STORED NUMBER" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE sStored TO DIAL THE STORED NUMBER
waitfor "ENTER NUMBER TO DIAL :" Forever
transmit sStored
transmit "^M"
waitquiet 10

transmit "^["
waitquiet 2
transmit "^["
waitquiet 2

if nullstr sLine
endif

endwhile
endif
fclose 0
endproc
 
If I understand correctly, when you goto to the label you have specified (I don't see one in the script you posted though), the data you previously read from the text file is being used again instead of reading the next line? If so, then you probably need to move the label to the fgets 0 sLine command at the beginning of the script.

 
Jeditom,

Try using array's for your variables. If you have to go back to restart, you can back off you index variable first.

(poor psuedo code here...)
Code:
sStored[100]
iIndex

if SUCCESS
   ; code here
else
   iIndex = iIndex -1
   goto RESTART
endif


Or maybe not. I'm not sure if I followed the question completely.
 
I'm a little late putting in my .02 but howbout calling another procedure and using the RETURN command to get back to the next variable?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top