Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default vba events across projects?

Is this possible?

I have a core library (vba project, "LibA") that I want to be ignorant of
any consumers. If I set up a separate project ("LibB") that has a reference
set to "LibA", there are times when I may like to make a piece of
information available from LiibB to LibA.

I thought the natural solution would be to set up an event that broadcasts
the need for information in LibA, with and event handler in LibB to provide
it. Doing so compiles, but doesn't seem to work.

TIA,
Eric


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default vba events across projects?

If LibA is ignorant of LibB then how will it know what to do with the
information ?

I would just set up any required methods in LibA and call them from LibB.

Can you be more specific about the libraries? Or post the code you have
which doesn't work...

Tim




"Eric" wrote in message
news:K5f_f.216$bm6.153@fed1read04...
Is this possible?

I have a core library (vba project, "LibA") that I want to be ignorant of
any consumers. If I set up a separate project ("LibB") that has a
reference set to "LibA", there are times when I may like to make a piece
of information available from LiibB to LibA.

I thought the natural solution would be to set up an event that broadcasts
the need for information in LibA, with and event handler in LibB to
provide it. Doing so compiles, but doesn't seem to work.

TIA,
Eric



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default vba events across projects?

Thanks for the reply. I'm talking about Custom events, and I must apologize
for accidentally posting this twice. Sample code below:

//////////////////////////////////////////////////////////
Class CMsgEx is a class in LibA with the following custom event raised in a
sample method below:
/////////////////////////////////////////////////////////

' post that we are looking for an application title
Public Event applicationTitleRequest(MsgEx As CMsgEx)

Public Function displayInformation(ByVal aMsg As String) As VbMsgBoxResult
RaiseEvent applicationTitleRequest(Me)
icon = Information
Caption = aMsg
Title = aTitle
displayInformation = show
End Function

/////////////////////////////////////////////////
Class CAppFacade is in LibB, and LibB has a refernce to Lib A
////////////////////////////////////////////////

Public WithEvents m_oMsgEx As LibA.CMsgEx

Private Sub m_oMsgEx_applicationTitleRequest(MsgEx As LibA.CMsgEx)
MsgEx.Title = Me.applicationName
End Sub



"Tim Williams" wrote:

If LibA is ignorant of LibB then how will it know what to do with the
information ?

I would just set up any required methods in LibA and call them from LibB.

Can you be more specific about the libraries? Or post the code you have
which doesn't work...

Tim




"Eric" wrote in message
news:K5f_f.216$bm6.153@fed1read04...
Is this possible?

I have a core library (vba project, "LibA") that I want to be ignorant of
any consumers. If I set up a separate project ("LibB") that has a
reference set to "LibA", there are times when I may like to make a piece
of information available from LiibB to LibA.

I thought the natural solution would be to set up an event that broadcasts
the need for information in LibA, with and event handler in LibB to
provide it. Doing so compiles, but doesn't seem to work.

TIA,
Eric




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default vba events across projects?

Eric,

The code below worked for me (at least it did what I expected, but I realize
these two are not always the same thing).
To simplify I created two simple classes in the same project, clsA and clsB.
clsB contains an instance of clsA.

I had to cheat a bit and expose the clsA instance of clsB via a property so
I could trigger the clsA event....

Cheers
Tim


'#### test code
Sub Tester()

Dim oB As clsB
Set oB = New clsB
oB.SubClassA.DisplayConsumerInformation

End Sub

'############### clsA code
Option Explicit

Private m_title As String

Public Event appTitleRequest(ByRef MsgEx As clsA)

Public Sub DisplayConsumerInformation()
Me.Title=""
RaiseEvent appTitleRequest(Me)
MsgBox Me.Title
End Sub

Property Let Title(sTitle As String)
m_title = sTitle
End Property

Property Get Title() As String
Title = m_title
End Property

'##################### clsB code
Option Explicit

Private m_title As String

Public Event appTitleRequest(ByRef MsgEx As clsA)

Public Sub DisplayConsumerInformation()
RaiseEvent appTitleRequest(Me)
MsgBox Me.Title
End Sub

Property Let Title(sTitle As String)
m_title = sTitle
End Property

Property Get Title() As String
Title = m_title
End Property




"Eric Fingerhut" wrote in message
...
Thanks for the reply. I'm talking about Custom events, and I must
apologize
for accidentally posting this twice. Sample code below:

//////////////////////////////////////////////////////////
Class CMsgEx is a class in LibA with the following custom event raised in
a
sample method below:
/////////////////////////////////////////////////////////

' post that we are looking for an application title
Public Event applicationTitleRequest(MsgEx As CMsgEx)

Public Function displayInformation(ByVal aMsg As String) As VbMsgBoxResult
RaiseEvent applicationTitleRequest(Me)
icon = Information
Caption = aMsg
Title = aTitle
displayInformation = show
End Function

/////////////////////////////////////////////////
Class CAppFacade is in LibB, and LibB has a refernce to Lib A
////////////////////////////////////////////////

Public WithEvents m_oMsgEx As LibA.CMsgEx

Private Sub m_oMsgEx_applicationTitleRequest(MsgEx As LibA.CMsgEx)
MsgEx.Title = Me.applicationName
End Sub



"Tim Williams" wrote:

If LibA is ignorant of LibB then how will it know what to do with the
information ?

I would just set up any required methods in LibA and call them from LibB.

Can you be more specific about the libraries? Or post the code you have
which doesn't work...

Tim




"Eric" wrote in message
news:K5f_f.216$bm6.153@fed1read04...
Is this possible?

I have a core library (vba project, "LibA") that I want to be ignorant
of
any consumers. If I set up a separate project ("LibB") that has a
reference set to "LibA", there are times when I may like to make a
piece
of information available from LiibB to LibA.

I thought the natural solution would be to set up an event that
broadcasts
the need for information in LibA, with and event handler in LibB to
provide it. Doing so compiles, but doesn't seem to work.

TIA,
Eric






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default vba events across projects?

Sorry - paste error. The clsB code is wrong. Will repost when I get
home...

Tim



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default vba events across projects?

OK - this is what I used...

'#### test code
Sub Tester()

Dim oB As clsB
Set oB = New clsB
oB.SubClassA.DisplayConsumerInformation

End Sub

'############### clsA code
Option Explicit

Private m_title As String

Public Event appTitleRequest(ByRef MsgEx As clsA)

Public Sub DisplayConsumerInformation()
Me.Title=""
RaiseEvent appTitleRequest(Me)
MsgBox Me.Title
End Sub

Property Let Title(sTitle As String)
m_title = sTitle
End Property

Property Get Title() As String
Title = m_title
End Property

'##################### clsB code
Public WithEvents m_oMsgEx As clsA

Private Sub Class_Initialize()
Set m_oMsgEx = New clsA
End Sub

Private Sub m_oMsgEx_AppTitleRequest(MsgEx As clsA)
MsgEx.Title = Me.AppName
End Sub

Property Get AppName() As String
AppName = "Some App Name"
End Property

Property Get SubClassA() As clsA
Set SubClassA = m_oMsgEx
End Property




"Tim Williams" wrote in message
oups.com...
Sorry - paste error. The clsB code is wrong. Will repost when I get
home...

Tim



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with projects Mike Excel Discussion (Misc queries) 0 February 10th 07 10:51 AM
Same variable name in different projects Anson[_2_] Excel Programming 1 June 18th 04 02:43 PM
Securing VB Projects? Jeffrey Marcellus Excel Programming 1 May 19th 04 07:25 PM
How to become a better programmer, post college. More projects or less projects. Matt Somers Excel Programming 1 February 12th 04 01:54 PM
locked vb projects Terence E Roberts Excel Programming 1 November 20th 03 04:37 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"