-
Oct 14th, 2017, 07:39 PM
#1
Thread Starter
Fanatic Member
What error number to choose for a user-defined run-time error?
If I need to raise a run-time error that I myself declare (user-defined run-time error), what error number do I allocate to it?
What is the acceptable range of numbers from within which I can choose a number for this purpose?
Thanks.
-
Oct 14th, 2017, 08:29 PM
#2
Re: What error number to choose for a user-defined run-time error?
Originally Posted by MSDN
Visual Basic errors (both Visual Basic-defined and user-defined errors) are in the range 065535. The range 0512 is reserved for system errors; the range 51365535 is available for user-defined errors. When setting the Number property to your own error code in a class module, you add your error code number to the vbObjectError constant. For example, to generate the error number 513, assign vbObjectError + 513 to the Number property.
https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx
-
Oct 15th, 2017, 03:21 PM
#3
Thread Starter
Fanatic Member
Re: What error number to choose for a user-defined run-time error?
Thanks for the help
There is a piece of code on this page:
https://www.daniweb.com/programming/...-bin-using-vb6
that I found a while back and copied to my project.
This piece of code is to move a file to recycle bin.
I copied it to my project and it has been working perfectly for me.
Today, I just happened to notice that this code contains a line:
This line has never actually executed since I have been using this code, because this code has always managed to successfully send the file to the recycle bin.
But, should I maintain this line in there as is?
Or should I change it to
Code:
Err.Raise vbObjectError Or 52
Or (because the range 1-512 is reserved, use another number like 513 and the following code:
Code:
Err.Raise vbObjectError Or 513
Please advise.
Thanks.
-
Oct 15th, 2017, 05:39 PM
#4
Re: What error number to choose for a user-defined run-time error?
Originally Posted by IliaPreston
Or should I change it to
Code:
Err.Raise vbObjectError Or 52
Or (because the range 1-512 is reserved, use another number like 513 and the following code:
Code:
Err.Raise vbObjectError Or 513
Please advise.
Thanks.
Never!
See this trappable errors list https://msdn.microsoft.com/en-us/lib...or=-2147217396
Err 52 refer to "Bad file name or number" error, if you want that code popup this error, pass non exist file to Recycle2
The Recycle2 was built very bad, it should add error trap and raise the actual error occured.
If i'm going to use that code, i will change it to
vb Code:
Private Sub Recycle2(ByVal FQFileOrFolder As String) 'Late bound. Dim Delim As Integer Dim FItem As Object Const ssfBITBUCKET = 10 On Error GoTo IO_Err Delim = InStrRev(FQFileOrFolder, "\") With CreateObject("Shell.Application") For Each FItem In .NameSpace(Left$(FQFileOrFolder, Delim - 1)).Items If Not FItem.IsLink Then If UCase$(FItem.Name) = UCase$(Mid$(FQFileOrFolder, Delim + 1)) Then .NameSpace(ssfBITBUCKET).MoveHere FItem End If End If Next End With Exit Sub IO_Err: ' just raise the error occured Err.Raise Err.Number ' ' OR add some check for Err.Number ' If Err.Number = 52 Then ' 'Do something to fix or inform the user about the error ' ElseIf Err.Number = 53 Then ' 'Do something to fix or inform the user about the error ' '. ' '. ' '. ' 'etc... ' End If End Sub
-
Oct 21st, 2017, 04:05 PM
#5
Thread Starter
Fanatic Member
Re: What error number to choose for a user-defined run-time error?
Originally Posted by 4x2y
Never!
...
If i'm going to use that code, i will change it to
vb Code:
Private Sub Recycle2(ByVal FQFileOrFolder As String)
'Late bound.
Dim Delim As Integer
Dim FItem As Object
Const ssfBITBUCKET = 10
On Error GoTo IO_Err
Delim = InStrRev(FQFileOrFolder, "\")
With CreateObject("Shell.Application")
For Each FItem In .NameSpace(Left$(FQFileOrFolder, Delim - 1)).Items
If Not FItem.IsLink Then
If UCase$(FItem.Name) = UCase$(Mid$(FQFileOrFolder, Delim + 1)) Then
.NameSpace(ssfBITBUCKET).MoveHere FItem
End If
End If
Next
End With
Exit Sub
IO_Err:
' just raise the error occured
Err.Raise Err.Number
' ' OR add some check for Err.Number
' If Err.Number = 52 Then
' 'Do something to fix or inform the user about the error
' ElseIf Err.Number = 53 Then
' 'Do something to fix or inform the user about the error
' '.
' '.
' '.
' 'etc...
' End If
End Sub
This new code that you have provided in here does not raise any error even when it should.
For example if a nonexistent file name is passed to this Recycle2 procedure, this procedure doesn't do anything and exits in the end without throwing any error!
-
Oct 21st, 2017, 04:32 PM
#6
Re: What error number to choose for a user-defined run-time error?
Originally Posted by IliaPreston
This new code that you have provided in here does not raise any error even when it should.
For example if a nonexistent file name is passed to this Recycle2 procedure, this procedure doesn't do anything and exits in the end without throwing any error!
That means you have On Error Resume Next (or so) in the procedure that call Recycle2, please test it in new project
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|