|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
simple but not clicking nowpublic function fun1(strID as string) as variant on error goto errHandler if not something then func1 = "hello" error.raise 1001, "source", ""hello everybody" end if exit function errHandler: Func1 = "Test Message" err.raise err.number, err.source, err.description end function In my called function I dont get the value of the function as "Test Message" What could be the wrong The syntax is Err.Raise 1001 ..., not Error.Raise. The error you were
actually getting was "Object required", indictaing the Error.Raise syntax was incorrect. -- Show quoteHide quoteRandy Birch MS MVP Visual Basic http://vbnet.mvps.org/ ---------------------------------------------------------------------------- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ ---------------------------------------------------------------------------- "abcd" <a***@abcd.com> wrote in message news:uAzGSawZFHA.3912@TK2MSFTNGP10.phx.gbl... :I have a function : : public function fun1(strID as string) as variant : : on error goto errHandler : : if not something then : func1 = "hello" : error.raise 1001, "source", ""hello everybody" : end if : : exit function : : errHandler: : : Func1 = "Test Message" : err.raise err.number, err.source, err.description : : end function : : : In my called function I dont get the value of the function as "Test Message" : : What could be the wrong : : : abcd wrote:
Show quoteHide quote > I have a function Your function is called "fun1", and you are setting the string into "Func1"?> > public function fun1(strID as string) as variant > > on error goto errHandler > > if not something then > func1 = "hello" > error.raise 1001, "source", ""hello everybody" > end if > > exit function > > errHandler: > > Func1 = "Test Message" > err.raise err.number, err.source, err.description > > end function > > > In my called function I dont get the value of the function as "Test > Message" > > What could be the wrong Try turning on Option Explicit. -- Regards, Michael Cole pls ignore my typos...the actual code looks correct...I have err and func1
correctly written.... I guess this is something scoping issue.... thanks Michael Cole wrote: Show quoteHide quote > abcd wrote: >> I have a function >> >> public function fun1(strID as string) as variant >> >> on error goto errHandler >> >> if not something then >> func1 = "hello" >> error.raise 1001, "source", ""hello everybody" >> end if >> >> exit function >> >> errHandler: >> >> Func1 = "Test Message" >> err.raise err.number, err.source, err.description >> >> end function >> >> >> In my called function I dont get the value of the function as "Test >> Message" >> >> What could be the wrong > > Your function is called "fun1", and you are setting the string into > "Func1"? > > Try turning on Option Explicit. abcd wrote:
> pls ignore my typos...the actual code looks correct...I have err and Then copy and paste the actual code rather than retyping it.> func1 correctly written.... -- Regards, Michael Cole its the big function and I can not copy the function due to security
concern...... Show quoteHide quote "Michael Cole" <no***@hansen.com> wrote in message news:usHnjyzZFHA.3784@TK2MSFTNGP12.phx.gbl... > abcd wrote: >> pls ignore my typos...the actual code looks correct...I have err and >> func1 correctly written.... > > Then copy and paste the actual code rather than retyping it. > > > -- > Regards, > > Michael Cole > > take this example
Private Sub Command1_Click() On Error Resume Next MsgBox calculate End Sub Function calculate() As String On Error GoTo errH x = 10 y = 0 k = x / y calculate = "successful" Exit Function errH: calculate = "failed" Err.Raise 1234, "dsfsd", "test message" End Function Why the message "failed" is not printed when the function is returned with raised error.... thanks Show quoteHide quote "Michael Cole" <no***@hansen.com> wrote in message news:usHnjyzZFHA.3784@TK2MSFTNGP12.phx.gbl... > abcd wrote: >> pls ignore my typos...the actual code looks correct...I have err and >> func1 correctly written.... > > Then copy and paste the actual code rather than retyping it. > > > -- > Regards, > > Michael Cole > > abcd wrote:
Show quoteHide quote > take this example Because the messagebox function has an error - the one that you raised.> > Private Sub Command1_Click() > On Error Resume Next > > MsgBox calculate > > End Sub > > Function calculate() As String > > On Error GoTo errH > x = 10 > y = 0 > > k = x / y > > calculate = "successful" > > Exit Function > > errH: > > calculate = "failed" > > Err.Raise 1234, "dsfsd", "test message" > > End Function > > > Why the message "failed" is not printed when the function is returned > with raised error.... Errors percolate up the call stack. Drop the err.raise in the error handler and you will see the messagebox display the message. The code is operating as it should... Show quoteHide quote > > thanks > > > > "Michael Cole" <no***@hansen.com> wrote in message > news:usHnjyzZFHA.3784@TK2MSFTNGP12.phx.gbl... >> abcd wrote: >>> pls ignore my typos...the actual code looks correct...I have err and >>> func1 correctly written.... >> >> Then copy and paste the actual code rather than retyping it. >> >> >> -- >> Regards, >> >> Michael Cole -- Regards, Michael Cole abcd wrote:
Show quoteHide quote > I have a function Besides all the other problems pointed out, it is unsafe to expect a> > public function fun1(strID as string) as variant > > on error goto errHandler > > if not something then > func1 = "hello" > error.raise 1001, "source", ""hello everybody" > end if > > exit function > > errHandler: > > Func1 = "Test Message" > err.raise err.number, err.source, err.description > > end function > > > In my called function I dont get the value of the function as "Test > Message" > > What could be the wrong function value returned from a function that ended with raising/propagating an error. In the actual implementation VB would really return a simple value prepared before the error even from an external COM+ dll, but complex values are not returned in such case (tried out for detached recordset, and also I think, for Variant). There is a recommendation somewhere saying that remote calls should behave according to the all-or-nothing principle, not exposing partial results. -- PZ |
|||||||||||||||||||||||