Question on error number (from Ed Jobe cls)

Question on error number (from Ed Jobe cls)

Anonymous
Not applicable
541 Views
8 Replies
Message 1 of 9

Question on error number (from Ed Jobe cls)

Anonymous
Not applicable
Hi,
from a post by Ed Jobe, that tirelessly generous vb genius lurking around
here at times, I'm trying to understand a couple lines...

Case Is = vbObjectError + 1001, 70 '70 = file access permission denied

I don't under stand this syntax vbObjectError + 1001, 70
the help for the + operator doesn't have any thing about a following comma
and extra argument so I don't quite know what that's doing

any way on my machine, the error when a drawing is already open
-2147467259
and vbObjectError = -2147221504
so I would think I should be using a line like":
Case Is = vbObjectError - 245755

which is very different, can anyone shed some light on this?

also why is it better to use the vbObjectError constant instead of using the
number directly - I would assume its so if vb rewrites it's constants in the
next version but keeps the offsets the same then the old code still
runs...is that the idea? or is it something else???

question 2: (greedy ain't i?)
another error line is:
Set dbxdoc = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
If strExt = "dwt" Then
Err.Raise vbObjectError + 1001
End If

in "vbObjectError + 1001" is the 1001 arbitrary or based on a list of codes
somewhere?


thanks in advance
Mark
0 Likes
542 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Mark Propst wrote:

> the help for the + operator doesn't have any thing about a following
> comma and extra argument so I don't quite know what that's doing

The comma belongs to the Case label, not the addition operator.

> also why is it better to use the vbObjectError constant instead of
> using the number directly - I would assume its so if vb rewrites it's
> constants in the next version but keeps the offsets the same then the
> old code still runs...is that the idea?

Yes.

> in "vbObjectError + 1001" is the 1001 arbitrary or based on a list of
> codes somewhere?

What you're seeing is an application-defined error. vbObjectError + 1001
will indicate something different in someone else's application.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
0 Likes
Message 3 of 9

Anonymous
Not applicable
thanks Frank,
I finally figured most of that out after rereading help some more. Should
have spent more time on that before posting, but the actual returned number
still mystifies me.
Select Case Err.Number
Case Is = -2147221005
Debug.Print "Dbx not registered..."

I get:
Error #:-2147221005 -:- Application-defined or object-defined error
so does that mean that somewhere else in the prog there would have been a
raise statement like
Err.Raise vbObjectError -2147221005
???
then the next test was for file access denied
Case Is = vbObjectError + 1001, 70 '70 = file access permission denied
now I understand that says if the error was 1001 or 70 ...blah...
but the native value for vbObjectError I guess I don't understand why it's
not 0.
does it vary from machine to machine or is an intrinsic constant in vb
on my machine i get

Sub testerr()
Debug.Print "vbObjectError: " & vbObjectError
Dim ErrorNumber
ErrorNumber = vbObjectError
Debug.Print "Error #:" & ErrorNumber & " -:- " & Error(ErrorNumber)
End sub
with the result:
vbObjectError: -2147221504
Error #:-2147221504 -:- Application-defined or object-defined error

so it's saying the built in constant is application defined...
i think i'm not getting something here.

anyway, thanks for the input, I'll keep studying.
Mark

"Frank Oquendo" wrote in message
news:10616BD329348C49992DB80285B1FEF6@in.WebX.maYIadrTaRb...

> Yes.
>
0 Likes
Message 4 of 9

Anonymous
Not applicable
Mark Propst wrote:

> Select Case Err.Number
> Case Is = -2147221005
> Debug.Print "Dbx not registered..."
>
> I get:
> Error #:-2147221005 -:- Application-defined or object-defined error
> so does that mean that somewhere else in the prog there would have
> been a raise statement like Err.Raise vbObjectError -2147221005???

That's the error number VBA returns when ObjectDBX is not registered. It
wasn't defined by Ed Jobe.

> then the next test was for file access denied
> Case Is = vbObjectError + 1001, 70 '70 = file access permission
> denied now I understand that says if the error was 1001 or 70

If the error # is vbObjectError + 1001 (-2,147,220,503) or 70, not 1001
or 70.

> does it vary from machine to machine or is an intrinsic constant in vb
> on my machine i get

vbObjectError is a constant (-2147221504).

> so it's saying the built in constant is application defined...
> i think i'm not getting something here.

No, the application-defined error code is vbObjectError plus an
arbitrary number. That allows you to establish your own set of error
codes for use in your application. It also makes it easier for end users
to trap specific errors.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
0 Likes
Message 5 of 9

Anonymous
Not applicable
ok, i think i get it now.
Thanks so much!
I wonder why Error(vbObjectError) doesn't return something like "intrinsic
constant"?
instead of "Application-defined or object-defined error"?

I was confusing err.number with vbObjectError constant!
Sub testerr()
On Error Resume Next
If Err Then
Debug.Print "Err num:" & Err.Number & vbCrLf & "Err desc:" & Err.Description
Else
Debug.Print "In an error free state, Err.Number = vbObjectError -
vbObjectError "
Debug.Print Err.Number = vbObjectError - vbObjectError

Debug.Print "Err num:" & Err.Number & vbCrLf & "Err desc:" & Err.Description
End If
End sub

Thanks again
Mark

"Frank Oquendo" wrote in message
news:20DA2283A27FF24BAD64290FC398C9E9@in.WebX.maYIadrTaRb...

> vbObjectError is a constant (-2147221504).
0 Likes
Message 6 of 9

Anonymous
Not applicable
Yeah, it was a long time before I figured out what that error message meant too Mark. It's saying that the program you've written called an external application or an object, and an error was returned from that call that is not recognised natively by VB(A). For example it is possible for a call to something external to return an Error 9 which VB knows is a Subscript Out of Range error (off the top of my head - don't quote me). But if it returns Error 923468326 VB (obviously) has no idea what *that* means, so it gives you the best information it can, ie a call to an application or an object has returned an error that was only defined (has meaning) in that application or object, better known as "Application-defined or object-defined error". One of those things that only makes sense in hindsight I reckon.



In a perfect world the documentation for everything you call/use describes all errors that could be returned so that you can cater for them in your calling application. Watch out for those low-flying pigs!



Regards



Wayne Ivory

IT Analyst Programmer

Wespine Industries Pty Ltd
0 Likes
Message 7 of 9

Anonymous
Not applicable
"wivory" wrote in message
news:f1a40ea.4@WebX.maYIadrTaRb...
> Yeah, it was a long time before I figured out what that error message
meant too Mark. It's saying that the program you've written called an
external application or an object, and an error was returned from that call
that is not recognised natively by VB(A).
"Application-defined or object-defined error". One of those things that only
makes sense in hindsight I reckon.

I now get that part. I was just thinking since vbObjectError *was* known by
vb(a), since it's an intrinsic constant, that the return code might not the
the "Application-defined or object-defined error". but i've quit trying to
make sense out of it and just accept it.

a bit of amusement from help:
Visual Basic errors (both Visual Basic-defined and user-defined errors) are
in the range 0-65535. The range 0-512 is reserved for system errors; the
range 513-65535 is available for user-defined errors.
...also from help
Unused error numbers in the range 1 - 1000 are reserved for future use by
Visual Basic.

make up your minds guys...

:-)~

Thanks for the input.
0 Likes
Message 8 of 9

Anonymous
Not applicable
I've been very busy, Mark. I just read this post. Something that wasn't
mentioned about "vbObjectError +1001" is how it makes it convenient to
create custom error #'s. As you mentioned, somewhere else in my code I use
Error.Raise. This error handler comes from a class that handles opening of
dbx doc's and provides error handling for things like when the file is
read-only and opening a dwt instead of just a dwg. There are several places
I raise errors. With this method, you can keep track of simple numbers,
instead of some obtuse number like -2147221504. In the class Declarations, I
have a comment listing the last errror number used. I just started out with
1000. Each time I need a new error number, I just look at the comment and
add one, updating the comment. That way I don't have to search through the
class looking for the last one used.

--
--
Ed
--
"Mark Propst" wrote in message
news:A908BC8BD26065247E550FB5BC6ABF4E@in.WebX.maYIadrTaRb...
>
> "wivory" wrote in message
> news:f1a40ea.4@WebX.maYIadrTaRb...
> > Yeah, it was a long time before I figured out what that error message
> meant too Mark. It's saying that the program you've written called an
> external application or an object, and an error was returned from that
call
> that is not recognised natively by VB(A).
> "Application-defined or object-defined error". One of those things that
only
> makes sense in hindsight I reckon.
>
> I now get that part. I was just thinking since vbObjectError *was* known
by
> vb(a), since it's an intrinsic constant, that the return code might not
the
> the "Application-defined or object-defined error". but i've quit trying to
> make sense out of it and just accept it.
>
> a bit of amusement from help:
> Visual Basic errors (both Visual Basic-defined and user-defined errors)
are
> in the range 0-65535. The range 0-512 is reserved for system errors; the
> range 513-65535 is available for user-defined errors.
> ...also from help
> Unused error numbers in the range 1 - 1000 are reserved for future use by
> Visual Basic.
>
> make up your minds guys...
>
> :-)~
>
> Thanks for the input.
>
>
0 Likes
Message 9 of 9

Anonymous
Not applicable
P.s. Thanks for the compliment. Still in a hurry.

--
--
Ed
--
"Ed Jobe" wrote in message
news:DBAE55729DD90F9E4F01647397E2D6C3@in.WebX.maYIadrTaRb...
> I've been very busy, Mark. I just read this post. Something that wasn't
> mentioned about "vbObjectError +1001" is how it makes it convenient to
> create custom error #'s. As you mentioned, somewhere else in my code I use
> Error.Raise. This error handler comes from a class that handles opening of
> dbx doc's and provides error handling for things like when the file is
> read-only and opening a dwt instead of just a dwg. There are several
places
> I raise errors. With this method, you can keep track of simple numbers,
> instead of some obtuse number like -2147221504. In the class Declarations,
I
> have a comment listing the last errror number used. I just started out
with
> 1000. Each time I need a new error number, I just look at the comment and
> add one, updating the comment. That way I don't have to search through the
> class looking for the last one used.
>
> --
> --
> Ed
> --
> "Mark Propst" wrote in message
> news:A908BC8BD26065247E550FB5BC6ABF4E@in.WebX.maYIadrTaRb...
> >
> > "wivory" wrote in message
> > news:f1a40ea.4@WebX.maYIadrTaRb...
> > > Yeah, it was a long time before I figured out what that error message
> > meant too Mark. It's saying that the program you've written called an
> > external application or an object, and an error was returned from that
> call
> > that is not recognised natively by VB(A).
> > "Application-defined or object-defined error". One of those things that
> only
> > makes sense in hindsight I reckon.
> >
> > I now get that part. I was just thinking since vbObjectError *was* known
> by
> > vb(a), since it's an intrinsic constant, that the return code might not
> the
> > the "Application-defined or object-defined error". but i've quit trying
to
> > make sense out of it and just accept it.
> >
> > a bit of amusement from help:
> > Visual Basic errors (both Visual Basic-defined and user-defined errors)
> are
> > in the range 0-65535. The range 0-512 is reserved for system errors; the
> > range 513-65535 is available for user-defined errors.
> > ...also from help
> > Unused error numbers in the range 1 - 1000 are reserved for future use
by
> > Visual Basic.
> >
> > make up your minds guys...
> >
> > :-)~
> >
> > Thanks for the input.
> >
> >
>
>
0 Likes