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

Error Handling

Status
Not open for further replies.

DMS500Tech

Technical User
Dec 22, 2004
39
US
I am at point where I don't know how to proceed. The following code handles the one exception perfectly. The code will pick out "ALREADY EXIST" on the fly and pass by and it and adds the feature at a rate of less than 2 seconds an instance. The problem comes when trying to add a second exception. I also need to look for "LEN Entered is not assighned to a DN". I am having trouble figuring out how to assign what is flying by the command line to a varible or get a second "if waitfor" to work. If a varible can be assigned then a "switch" "case" could be done or if there is another way to accomplish this I am open to suggestions. An IF and ELSEIF has already been tried but it does not work.

CODE:
if sdlginput "File Name" "Enter path and file name:" FName
if isfile FName ; Make sure file exists.
if fopen 0 FName READ ; Open file for read.
while not feof 0 ; Loop to end of file.
fgets 0 LineInfo ; Get line from file.
transmit "ADO $ ^M "
transmit lineinfo ; Send line to port
transmit "LCDR $ Y^M"
if waitfor "LCDR : ALREADY EXISTS" 1
pause 1
transmit "N^M"
pause 1
endif
transmit "^M"
; pause 1
endwhile
fclose 0 ; Close the file.

endif
else
errormsg "File doesn't exist."
endif
endif
 
I think if you check Aspects help file for 'WHEN TARGET', you'll find what you're looking for. If you search this forum you will find several good examples.

 
Here's a sample from a program I use with the DMS.

Code:
when target 0 "DMO REJECTED" MATCHCASE call test suspend
when target 1 "ENTER Y TO CONFIRM" MATCHCASE call test1
when target 2 "*** ERROR - INCONSISTENT DATA ***" MATCHCASE call test suspend
when target 3 "NO COMMAND IN LINE" call test2 suspend
when target 4 "*** ERROR ***" call test3 suspend
 
As kodr mentioned, when target is what you will likely want to use. I have a script from another user on my site (go to the samples page and search for Josh) that uses three when targets to look for up to three different strings and returns the first string that was matched if that is something you would need. Otherwise, two when targets should do the trick.

 
Sometimes writting a script can be so frustrating when you know it is a simple thing you are trying to do. I modified the original script as follows and have tried puting the "when" statements before and after the "transmit LCDR" have deleted and recopied the statement text. I have tried with and without "MATCHTEXT" and "SUSPEND" I have tried everything I can think of and the "when" statements will not fire.
Any Ideas???????

proc getinfo

string FName ; Name of file to read.
string LineInfo ; Line from file.

if sdlginput "File Name" "Enter path and file name:" FName
if isfile FName ; Make sure file exists.
if fopen 0 FName READ ; Open file for read.
while not feof 0 ; Loop to end of file.
fgets 0 LineInfo ; Get line from file.
transmit "ADO $ ^M "
transmit lineinfo ; Send line to port
transmit "LCDR $ Y^M"

when target 0 "LCDR : ALREADY EXISTS" MATCHCASE call option1 SUSPEND
when target 1 "LEN Entered is not assigned to a DN" MATCHCASE call option2 SUSPEND
when target 2 "SHOULD ORDER BE DONE ANYWAY? (Y OR N)" MATCHCASE call option3 SUSPEND
when target 3 "*** ERROR ***" MATCHCASE call option2 SUSPEND
when target 4 "*** ERROR - INCONSISTENT DATA ***" MATCHCASE call option2 SUSPEND

transmit "^M"
endwhile
fclose 0 ; Close the file.

endif
else
errormsg "File doesn't exist."
endif
endif
endproc

proc option1
waitfor ">"
transmit "N^M"
pause 1
endproc

proc option2
transmit "abort^M"
pause 1
endproc

proc option3
transmit "Y^M"
pause 1
endproc
 
Try placing the WHEN lines immediatly under 'proc getinfo'

I think it's a matter of telling the program ahead of time, your placing comes after the event is likely to have occured.
 
Code:
proc getinfo
when target 0 "LCDR : ALREADY EXISTS" MATCHCASE call option1 SUSPEND
when target 1 "LEN Entered is not assigned to a DN" MATCHCASE call option2 SUSPEND
when target 2 "SHOULD ORDER BE DONE ANYWAY? (Y OR N)" MATCHCASE call option3 SUSPEND
when target 3 "***  ERROR  ***" MATCHCASE call option2 SUSPEND
when target 4 "***  ERROR - INCONSISTENT DATA  ***" MATCHCASE call option2 SUSPEND
  string FName                        ; Name of file to read.
   string LineInfo                    ; Line from file.

   if sdlginput "File Name" "Enter path and file name:" FName
      if isfile FName                    ; Make sure file exists.
         if fopen 0 FName READ               ; Open file for read.
            while not feof 0                 ; Loop to end of file.
               fgets 0 LineInfo              ; Get line from file.
                 transmit "ADO $ ^M "    
                 transmit lineinfo           ; Send line to port
                 transmit "LCDR $ Y^M"



                 transmit "^M"
            endwhile
            fclose 0                         ; Close the file.

         endif
      else
         errormsg "File doesn't exist."
      endif
   endif
 endproc
 
 proc option1
    waitfor ">"
    transmit "N^M"
    pause 1
 endproc
 
 proc option2
    transmit "abort^M"
    pause 1
 endproc

 proc option3
    transmit "Y^M"
    pause 1
 endproc
 
If the "when" statements are placed before defining the string variables aspect gets angry so I placed them directly after string FName and string LineInfo but that aside it did not make any difference. There is no indication that the script is looking for anything. The script opens the file spits out the data regardless of the prompt.
 
Why do you use the MATCHCASE option and the long "match"?
Have you tried with a shorter match, like:
Code:
proc getinfo
when target 0 "lcdr : already" call option1 SUSPEND
when target 1 "len entered" call option2 SUSPEND

Maby that would get the WHEN to fire....?
 
Thank you geirendre. The only reason I was looking for what I was is because that was the entire line. That has always been my pet pieve about the aspect help files they don't ever seem to go into enough detail about parameters used with commands. Anyway, I shortend the lines and it now seems to be working like a charm.

when target 0 "EXISTS" MATCHCASE call option1 SUSPEND
when target 1 "not assigned" MATCHCASE call option2 SUSPEND
when target 2 "ORDER BE DONE" MATCHCASE call option3 SUSPEND
when target 3 "ERROR" MATCHCASE call option2 SUSPEND

thanks again to KODR and KNOB for getting me started in the right direction. Everyone at this forum ROCKS!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top