Home All Groups Group Topic Archive Search About

simple but not clicking now

Author
2 Jun 2005 12:03 AM
abcd
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

Author
2 Jun 2005 12:42 AM
Randy Birch
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.


--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



Show quoteHide quote
"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
:
:
:
Author
2 Jun 2005 1:04 AM
Michael Cole
abcd wrote:
Show quoteHide quote
> 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.


--
Regards,

Michael Cole
Author
2 Jun 2005 5:59 AM
abcd
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.
Author
2 Jun 2005 6:30 AM
Michael Cole
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
Author
2 Jun 2005 3:51 PM
abcd
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
>
>
Author
2 Jun 2005 4:58 PM
abcd
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
>
>
Author
3 Jun 2005 12:12 AM
Michael Cole
abcd wrote:
Show quoteHide quote
> 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....

Because the messagebox function has an error - the one that you raised.
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
Author
2 Jun 2005 5:31 PM
Pásztor, Zoltán
abcd wrote:
Show quoteHide quote
> 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

Besides all the other problems pointed out, it is unsafe to expect a
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