473,403 Members | 2,222 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,403 software developers and data experts.

return a value within an event

Sam
Hi,
How, if possible, can I return a value from an event ?
In :

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

btnSave_Click and btnSave.Click must have the same signature so I can't
figure out how to do it.

Any help ?

Thx

Nov 21 '05 #1
5 1401
But these are not return values, they are parameters passed to the event. If
you generate your own event you can pass parameters to be handled.

ie
in a class called file processor I add in my event

Public Event TerminalFailure(ByVal strFailureDescription As String)

Then, when I make use of the class I declare it with events.
Private WithEvents m_FileProcessor As FileProcessor

Now within the code I get the signature as follows:

Private Sub EngineFailure(ByVal strFailureReason As String) Handles
m_FileProcessor.TerminalFailure


"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,
How, if possible, can I return a value from an event ?
In :

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

btnSave_Click and btnSave.Click must have the same signature so I can't
figure out how to do it.

Any help ?

Thx

Nov 21 '05 #2
Sam
Yes I know they are parameters, what I was wondering is how to do
something like:

Private Function btnSave_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnSave.Click as Boolean

Of course this syntax is not correct but how can I make it work ?

Thx

Nov 21 '05 #3
Sam,

You get probably a lot answers on this,

I would do thise case
\\\
BtnSave_Click(sender, nothing)
///
You pass the original sender and the event you cannot pass because it is not
equal.

Because I am not sure if this is completly answers your question, you can
than, when you have not used that already, the Tag for passing a value
first.

sender.tag = myvalue

I hope this helps,

Cor
Nov 21 '05 #4
Sam
Thx.
I think I'll just use a member variable to my class to keep track if
the event succeeded or not (Saving stuff).

Nov 21 '05 #5
"Sam" <sa**************@voila.fr> schrieb:
Private Function btnSave_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnSave.Click as Boolean

Of course this syntax is not correct but how can I make it work ?


Events cannot return values like function procedures. However, you if you
write your own events you can return values to the object raising the event
using custom event arguments:

\\\
Public Event Foo(ByVal sender As Object, ByVal e As FooEventArgs)
..
..
..
Protected Sub OnFoo(ByVal e As FooEventArgs)
RaiseEvent Foo(Me, e)
End Sub
..
..
..
Dim e As New FooEventArgs()
OnFoo(e)
If e.Handled Then
...
Else
...
End If
..
..
..
Private Sub Bla_Foo(ByVal sender As Object, ByVal e As FooEventArgs)
If...Then
e.Handled = True
End If
End Sub
..
..
..
Public Class FooEventArgs
Inherits EventArgs

Private m_Handled As Boolean

Public Property Handled() As Boolean
Get
Return m_Handled
End Get
Set(ByVal Value As Boolean)
m_Handled = Value
End Set
End Property
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
4
by: phil | last post by:
Is there an elegant way that I can return a value from a JavaScript function to ASP.NET? I want to have a popup confirmation dialog using JavaScript and only have a button control execute its ASP...
14
by: libs | last post by:
I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
1
by: mailpitches | last post by:
X-No-Archive: yes a function, the return value of the function is a boolean. What does this boolean value mean? Example: <body onload="document.getElementById('field').onkeydown=function(x) {...
5
by: GiJeet | last post by:
Hello, I'm trying to figure this code out. <input type="submit" onclick="if(!confirm('Are you sure?') return false; "... /> I know that if you return false in an event like this onclick it...
1
by: Constantine AI | last post by:
Hi i am trying to get User input if data does not exist within a DLOOKUP table. I have gotten it to work for one record but not multiple, i have tried to incorporate my code into a loop procedure but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.