By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

err.raise + scoping

P: n/a
this is simple VB question but its not clicking me right now...the code is
as below
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
'I am expecting that calculate should return "failed" but its returning
empty,

What could be the cause...basically I want to get a value as a return value
from the error handler...

[its shame on me that I am microsoft certified in VB 6.0 (both desktop and
distributed and I can not solve this]
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ohhhh. Well you should be trapping an exception here:


Private Sub Command1_Click()
MsgBox calculate
End Sub

Function calculate() as String

Dim x as integer = 10
Dim y as integer = 0
Dim k as integer

Try

k = ( x / y )

Return "Success"

Catch Ex as Exception

Return "Failure"

End Try

End Function

"abcd" <ab**@abcd.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
this is simple VB question but its not clicking me right now...the code is
as below
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
'I am expecting that calculate should return "failed" but its returning
empty,

What could be the cause...basically I want to get a value as a return
value from the error handler...

[its shame on me that I am microsoft certified in VB 6.0 (both desktop and
distributed and I can not solve this]

Nov 21 '05 #2

P: n/a
You raised an error, so the function cannot return a value.

--
Jonathan Allen
"abcd" <ab**@abcd.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
this is simple VB question but its not clicking me right now...the code is
as below
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
'I am expecting that calculate should return "failed" but its returning
empty,

What could be the cause...basically I want to get a value as a return
value from the error handler...

[its shame on me that I am microsoft certified in VB 6.0 (both desktop and
distributed and I can not solve this]

Nov 21 '05 #3

P: n/a
Thanks. You are right.

I found alternate solution like passing a returnvariable byref and getting
the result value into that variable....(like C++ out parameter)

thanks

"Jonathan Allen" <x@x.x> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
You raised an error, so the function cannot return a value.

--
Jonathan Allen
"abcd" <ab**@abcd.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
this is simple VB question but its not clicking me right now...the code
is as below
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
'I am expecting that calculate should return "failed" but its returning
empty,

What could be the cause...basically I want to get a value as a return
value from the error handler...

[its shame on me that I am microsoft certified in VB 6.0 (both desktop
and distributed and I can not solve this]


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.