Err.Raise Changes Err.number When Called.
I don't normally post issues I have because I can usually find a solution by searching the forums but I am having trouble with my error handling routine.
I am currently using an error handler that when called saves the current line number, err.number, and description to public variables. In order to preserve this information, I then raise this error so that it is sent up to the calling procedure, where the same information should be likewise recorded until it gets to my main error handler where I email the error information. Here is the problem. If Err.number = 0, this value is recorded to a variable. When I then call Err.Raise using the saved Error number variable, instead of going up to the calling procedure, it runs the same error handler again, changes the error number to 5 and then go up the chain. Why is it doing this? My code is as follows:
90 ErrorNum = Err.Number 'First time is 0, second time changes to five
95 ErrorDescription = Err.Description
100 If ErrorSource = vbNullString Then
105 ErrorSource = PROCEDURE_NAME 'Constant declared in procedure.
110 ErrorLine = Erl
115 End If
120 If ModuleName = vbNullString Then
125 ModuleName = MODULE_NAME 'Constant declared in procedure.
130 End If
135 Err.Raise ErrorNum 'This goes back to line 90, changes err.number then
' goes up to calling procedure with same error handler.
Once Err.number is no longer 0, it goes up the call stack normally.
FYI- Error 5 is "Invalid procedure call or argument"
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Err.Raise Custom Description Replaced W/ Default For Error Number
I'm raising an error from a DLL and when it is caught in the invoking DLL, the Err.Source is blank, and the Err.Description is not the custom message I raised. The Description is set to the default VB description for the actual Err.Number.
I'm running VB 6.0, Service Pack 6, on an XP machine.
The exact same code works in Win2000.
Need To Validate A Phone Number Field Which Will Be Called From An Access Database
I am building a beginner's database for school. I used VB to build a form out of an Access database. My assignment is to validate and automatically edit the phone number field to store the input in a specific format. I know that the logical thing to do would be to lock the input format in the properties, but the assignment is to remove the "1", parentheses, and dashes, if there are any, then display the number in this format...(xxx)xxx-xxxx, regardless of whether the user enters 1-xxx-xxxx, 1xxxxxxx, 1 xxx xxxx, 1(xxx)xxx-xxxx, (xxx)xxx-xxxx, or what have you. Is there a chunk o code out there? Thank you for being here to read these strings and attempt to help, by the way. It is admirable that some have come far enough in their learning and are still motivated to take time to help others....hope to be helping others one day myself...Peace, friends
P.S. Attached is the little database that I am using to build the form. It is in Access 97 format because the learning edition of VB6 will not accept anything else.
Raise Error Or Raise Event?
When dealing with COM+ and DCOM objects distributes across a network and the client tries to save an object, is it best to raise errors back to the UI, or to raise events?
Similar with the Data Tier and Business Tier...events or errors?
"Err.Raise VbObjectError + 501" Gives Err.Number=429
I'm reviewing some old code, amending the error-handling to ensure all Err.Raise statements use numbers beyond the vbObjectError+512 range. I've discovered that the numbers below, when added to vbObjectError and the result placed in Err.Number, all come out as 429 - weird! Luckily, it's easy to reproduce as otherwise I doubt if this would be believed: -
Private Sub Command1_Click()
Err.Number = vbObjectError + x
Substituting "x" above for any of 274, 340, 483, 486, 490, 499, 501 or 510 will result in 429 being displayed by MsgBox. I checked all numbers in the range 0 through 16381, and these are the only ones to give this result.
As these are all outside the recommend range for Err.Raise, my interest is purely academic, but I'd love to know what's going on.
The (slightly modified) original code that drew my attention to this is...
Private Sub Command1_Click()
Dim lngXyz As Long
On Error GoTo ERROR_HANDLER
lngXyz = vbObjectError + 501
MsgBox vbObjectError & vbCrLf & lngXyz & vbCrLf & Err.Number
...the code sample at the top of this post is a simplified illustration.
Caller Passes The Handle To The Being Called, But Can't The Being Called ...
It's a simple little problem. Here's what happens:
Since I believe that no programmer would like to leave his application without as many error handlers as possible to trap even the most unexpected error, I did the same thing. I got a big procedure. It calls many other procedures within it. The main procedure has an error handler of it's own to trap any unexpected errors. Some procedures that are being called by this procedure has it's own error handler. Now when an error occurs in one of the called procedures, besides that procedure handling the error, the error handler of the calling procedure is called and not the one of that procedure. (Hope i made myself clear). Is there anyway to make this not happen or is it simply just not possible.
Can I throw errors out of a class using the err.raise method ?
It doesn't work if I'm trying to execute err.raise within
a class module and to catch the error out of the class.
Should the following work in VBA?
dim c as new Class1
on error goto err_
-------------------End of Module1
public sub f()
--------------------End of Class1
Err Raise In SQL To VB
I am trying to do an erroraise from sql server in a stored procedureto vb and then
show it to the user, but I cant get it together.
anybody with an idea.
I'm probably being a bit slow here but here we go -
I'm having problems capturing errors that I've raised in a class module (in an error handler in the class module) in a component using 'err.raise vbojecterror + 1001' in the form that created an instance of the class. A runtime error is raised and the application stops. The error handling code in the form never gets a chance to handle the runtime error raised in the object.
My understanding of using err.raise in a class would be to raise a runtime error that a form that is using the class could capture and take appropriate action.
I'm using VB6.
How To Raise Event?
i have made an active EXE, in that Active exe i open a database -in a sub- and then i write data to access database with other sub. i use the RecordChangeComplete event of the recordset to trigger an event i have made "Event SavedOK()" but the event inside the project i use it i doesn't raise.The instancing of the class is "GlobalMultiuse".
' The code ..........
Private Sub RecMDB_RecordChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Does anyone can help me how to raise my event???
Question About A Raise...
Or, arrays rather.
Does anyone know if it's possible to determine the number of values in an array? Thanks!
Hi Everyone -
I have a legacy application that performs an err.raise
when there is a fatal error.
I would like to create a "wrapper" around this error message
handler and create a modal dialog with a self dismissing timer
associated with it.
If the application uses this err.Raise throughout the application,
is there a way catch it at all times - kinda like a global catcher??
edit: After looking at the load event, there is an on error handler
that calls the FatalError handler...
so if one of the modules has an error, will the event bubble
back up to the load event and its error handler take care of
popping the fatalerror messages???
How Do I Raise An Event??
What I want to do is...... when I press the downkey/upkey in the form_keydown event I want have that do the same as clicking the corresponding scroll bar. So when I press the up/down keys, then it calls the scrollbar_scroll event??
I have two scroll bars....one that is used to navigate up records in the datagrid, and one that is used to navigate down records in the datagrid. Maybe I don't need to raise an event?? If there is a better way, or if this is the correct way, Please let me know.
Thanks in advance!
How To Raise Events
i have a two forms in a MDI form and i want to raise the keydown event of first form when the keydown event of second form is raised. i don't want to call the procedure but to raise the event. i hope i am clear.
Err.Raise On WinXP Different To NT
VB6.0, SP5, WinXP
I want to use Err.Raise to send an error message to the next level up, so for example;
On Error GoTo 0 ' disable current handler, so the level up can catch
Err.Raise vbObjectError + 101
This works fine on Windows NT, but on Windows XP, I get a runtime error falling on the Err.Raise line, with vbObjectError showing the number -2147221504.
Seems that perhaps vbObjectError constant has not been correctly initialised... (or any number of other weird things).
If anybody knows of a solution to this problem (since I still need to raise the error to the level above), I would be interested. Until then I guess I need to restructure this code to not rely on the error handlers...
Err.Raise && CallByName
I wrote a class module with some method inside.
For each method, I use Err.Raise to raise my own error in the error handler.
The problem is that, if I just call the method as normal, I can get the correct error number. Once I call it using CallByName, it will return 440-Automation Error no matter what the error is, any help???
Err.Raise - Passing It On
What is the best way to pass an error up the stack?
On Error GoTo ErrorHandler
'clean up my stuff
Err.Raise Err.number, Err.source, Err.description
Is that Ok?
How To Raise A Mouseclick???
how to raise a left-button mouse click????????
my prog. has to klick on a button and i need to simulate a mouse click...........
I have one class and one main program which calls that class. In the class, I have trap for an error and use Err.Raise method to fire the error to the main program, but it doesn't work so far.
Any idea? Thanks
Public Function GetRPData() As ADODB.Recordset
On Error GoTo errHandler
Err.Raise vbObjectError + 1000, "Mycode.Mycode", "My own error."
'In case there is another error that is generated by system or provider
Err.Raise Err.Number, Err.Source, Err.Description
'*******************Code in the main program
Private Sub Form_Load()
On Error GoTo errHandler
'My code and declaration......
MsgBox Err.Number & " " & Err.Description
How To Raise In VB A SQL Message
Pls help! I want to raise up a message of SQL 2000 in vb. The messageis a custom one inclued in a store procedure or in a trigger. And I cantsee it when I'm working in alysis querry window of SQL.
What will this do? Throw up (bad choice of words) a message box? I'm too lazy to test it.
Err.Raise vbObjectError + 525, "ConvertReportToPDF.SetupDecompressOrCopyFile", _
"Sorry...cannot Decompress SnapShot File" & vbCrLf & _
"Please select a different Report to Export"
Okay, great and thanks!
Put your PC to good work at vbCity at world community grid and join Team vbCity.
2,669,763 3,325,308 points and ranked 1,195 1,149 as of March 8 May 23, 2008!
Edited by - Geof on 8/21/2008 7:05:07 AM
Err.Raise - Whats Up With This?
How do i propogate the error back to the calling function, and let that function handle it? I am using err.raise but for some reason its not handled in the calling function. It always results in runtime error. BTW, i have an error handler in the calling function.
public Function Add(objfav as clsFavorites, optional key as Variant) as clsFavorites
'some details omitted for clarity
on error GoTo raiseError
'set the properties passed into the method
mCol.Add objfav, key
'return the object
set Add = objfav
How To Raise VB COM Exceptions?
Is there any way in a COM object method to trap an error triggered by calling another COM object and raise an exception of its own? Here is the scenario:
A client calls MyObject.Connect (which is a VB COM object) passing parameters to connect to a database. MyObject calls ADODB.Connection.Open, which may raise an error. What I want is collect information from the Err object (i.e. source, number, and description), generate more detailed error string (such as "Cannot connect to database on server as user because of error Err.Number in Err.Source: Err.Description "), and raise error with my error code and generated error message.
I can do it in C++ using IErrorInfo interface, but cannot figure out how to do the same in VB. I tried to disable error handling (On Error GoTo 0)before raising error, but COM client did not get the error I raised.
Any hints are greatly appreciated. Thank you.
Raise Event , API ??
I would like use event dblClick of my listview. I can use
listview1_dblclick. But can i use another source.
I explain :
I have 2 form (form1 and form2) and 1 module
Form1 have listview1
Form2 have listview2
When i click on spacebar i want call function in module who call the dblclick of my form
listview1_Keypress call Module function call Listview1_dblclick
listview2_Keypress call Module function call Listview2_dblclick
Raise Event For All Clients
Is it easy to create procedure with wincsock that sends notification for all clients that listening eg. port 1234.
AppA.exe ,AppB.exe and AppC.exe need to know when customer changes in CustomerRegister.exe
I have trid to use activex.exe to hadle those events but i think taht winsock is better?
Thanks very much!
How Do I Raise A Global Event ???
Is there any way to make it so a button_click on a form can raise an event
that can be used on all forms in the application, and in the "main" sub
Err.Raise && Loop Should Continue
inside a for-each-loop I am writing
if condition = true then
continue with my code
Err.Raise 53, "A test error", "this is an error"
The reason why I use err.raise is because I want to prevent that my CMS-system continues with the publishing process. You might think: Then do not use the publish-method in "else" but it is not as simple.
So I want that the rest of the code is not executed but the loop should go on
thanks for your ideas
Raise Error In Caller
I'm trying to get to grips with raising errors appropriately in VB6. What I've got is a class method that will only accept parameters of a certain form
Set Class1 = New CTestClass
Class1.CallMethod 1, 2
Public Sub CallMethod(Arg1, Arg2)
If Not (ValidArgs(Arg1, Arg2)) Then
The working aren't important, but you get the idea. Now, what I want to happen is when the error is raised, for the "Class1.CallMethod 1,2" line to be highlighted, not the "Err.Raise .." line - I want the error to be passed up to the caller, rather than raised in the class.
Can this be done?
Am I missing something obvious?
If anyone could guide me along the right route it would be greatly appreciated!
Raise An Event From A Class
I have a class in a usercontrol. I want the usercontrol to respond to an event raised in the class. Its pretty straight forward.
event DoSomthing() 'in class module
private sub Do()
The raiseevent fires but the usercontrols event doesnt respond. I suspect that when I instance the class in the control (private withevents TheClass as ClassName) it dims a new object, rather than instancing the object already there.....I think.
private sub usercontrol1_initialize()
Set TheClass = new ClassName
'I initialize it and the event shows at the top (in usercontrol) where they should but is doesn't fire. When raiseevent fires in the class it just goes to the next line instead of firing the event in the control. HELP!!! (trying to get it to work for 2 days)
How To Raise An Event After A TimeSetEvent
Iím writing an application in VB6.
I have the following problem:
In a class (called TxD) I defined my Serial Communucation Interface using MSCOMM.
Works just fine.
During initialization I must make a special Wakeup pattern. (25 ms Low a followed by 25 ms high signal). For this I use an API call TimeSetEvent and GetCommState and SetCommState in order to make a special Baudrate for sending a sequence of zeroís lasting 25 ms.
The TimeSetEvent must time-out a time of 50 ms. After this messages must be sent
I tested this in a small project where I did not had no classes. That worked fine.
In the TimeSetEvent paratemer list a AddressOf Functionname was included. This function resides in a module.
But now I want to port this to my application. This means that the TimeSetEvent must trigger a method in my TxD class. I canít get it working. It seems that the triggers only works in modules and not in classes.
In donít know how to solve this problem,
Is there a way to raise an event within a triggerroutine in a module????
Please advise meÖ.
Hope to hear from you soon,
Err.raise Generating Error
I have the following error handling code in a function
ErrReport Err.Description, "LiteningFastV7.clsCostCode.AddNew00CostCode", Erl
Err.Raise vbObjectError + 100, _
"clsCostCode component failure"
ErrReport just logs the error to a file.
When an error occurs the err.raise generates an unhandled run time error 80040064 clsCostCode Component Failure. Instead of raising the error to the calling function.
The calling function has error handling code. I don't have a clue why this is happening.
Raise Event Question
I have a little problem I am trying to get around.
First the background: I have an application consisting of and exe and several dll's. In one of the dll's I have several classes, each unique to a piece of hardware my company manufactures. The exe controls the hardware using the classes in the dll.
Now, I am adding a Modem timeout feature to the project. All communication is handled within the dll's. I have the MSComm control on the main form of the exe, then when I instantiate a new object from the dll, I pass the reference of the comm control into the dll and thus send all commands from the dll. The modem timeout has a time period of, say 5 minutes. If the user does not have any activity for 5 minutes, the program should disconnect from the line. If there is activity, it resets the timer and starts counting over. All the timers are software timers written in the dll.
The problem I am having is getting the exe to know the timeout event has fired. I have declared the control variable in a module, since lots of forms use the controls to communicate with the equipment. I need to be able to somehow notify the exe from the dll that the timeout has occured so I can disconnect and reset all the controls.
Does anyone have any ideas how I might go about this?
On Error And Err.raise (solved)
I have a method in a class and I want to raise specific user defined errors, according to the parameters user has passed. In my method code I'm using something like:
Public Sub MyMethod(byval lng as long, ...)
On error goto errH
If lng < 0 then
Err.raise vbObjectError+ 1 , "project.class.method", "No negative"
Elseif Lng > 2000 then
Err.raise vbObjectError+ 2 , "project.class.method", "No greater than 2000 allowed"
here goes my main routine...
I want this class to be used in a dll and in an exe project. I'm testing it as part of the exe project, and when the err.raise statement is executed the error is raised, but the execution is not transferred to the error handling part of the code.
The procedure that's calling the method is as follows
On Error GoTo ERRH
Set ob = New MyClass
How Do I Raise Custom Errors
I have a User Control that needs a user name and a password to be entered on a form. When the user clicks the OK button the user name and password are stored in variables that are located in a class. If the user does not enter a password I want the class to report back to the user that they must enter a pasword. i think you do this by raising custom events. How do I raise custom events or is there a better way of accomplishing this.
How Should I Raise Errors From Components?
I have always wondered, what is the best way to handle errors that occur in my components. An example of my problem would be my database components. At present I have a database component which contains all functions that the program will require for its database interaction.
Public sub Connect(Host as string, UserName as string, Password as string)
set mObjSession = CreateObject("OracleInProcServer.XOraSession")
set mObjDatabase = mObjSession.OpenDatabase(Host, UserName & "/" & Password, 0&)
In the example above, I have created a session object before connecting. If the password was incorrect, the error would be returned to the calling application without destroying the session object. Is this bad programming practice? If so, how should I be doing it?
Err.Raise Event Problem
I'am writing a class module in which one of the method use Err.Raise to display error in its error handler.
When I run the program under VB IDE, it can display the error correctly. Once I build the EXE and run it, it always display 'Automation Error' no matter what error it is. If I just use MsgBox to display what pass to Raise, it is the correct error message.
Error Raise Problem
In my last Thread I asked What the [<Non-Basic Code>] in the call stack was. Now I Want to get passed it.. When I use the Err.Raise function to swap the error to next Sub Or Function and try it to get by the [<Non-basic code>] There is another Error.. Can't you get by it somehow?? anyone??
Raise Events From Collection
I have a collection of classes in which I want to be able to receive events from. Does anyone know how to do this??
Err.Raise And Form_Activate Questions
Thanks for the reply.
Just installed sp 5, but I am still having the problem.
Perhaps I have some funny options set.
Any suggestions on books?
Do you know of an event that tell me if my user selected another application?
Polling Vs. Raise Event
Any advice on using an event instead of polling? I do a lot of polling in my application.
For one, I have to check Reaction Time buttons to see if they are being pressed. It used to really chew up the CPU until I introduced Sleep to my polling loop.
I am already familiar with the timer control and I like it okay I guess. My sleepy loop works fine too, and spares the CPU some work.
But boy, wouldn't it be neat to have a button pressed event just like you get a mouse-click event.
Here's a code sample for how I poll for a rection time button.
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Private Function Button_Pressed(lWait_Time as Long) as Long
'returns elapsed time when button is pressed
'times out after lWait_Time
Dim lStart_Time as Long
Dim lElapsed_Time as Long
lStart_Time = timeGetTime()
Do Until Button_Pressed or lElapsed_Time > lWait_Time
lElapsed_Time = timeGetTime() - lStart_Time
If Get_Button_State() = bsPRESSED Then
Button_Pressed = lElapsed_Time
Sleep 10 'sleep 10 msec, let CPU rest
I suppose I could write a class to raise the event when the button is pressed and then consume the event in my app, but I still have to poll in the class, right?
Any tips much appreciated!
Raise A Custom Event
I'm working on a shell project. i'm using DDE to send messages between my different programs; when the message is put together at the receipent's end, it's fed into a routine so the program knows how to act on the command it's been sent.
The problem is, it takes too long to process the command, so the DDE-sending application times out and throws errors at me. I'm using something like this:
Private Sub Form_LinkExecute(CmdStr as String, Cancel as Integer)
Cancel = 0
So you can see what's happening... it's being sent to a function, which is taking ages to execute and return. Is there a way of making your own event, and then using the RaiseEvent command to fire it?
If not, then i'd appreciate any other ideas as how i could process the data without the LinkExecute sub having to call another sub..
Thanks in advance,
Err Object And Its Raise Method
I have an application, where I have to raise Err.Raise method if something goes wrong. Just curious, is there a way that I can raise the error using Err.Raise method and the User, does not have to click the OK button, to make it go away? For instance is there any property, or something that raises the error msgbox and then disappears after some time delay? Just trying to save the user a click
How Can I Raise An Event For A Certain Control
Lets say I have a special command button object called Command1 which has a Click event defined of course. When the button is actually clicked with the mouse, then internal processing of the special command button user control does a bunch of nice little things internal to its user control code logic (no need to explain). Now, lets say I have a second command button and when it is pressed I would like the Command1 Click event to fire. I can not simply call the Command1_Click() method directly since the actual user control internal processing will not execute.
Is there a way to have the actual Click event for Command1 be thrown? I now the "RaiseEvent" call exists, but I can not figure out how to indicate what event to through for a particular object.
Help would be appreciated .....
What Happens In Class Module With Err.raise?
Back to newbie school here
This is related somewhat to my other error question but a different question. My class module connects to the database. If it can't find the file it raises an error. At the moment my class module error handler is:
Err.Raise Err.Number, "OpenDatabase_Error", Err.Description
What happens specifically when I do that? I thought that raising an error in a class module would pass that error back to the calling procedure...so in my main form where the errorhandler displays a messagebox, shouldn't it display the error? That ain't happening! I am really confused here. the error number for a missing file is:
-2147467259. Instead I am getting a msgbox with the error description 440 Automation Error.
I know it is bad programming practice to show a msgbox from a class module, so when I raise an error in a class module, how do I use that at form level to determine what message to display to the user?
God Bless America
How To Use The Raise Event Feature In VB?
There is an integer varibale called ChanceIndex. There is another function called SolvePuzzle() that solves an incomplete puzzle. Now once my ChanceIndex=0 how should I raise an event and then call SolvePuzzle()?
Raise Error To Parent
I have a form that opens another. I want to Raise an error in that to its parent form. But it doesn't work, as any error stops at the child form and program crashes.
Raise KeyPress When From Is Not In Focus
How do I get the program to raise an keypress event when the program is not in focus? NO through code, but when a person actuall presses a key when it isnt in focus.
HOW-TO: Raise A Parent Event???
I'm developing an UserControl with a TreeView inside. I'm trapping the MouseDown event but I need to invoke the default behaviour for this event too. How can I do it???
Thanx !!! in advance...