473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

err.raise + scoping

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
3 1662
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ian McMeans | last post by:
I was bitten by a bug today that depended on how lambda works. It took me quite a while to realize what was going on. First, I made multiple lambda functions inside a loop, each of which...
2
by: David Stockwell | last post by:
Hi, Another of my crazy questions. I'm just in the process of learning so bear with me if you can. I actually ran it.... with two test cases TEST CASE 1: Say I have the following defined:...
2
by: Robert M. Gary | last post by:
I'm curious what the ANSI C++ standard says about nested classes. I'm not able to find where in the ANSI C++ standard this is addressed. The issue is the accessibility of sibling nested classes....
1
by: Michael | last post by:
I am having a problem with scoping of parameters in my XSLT Stylesheet...here is the stylesheet (the xml document is irrelevant for the example) <?xml version="1.0" encoding="UTF-8"?>...
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
17
by: Chad | last post by:
The following question stems from Static vs Dynamic scoping article in wikipedia. http://en.wikipedia.org/wiki/Scope_(programming)#Static_versus_dynamic_scoping Using this sites example, if I...
3
by: SPECTACULAR | last post by:
Hi all. I have a question here.. what kind of scoping does C++ use? and what kind does Smalltalk use? I know smalltalk is a little bit old .. but any help would be appreciated.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.