urgent : error handler in Infopath 2003 VBS

  • Thread starter Didier Maignan - Interprojet
  • Start date
D

Didier Maignan - Interprojet

Contrary to VBA, There is no "ON error goto" to handle error and prevend
users from seiign a call for ...debugging the form.

I see a lot of stuff on JS but nothing consistent on VBS. Can you propose a
VBS generic code to show a message box on error occuring with the
errordetailedDescription as an information message box (and with no button
for debugging)

Thx a lot
 
S

S.Y.M. Wong-A-Ton

To get a misconception out of the way: The VBScript used in InfoPath is not a
"special kind" of VBScript. It is the normal VBScript used everywhere else
for scripting. Since VBA is a close cousin of Visual Basic (the programming
language), it supports many things that VB supports. VBScript is quite
limited compared to VB.

Having said that, you can use "On Error Resume Next" at the top of your code
and then test for Err.Number being unequal to zero after each line where you
suspect an error might occur. So do something like

Dim obj
On Error Resume Next
Set obj = CreateObject("Foo")
If Err.number <> 0 Then
MsgBox "An error occurred"
End If
 
D

Didier Maignan - Interprojet

Thx a lot SYM

This is very interesting. It works. I tried to go further now. I explore
with very little success several solution to track the exact error so that
users are not trapped with a debugging error.
The fact is that VBS Infopath error events are apparently 2 : resume and
goto 0
Is it possible to build a module for error management with that ?

FYI My code makes call to XML and to SQL server as datasources, and also
writes onto Project Professional wich can also trigger error if the
application meets a problem.

for instance something like this :
If err.number<>0 then
message="Error N° "& Err.number & " of type " & Err.Source & " appeared : "
& chr(13) & Err.Description & " Please contact your admin."
MyVar=msgbox(message ,48,"error was detected in your form" )

this one does not work properly.

Can you help with detailed error handling ?
 
S

S.Y.M. Wong-A-Ton

Why does it not work properly, Didier? Are you getting error messages? Other
than not having broken the message string properly, it worked fine for me.

You must let the concept of "modules" go when using VBScript. What you can
do is write a general function or subroutine that will display an error
message when an error occurs, and call this function/sub after each line in
your code where you think an error might occur. So add a function like this
to your code

Sub CheckForErrors
Dim Message
Dim Answer
If Err.number <> 0 Then
Message= "Error N° " & Err.number & " of type " & Err.Source & "
appeared: " & Chr(13) & Err.Description & " Please contact your admin."
Answer = MsgBox(Message ,48,"error was detected in your form")
End If
Err.Clear
End Sub

Remember to use proper line continuation characters (&_) when constructing
the string for the "Message". Then you can call this sub after each line in
your code like this

Dim obj
On Error Resume Next
Set obj = CreateObject("Foo")
CheckForErrors
 
D

Didier Maignan - Interprojet

Thx SYM

We tried that. Thansk la lot.
If there is an error (Foo or databse connection or whatelse ) this is OK
But in case of no error : there is an ... error on the line :
If Err.number <> 0 Then

so this procedure is not applicable for all cases , except if there IS an
error.
So this is not convenient.

Didier
 
S

S.Y.M. Wong-A-Ton

Let me see if I understood you correctly. If you add "If Err.number <> 0
Then" etc. in your code and no error occurred, the line causes an error? If
so, what is the error message?

I tried it and it worked fine on my end. Try creating a new form (a clean
start) with a button that has only that line of code (including and End If of
course) in it and test it. The only error that I can imagine taking place is
that the "Err" object could be "Nothing", but according to me this object is
always defined.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top