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!

Loop indefinately until user interacts 1

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I currently have a process that will run once and exit procomm. I am looking for a way to loop the process indefinately.

When the user is ready to interupt the sequence they can hit enter (or any key for that matter) stop the process and exit the system.

Thank you for your assistance Jason Meckley
Database Analyst
WITF
 
I thought something like the below script would work, but it looks like the $KEYHIT system variable is not working as I expected. I'll play around with this script some more when I get back from lunch.

proc main
when $KEYHIT call closedown

while 1
yield
endwhile
endproc

proc closedown
pwexit
endproc aspect@aspectscripting.com
 
I have been looking around in the help menu of Ascept Editor. I would like to use a key that is not used very often, or for basic computer usage.

What about the <ESC> key? this way the user could still use the computer for other things while the script is running. Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
Here's a script that will exit the script and close down Procomm when the Escape key is pressed. I remembered at lunch that I needed to add set aspect keys on to make the original script work. If the user is going to press keys other than Escape that need to go to the remote system, then you will need to modify the script so that it sends those extra keystrokes using the transmit command.

proc main
set aspect keys on
when $KEYHIT call closedown

while 1
yield
endwhile
endproc

proc closedown
integer iKey

keyget iKey
if iKey == 27
pwexit
endif
endproc aspect@aspectscripting.com
 
So if I understand this correctly:

They can press anykey to take them to the closedown procedure. but, it will only exit if they press the escape key. Is that correct?

The idea is for the user to be able to use other software on their computer without effecting the transmit. Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
The script will only act on keys that are pressed while in Procomm. If the key is something other than Escape, then nothing happens and the script keeps waiting. If an Escape is pressed, then Procomm (but only Procomm) will close.

ASPECT is not able to grab keystrokes that are not entered in the Procomm window, so the best the script could do is wait for an Escape in the Procomm window and then restart or shutdown by using the exitwindows command and the appropriate flag.
aspect@aspectscripting.com
 
That would be fine. I just need the script to exit procomm when the user hits escape. I wasn't sure if just pressing keys would effect other software or not.

I am getting all kinds of compile errors though. Most of the errors occur on defining the variables. I narrowed the errors down to these two commands:
set aspect keys on
when $KEYHIT call closedown
Below is the script. I am looking to open the script, have it loop continually until the user hits esc.

proc main
set aspect keys on
when $KEYHIT call closedown
;---Define Variables--------------------------------------------
string strCrawl ;Message displayed on the screen
string strCounty ;Variable for which county is displayed
string strCountyName ;&quot;<Name> County&quot; will be displayed on the screen
string strBulk ;All Commands
string strLineBuffer ;Data in file
integer intX ;Number for the loop
integer intLength ;Length of the string
integer intCLen ;Length of the County String
integer intChoice ;1 = crawl data, 2 = exit procomm

;---Begin Code--------------------------------------------------
sdlgmsgbox &quot;MCR/CODI Switch&quot; &quot;Set the AB switch to SCHOOL CLOSING, once that is done click OK&quot; EXCLAMATION OKCANCEL intChoice

if intChoice == 2
pwexit ;Exit procomm
else
transmit &quot;\sr\\&quot; ;Reset the Chyron CODI
waitfor &quot;000*&quot; forever matchcase ;Allow the CODI to reset
transmit &quot;\ct\9\2\0\\&quot; ;Remove the shadow edge from the font
;The following line will set lines 1-180 to video and 181-256 black
transmit &quot;\c1\\\f1\\\db\2\r\1\0\0\0\1\185\0\0\0\1\184\0\0\0\0\256\0\0\0\0\\\vb\\&quot;
transmit &quot;\dm\1\0\250\380\c1\f1\ATTENTION:\30\405\c1\f1\The following organizations have a modified schedule for today\\&quot;
transmit &quot;\md\1\\\sw\160\\&quot;

while 1
for intX = 1 upto 13 ;This process is repeated for each county

;---Set Variable for that County------------------------
if intX == 1
strCounty = &quot;V:\StormWarning\TVDir\Adams.txt&quot;
elseif intX == 2
strCounty = &quot;V:\StormWarning\TVDir\Berks.txt&quot;
elseif intX == 3
strCounty = &quot;V:\StormWarning\TVDir\Cumberland.txt&quot;
elseif intX == 4
strCounty = &quot;V:\StormWarning\TVDir\Dauphin.txt&quot;
elseif intX == 5
strCounty = &quot;V:\StormWarning\TVDir\Juniata.txt&quot;
elseif intX == 6
strCounty = &quot;V:\StormWarning\TVDir\Lancaster.txt&quot;
elseif intX == 7
strCounty = &quot;V:\StormWarning\TVDir\Lebanon.txt&quot;
elseif intX == 8
strCounty = &quot;V:\StormWarning\TVDir\Mifflin.txt&quot;
elseif intX == 9
strCounty = &quot;V:\StormWarning\TVDir\Perry.txt&quot;
elseif intX == 10
strCounty = &quot;V:\StormWarning\TVDir\Schuylkill.txt&quot;
elseif intX == 11
strCounty = &quot;V:\StormWarning\TVDir\Snyder.txt&quot;
elseif intX == 12
strCounty = &quot;V:\StormWarning\TVDir\York.txt&quot;
else
exitfor ;Exit the for loop
endif

;---Create county text----------------------------------
strCrawl = &quot;&quot; ;Reset the Crawl message
strlen strCounty intCLen
substr strCountyName strCounty 22 (intCLen - 26) ;Parse the county from the string
strBulk = &quot;\dm\1\0\45\368\c1\f1\&quot;
strcat strBulk strCountyName
strcat strBulk &quot; County&quot;
strcat strBulk &quot;\50\421\c5\f1\visit and listen to WITF 89.5 FM for updates\\\me\cs\&quot;
transmit strBulk ;Send setup commands to the CODI (message 1 and crawl data)

;---Open file or default message------------------------
if fopen 0 strCounty READ TEXT ;Open file for read only, if it exists.
while not feof 0 ;Loop while not end of file.
fgets 0 strLineBuffer ;Get line from file.
if not nullstr strLineBuffer
strlen strLineBuffer intLength ;Caluclate the length of the line
substr strCrawl strLineBuffer 1 (intLength - 2) ;Remove the Quotes
strcat strCrawl &quot; &quot; ;add a space between rows
endif
endwhile

fclose 0 ;Close the file
else
strCrawl = &quot;There are no delays, cancellations or closings at this time.&quot;
endif

;---Transmit data---------------------------------------
transmit strCrawl ;Send the crawl data to the CODI
transmit &quot;\\\md\1\\\me\cb\1\0\397\\\sa\\&quot; ;Send the display commands to the CODI and wait for a system acknowledge
waitfor &quot;*&quot; forever matchcase ;continue with script when the crawl is finished
transmit &quot;\mb\1\\\me\ce\\&quot; ;Free some memory buffer
endfor ;Repeat the process 12 times (each county)
endwhile

transmit &quot;\pb\\\sr\\&quot; ;Reset the system, close ProComm
waitfor &quot;000*&quot; forever matchcase
pwexit
endif
endproc ;End main procedure

proc closedown
integer intKey ;numeric value of the key

keyget intKey
if intKey ==27
waitfor &quot;*&quot; forever matchcase
transmit &quot;\pb\\\sr\\&quot; ;Reset the system, close ProComm
waitfor &quot;000*&quot; forever matchcase
pwexit
endif
endproc ;End closedown procedure Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
If you move:

set aspect keys on
when $KEYHIT call closedown

after the line:

;---Begin Code--------------------------------------------------

then the script should compile OK. The problem was that the compiler was finding variable declarations after a couple ASPECT commands and it doesn't like that (all variables must be declared at the beginning of the script).

Additionally, I would place the two lines at the location in your script when you expect the user will not need to send any more data to the remote system. This is due to the fact that setting aspect keys on requires your script process the keystrokes in a different manner than before. If possible, I would add those two lines at the latest point in your script while you can so you can hopefully get around this issue (i.e. if all the user has left to do is hit Escape, then we don't have to worry about the script processing the keystrokes). aspect@aspectscripting.com
 
Thank you for your help! it is working, however when I press <ESC> the correct text is transmitted, AND the text from the main procedure is inserted, so it is not working 100%.

I have been reading up on the YIELD command. will that pause execution until it is done, or pause when the WHEN command is activated, or does it work diferently all together? Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
it's the same one. That is the only script in this process. When the user presses the esc key I want the main proc to end and the closedown proc to execute. Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
Jason, I haven't had a chance to go through your entire script (trying to get a patch out the door today), but does the user ever perform any input with the keyboard? It didn't look like they did and if not, then you can leave the set aspect keys on and the when $KEYHIT lines toward the top of the script. I think that should work for you, hopefully! aspect@aspectscripting.com
 
there is no user input, all the information is taken from text files.

I tested it earlier and the call to the closedown procedure worked. however, it generated errors on the hardware I was connected to. and procomm continued transmitting information from the main procedure, which I do not want to happen. I need it to stop main proc and start closedown proc.

You have been greatly beneficial in the progress of this project. Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
Where do you have the two lines in your script? Are they still at the beginning of the script or did you move them elsewhere? If the Escape key is pressed and the closedown procedure is called, then Procomm should not send any more data (other than the transmit command you have in the closedown procedure). However, the switch may be processing earlier transmit statements that the script sent when the Escape key has been pressed, and this may cause some errors due to timing if the two transmit statements &quot;stomp&quot; on each other.
aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top