VB To PB Translation - Emulate 'With Events' capability in VB

Hi All,

We have a VB application that 'connects' to a donor application using Composia's Digital Cortex OLE Control.  As you can see from the code, the OLE object is defined 'With Events' and therefore the VB application 'listens' for certain events that take place in the donor application.  So if a user clicks on a combobox, the VB application detects that.  If the user changes the value of the combobox, the VB app 'reads' the data and does some processing based on the value of the combobox in the donor app.

Here is the problem.  It seems that PowerBuilder cannot instantiate an instance of the OLE control 'With Events' and listen for events in the donor application like VB can.  Can anyone lend a hand here?

Here is the code:

Thanks for any help here!!!!!!!!  PEM

Here is part of the code that we are having trouble with...
***************************************************************************
     Private Sub Scene1_ControlEvent(ByVal Control As Object) Handles Scene1.ControlEvent
          Dim cb As DCWinControlWrappersLib.DCWinComboBox
          ' Assign control with listbox
          cb = Control
          ' Display recieved events
          Select Case cb.Event
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnItemSelected
                    EventCombo.Items.Insert(0, "wcOnItemSelected, item#" & cb.EventData)
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnDroppedDown
               more....

pemurrayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

buasuwanCommented:
Hi PEM,

I have no Cortex OLE Control for testing your case.
Normally, All OLE Controls can be used within PowerBuilder Environment.
I think it would be better if you place this OLE Control in a window and check the events(ItemSelected, DroppedDown) in the event list on the painter. And you can place your codes in each event insteads of placing in the same script like VB.

Hope this help,
Buasuwan.



pemurrayAuthor Commented:
Dear Buasuawn,

I will try it.

My most sincere thanks for you looking in on me.

Best regards,

Paul

PEM
pemurrayAuthor Commented:
Hi Buasuawn,

I created a new window and dropped the control onto the window.  I right-clicked on the control and then clicked on the events tab.  I did see a different set of events from those I would ordinarily see for the window events.  Among them was the  ControlEvent event.

Is is reasonable to assume that this corresponds to the ControlEvent in the VB code below?

 Private Sub Scene1_ControlEvent(ByVal Control As Object) Handles Scene1.ControlEvent
          Dim cb As DCWinControlWrappersLib.DCWinComboBox
          ' Assign control with listbox
          cb = Control
          ' Display recieved events
          Select Case cb.Event
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnItemSelected
                    EventCombo.Items.Insert(0, "wcOnItemSelected, item#" & cb.EventData)
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnDroppedDown
               more....

Would you be able to help me with 'rearranging the code' to populate this event?  Here is the whole section of the code for reference (I am not asking you to translate the whole thing, but any pointers would be appreciated):

Private Sub Scene1_ControlEvent(ByVal Control As Object) Handles Scene1.ControlEvent
          Dim cb As DCWinControlWrappersLib.DCWinComboBox
          ' Assign control with listbox
          cb = Control
          ' Display recieved events
          Select Case cb.Event
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnItemSelected
                    EventCombo.Items.Insert(0, "wcOnItemSelected, item#" & cb.EventData)
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnDroppedDown
                    EventCombo.Items.Insert(0, "wcOnDroppedDown")
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnClosedUp
                    EventCombo.Items.Insert(0, "wcOnClosedUp")
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnItemAdded
                    EventCombo.Items.Insert(0, "wcOnItemAdded, item#" & cb.EventData)
                    ' Add item to the combobox itemlist
                    cbVB.Items.Insert(cb.EventData, cbWrap.List(cb.EventData))
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnItemRemoved
                    EventCombo.Items.Insert(0, "wcOnItemRemoved, item#" & cb.EventData)
                    ' Remove item from itemlist
                    cbVB.Items.RemoveAt(cb.EventData)
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnTextChanged
                    EventCombo.Items.Insert(0, "wcOnTextChanged")
                    ' Change the combobox text
                    cbVB.Text = cbWrap.Text
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnClick
                    If Not IsNothing(cb.EventData) Then
                         EventCombo.Items.Insert(0, "wcOnClick, item #" & cb.EventData)
                    Else
                         EventCombo.Items.Insert(0, "wcOnClick")
                    End If
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnRightClick
                    If Not IsNothing(cb.EventData) Then
                         EventCombo.Items.Insert(0, "wcOnRightClick, item #" & cb.EventData)
                    Else
                         EventCombo.Items.Insert(0, "wcOnRightClick")
                    End If
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnRightDblClick
                    If Not IsNothing(cb.EventData) Then
                         EventCombo.Items.Insert(0, "wcOnRightDblClick, item #" & cb.EventData)
                    Else
                         EventCombo.Items.Insert(0, "wcOnRightDblClick")
                    End If
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnDblClick
                    If Not IsNothing(cb.EventData) Then
                         EventCombo.Items.Insert(0, "wcOnDblClick, item #" & cb.EventData)
                    Else
                         EventCombo.Items.Insert(0, "wcOnDblClick")
                    End If
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnAllItemsRemoved
                    EventCombo.Items.Insert(0, "wcOnAllItemsRemoved")
                    ' Delete all items from itemlist
                    cbVB.Items.Clear()
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnShow
                    EventCombo.Items.Insert(0, "wcOnShow")
                    ' Make combobox visible
                    cbVB.Visible = True
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnHide
                    EventCombo.Items.Insert(0, "wcOnHide")
                    ' Make combobox invisible
                    cbVB.Visible = False
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnGotFocus
                    EventCombo.Items.Insert(0, "wcOnGotFocus")
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnLostFocus
                    EventCombo.Items.Insert(0, "wcOnLostFocus")
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnEnable
                    EventCombo.Items.Insert(0, "wcOnEnable")
                    ' Make combobox enabled
                    cbVB.Enabled = True
               Case DCWinControlWrappersLib.WinControlWrapperEvent.wcOnDisable
                    EventCombo.Items.Insert(0, "wcOnDisable")
                    ' Make combobox disabled
                    cbVB.Enabled = False
          End Select
          ' Display item information from wich event was recieved
          Count1.Text = CStr(cbWrap.ListCount)
          Text1.Text = cbWrap.Text
          If cbWrap.ListIndex < cbVB.Items.Count Then
               Index1.Text = CStr(cbWrap.ListIndex)
               cbVB.SelectedIndex = cbWrap.ListIndex
          End If
          ' Display last coming event message in the event messages combobox
          EventCombo.SelectedIndex = 0
     End Sub



Thank you again!!

Paul
buasuwanCommented:
Hi Paul,

In this 'ControlEvent event', has any arguement? Is it the same as VB, 'Control'? And what type is it?

Let me try.

in ControlEvent

OLEObject cb, WinControlWrapperEvent
cb = Control

WinControlWrapperEvent = create OLEObject
WinControlWrapperEvent.connectToNewObject('DCWinControlWrappersLib.WinControlWrapperEvent')

choose case cb.Event
case WinControlWrapperEvent.wcOnItemSelected
       //   EventCombo.Items.Insert(0, "wcOnItemSelected, item#" & cb.EventData)
end choose

WinControlWrapperEvent.disconnectObject()
destroy WinControlWrapperEvent
// End

Hope it works,

Buasuwan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.