[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Passing "Events" From A Module

BeeJ

2/16/2012 9:33:00 PM

So I have a lot of code in a module.
And I do not want or need to convert it to a Class.

Modules do not support events.
So how can I do an event-like operation.

I tried to fiddle with AddressOf and that is not appropriate (or I
could not figure it out). Only class (unrelated) methods showed up
and that would be the long way around (class method raise an event back
to the form).

I tried to set a Form method to an object in the module to simply do a
"callback" but that does not seem to be allowed.

I could pass the module a hidden control and use the control change
event to do what I want.

I could run a timer watching for a global variable in the module
change.

For this kind of thing I can only think of Object or Control to use but
can't figure out how to use Object.

Is there a more better (simple) way?

I do not think I have ever seen anything like this done before.


16 Answers

unknown

2/16/2012 9:54:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jhjsml$ugt$1@speranza.aioe.org...
> So I have a lot of code in a module.
> And I do not want or need to convert it to a Class.
>
> Modules do not support events.
> So how can I do an event-like operation.
>
> I tried to fiddle with AddressOf and that is not appropriate (or I could
> not figure it out). Only class (unrelated) methods showed up and that
> would be the long way around (class method raise an event back to the
> form).
>
> I tried to set a Form method to an object in the module to simply do a
> "callback" but that does not seem to be allowed.
>
> I could pass the module a hidden control and use the control change event
> to do what I want.
>
> I could run a timer watching for a global variable in the module change.
>
> For this kind of thing I can only think of Object or Control to use but
> can't figure out how to use Object.
>
> Is there a more better (simple) way?
>
> I do not think I have ever seen anything like this done before.

Why are you looking for a complicated solution when a simple solution is
available? How about adding this to your module:

Public Sub IamAnEvent(ByRef s As String)
Debug.Print "IamAnEvent: s = " & s
End Sub

And call it from anywhere in the project.



Karl E. Peterson

2/16/2012 9:55:00 PM

0

BeeJ pretended :
> So I have a lot of code in a module.
> And I do not want or need to convert it to a Class.
>
> Modules do not support events.
> So how can I do an event-like operation.

Use a class.

> I tried to fiddle with AddressOf and that is not appropriate (or I could not
> figure it out). Only class (unrelated) methods showed up and that would be
> the long way around (class method raise an event back to the form).
>
> I tried to set a Form method to an object in the module to simply do a
> "callback" but that does not seem to be allowed.
>
> I could pass the module a hidden control and use the control change event to
> do what I want.
>
> I could run a timer watching for a global variable in the module change.
>
> For this kind of thing I can only think of Object or Control to use but can't
> figure out how to use Object.
>
> Is there a more better (simple) way?
>
> I do not think I have ever seen anything like this done before.

But if you insist on being somewhat silly, WM_BROADCAST it. <shrug>

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

2/16/2012 9:58:00 PM

0

Karl E. Peterson was thinking very hard :
> BeeJ pretended :
>> I do not think I have ever seen anything like this done before.
>
> But if you insist on being somewhat silly, WM_BROADCAST it. <shrug>

Mispoke.

SendMessage(HWND_BROADCAST, RegisteredWindowMessage(), yada, yada)

--
..NET: It's About Trust!
http://vfre...


BeeJ

2/16/2012 10:16:00 PM

0

Yeah but ... that locks the module to call by name rather than call by
reference, which is the most general portable case.


BeeJ

2/16/2012 10:18:00 PM

0

I am exploring things I have never seen before.
I could create a little class to do just this op but wonding if there
is not another way.


BeeJ

2/16/2012 10:19:00 PM

0

Karl E. Peterson formulated the question :
> Karl E. Peterson was thinking very hard :
>> BeeJ pretended :
>>> I do not think I have ever seen anything like this done before.
>>
>> But if you insist on being somewhat silly, WM_BROADCAST it. <shrug>
>
> Mispoke.
>
> SendMessage(HWND_BROADCAST, RegisteredWindowMessage(), yada, yada)

Unconventional (not silly) is more fun.


Karl E. Peterson

2/16/2012 11:14:00 PM

0

BeeJ used his keyboard to write :
> Karl E. Peterson formulated the question :
>> Karl E. Peterson was thinking very hard :
>>> BeeJ pretended :
>>>> I do not think I have ever seen anything like this done before.
>>>
>>> But if you insist on being somewhat silly, WM_BROADCAST it. <shrug>
>>
>> Mispoke.
>>
>> SendMessage(HWND_BROADCAST, RegisteredWindowMessage(), yada, yada)
>
> Unconventional (not silly) is more fun.

I won't disagree. :-)

You seem to be a recreational programmer. Nothing wrong with that!
When "real world constraints" aren't a factor, you might as well play.

--
..NET: It's About Trust!
http://vfre...


Larry Serflaten

2/17/2012 12:06:00 AM

0

On Feb 16, 3:32 pm, BeeJ <nos...@spamnot.com> wrote:
> So I have a lot of code in a module.
> And I do not want or need to convert it to a Class.
>
> Modules do not support events.
> So how can I do an event-like operation.


Nearly all events are initiated by some user action, which then calls
a routine to handle the event. Code in a module does not interact
with a user, so no events are provided.

Also events are a notification system, so that when an
action happens, other interested parties can respond.

So, the question is, what is happening in your module that
you want to raise an event, and who do you want to respond?

LFS

unknown

2/17/2012 1:45:00 AM

0

Since BeeJ forgot to include what he responded to, I am including it below:

"Farnsworth" <nospam@nospam.com> wrote in message
news:jhjttr$1q6$1@speranza.aioe.org...
> "BeeJ" <nospam@spamnot.com> wrote in message
> news:jhjsml$ugt$1@speranza.aioe.org...
>> So I have a lot of code in a module.
>> And I do not want or need to convert it to a Class.
>>
>> Modules do not support events.
>> So how can I do an event-like operation.
>>
>> I tried to fiddle with AddressOf and that is not appropriate (or I could
>> not figure it out). Only class (unrelated) methods showed up and that
>> would be the long way around (class method raise an event back to the
>> form).
>>
>> I tried to set a Form method to an object in the module to simply do a
>> "callback" but that does not seem to be allowed.
>>
>> I could pass the module a hidden control and use the control change event
>> to do what I want.
>>
>> I could run a timer watching for a global variable in the module change.
>>
>> For this kind of thing I can only think of Object or Control to use but
>> can't figure out how to use Object.
>>
>> Is there a more better (simple) way?
>>
>> I do not think I have ever seen anything like this done before.
>
> Why are you looking for a complicated solution when a simple solution is
> available? How about adding this to your module:
>
> Public Sub IamAnEvent(ByRef s As String)
> Debug.Print "IamAnEvent: s = " & s
> End Sub
>
> And call it from anywhere in the project.

Yeah but ... that locks the module to call by name rather than call by
reference, which is the most general portable case.



unknown

2/17/2012 1:47:00 AM

0

Oops. I forgot to do what BeeJ was supposed to do, trim the post to what he
was responding to:

"Farnsworth" <nospam@nospam.com> wrote in message
news:jhjttr$1q6$1@speranza.aioe.org...
> Why are you looking for a complicated solution when a simple solution is
> available? How about adding this to your module:
>
> Public Sub IamAnEvent(ByRef s As String)
> Debug.Print "IamAnEvent: s = " & s
> End Sub
>
> And call it from anywhere in the project.

Yeah but ... that locks the module to call by name rather than call by
reference, which is the most general portable case.