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

I need to have an error trap routin

Status
Not open for further replies.

Eguy

Programmer
Dec 22, 2000
566
0
0
US
I need to have an error trap routine to trap for index problems on open. i.e. missing cdx, corrupt index, etc. I need to know what table the application was trying to open. MESSAGE(1) does not work in a distributed executable unless the .prg is present (not an option). The use of a function to handle opens was never used and to implement this now would be an enormous task as there are over 200 programs & screens and is undergoing constant change due to the clients changing needs, wants, and desires. Is there any way of knowing what table was being used? Any ideas would be appreciated. This is done VFP 5.

TIA,
Ed


Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
Add a variable to your program that opens the tables which holds the name of the table to be openend.
That way you can always track the problem down to the table that causes it.

Rob.
 
Here is procedure that I wrote a long time ago. I just spent a few minutes cleaning it up. It still could use a little more error-handling, like ensuring the table exists, but it is a good start.

Rather than using this type of logic all the time:

IF USED('myTable')
SELECT myTable
ELSE
SELECT 0
USE myTable
ENDIF

I just call the function to select the table, and open it if necessary. It also provides a nice message back if the index does not exist. Copy all this code in prg and run it. You will notice a message comes back saying the index does not exist. Is the type of trapping you are looking for?

CREATE table boo (name C(10))
selecttable('boo','myidx')

*****************************************************************************
PROCEDURE SELECTTABLE
PARAMETER tctbl, tcidx
* called to ensure a table is already open and the proper order is set
* if the table is not opened, it is opened.
* if the table is open - we ensure it is active and the order is
* checked to ensure it is correct
* if no order is passed, we will not do anything with the order

* Note: some of the macros may be able to be removed later.
* additional test for performance should be done when time permits.

LOCAL llFoundit, lctagname, lnCount

IF !USED('&tctbl')
SELECT 0
USE (tctbl)
ELSE
SELECT (tctbl)
ENDIF

llFoundit = .F.

IF PCOUNT() = 2
IF UPPER(ALLTRIM(ORDER())) <> UPPER(ALLTRIM('&tcidx'))
FOR lnCount = 1 TO 254 && vfp max # of tags is 254
lctagname = TAG(lnCount)
IF !EMPTY(lctagname) && Chks for tags in the index
IF UPPER(ALLTRIM(lctagname)) == UPPER(ALLTRIM(tcidx))
* We found the tag
llFoundit = .T.
EXIT
ENDIF
ELSE
EXIT && Exit the loop when no more tags are found
ENDIF
ENDFOR

IF llFoundit
SET ORDER TO TAG &tcidx
ELSE
MESSAGEBOX(&quot;WARNING!!!&quot; + CHR(13)+CHR(10)+CHR(13)+CHR(10) + ;
&quot;Tag: &quot; + tcidx + &quot; was not found on table: &quot; + tctbl)
ENDIF
ENDIF
ENDIF




Jim Osieczonek
Delta Business Group, LLC
 
i simply use an ON ERROR DO AFSERROR in my &quot;startup&quot; program. On any error this leads to following routine:
(I quickly translated from dutch to english)

* afserror.prg

set print off
set device to screen
activate screen
save screen to oldscreen
set fullpath off
if (error()>=108 .AND. error()<=111) .OR. error()=130
do afsmeldb with &quot; Data in use by someone else &quot;
fout=1 && fout = dutch for error
foutbezig=&quot;j&quot; && bezig= busy
do while foutbezig=&quot;j&quot;
@ 22,0 prompt &quot;\<Retry&quot; message &quot;Retry again.&quot;
@ 22,col()+1 prompt &quot;\<Main Menu&quot; message &quot;Leave program and go back to main menu.&quot;
menu to fout
do afsleeg
foutbezig=&quot;n&quot;
on error
on error do afserror
do case
case fout=1
retry
case fout=2
return to master
otherwise
foutbezig=&quot;j&quot;
endcase
enddo
else
@ 17,0 to 24,79 clear
@ 17,0 to 21,79 double colo sche 11
@ 17,4 say &quot; Error: &quot; colo sche 11
@ 18,5 say &quot;Program = &quot; colo sche 11 && calling program
@ 19,5 say &quot;Oldprogram= &quot; colo sche 11 && previous program
@ 18,30 say &quot;Number =&quot; colo sche 11
@ 19,30 say &quot;Error =&quot; colo sche 11
@ 20,5 say &quot;Command =&quot; colo sche 11
i=1
do while len(sys(16,i))#0
i=i+1
enddo
@ 18,17 say right(sys(16,i-3),12)
@ 19,17 say right(sys(16,i-4),12)
@ 18,40 say error()
@ 19,40 say message()
@ 20,17 say message(1)
fout=3
foutbezig=&quot;j&quot;
do while foutbezig=&quot;j&quot;
@ 22,0 prompt &quot;\<Dot&quot; message &quot;Cancel program and go to dot-prompt.&quot;
@ 22,col()+1 prompt &quot;\<Continue&quot; message &quot;Pretend error did not ha^ppen.&quot;
@ 22,col()+1 prompt &quot;\<Retry&quot; message &quot;Retry to see whether error happens again.&quot;
@ 22,col()+1 prompt &quot;\<Memo&quot; message &quot;Display memory variables.&quot;
@ 22,col()+1 prompt &quot;\<Record&quot; message &quot;Display actual record.&quot;
@ 22,col()+1 prompt &quot;\<Stat&quot; message &quot;Display status.&quot;
menu to fout
do afsleeg && small program that clears the bottom lines
foutbezig=&quot;n&quot;
on error
on error do afserror
do case
case fout=1
cancel
case fout=2
&& donét do anything
case fout=3
restore screen from oldscreen
if error()=125
set device to print
do &printdef with &quot;elite&quot;
set print on
set console off
endif
retry
case fout=4
disp memo
wait
case fout=5
disp
wait
case fout=6
disp stat
wait
otherwise
foutbezig=&quot;j&quot;
endcase
enddo foutbezig
endif
restore screen from oldscreen
return

hope this can help you as an idea ...

frebev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top