1. Tracy Lamb
  2. PowerBuilder
  3. Saturday, 28 October 2023 16:36 PM UTC

Hi all,

My application registers with Windows as a DDE Server, and communicates with several different 3rd party apps through DDE.  We're just now exploring how to communicate via Excel by the same means.

In Excel, I put a button on the worksheet to request information from my app.  This works fine. Excel requests the current row number, and the correct response is received by Excel.  I can also request the row count, and the correct response is received by Excel.

I put another button on the worksheet to wrte information to my app.  This doesn't work.  In fact, the remotesend event in my app isn't even triggered. (I put MessageBox's in the remotesend, remoterequest and remoteexec event for testing purposed.) The code I'm using is Excel is :

Sub Button5_Click()

Dim channelNumber As Long
Dim dataToSend As String
Dim dataSendTo As String

dataSendTo = "3~tAsFound"
dataDataToSend = "Poke"

channelNumber = Application.DDEInitiate(app:="CMI Datasheet", topic:="1000453600")
Application.DDEPoke channelNumber, dataSendTo, dataDataToSend
Application.DDETerminate channelNumber

End Sub

I tried enclosing the DDEPoke command with (...) For some reason, Excel doesn't like it!  The documentation I found on DDEPoke doesn't have () either.

I'm just wondering why remotesend event doesn't even get triggered.  Any thoughts, advice would be appreciated.

~~~Tracy

Accepted Answer
Tracy Lamb Accepted Answer Pending Moderation
  1. Sunday, 29 October 2023 15:19 PM UTC
  2. PowerBuilder
  3. # Permalink

I figured out how to get the remotesend event to trigger from Excel script.  

Sub Button5_Click()

Dim channelNumber As Long
Dim dataSendTo As String

dataSendTo = Worksheets("Sheet1").Cells(3, 2).Value & vbTab & Worksheets("Sheet1").Cells(5, 2).Value
Set workOrder = Worksheets("Sheet1").Range("B1")
Set cellToPoke = Worksheets("Sheet1").Range("B6")
channelNumber = Application.DDEInitiate(app:="CMI Datasheet", topic:=workOrder)
Application.DDEPoke channelNumber, dataSendTo, cellToPoke
Application.DDETerminate channelNumber

End Sub

Still not sure why I can't substitute actual strings instead of having to make reference calls to cells on the worksheet, but I guess that's a different topic perhaps for a different user group.  Any ideas you might have would be appreciated.  

~~~Tracy

 

Comment
  1. Tracy Lamb
  2. Sunday, 29 October 2023 18:18 PM UTC
Thanks Mark.

I tried eliminating the declaration of dataSendTo and just using the SET statement as I do with cellToPoke. This causes an error, probably because dataSendTo is a concatonation of 2 cells with a tab character between each value. I changed the Declaration from String to Variant. This does work, just as setting the declartion to String works so defining it as String or Variant doesn't seem matter. Either way I still have to include the line that says "dataSendTo = ... " .



The "topic:=" parameter is in the DDEInitiate command, not the DDEPoke command. I changed it because the topic was originally hardcoded, and I wanted it to come from a cell on the spreadsheet.
  1. Helpful
  1. Tracy Lamb
  2. Sunday, 29 October 2023 18:24 PM UTC
I emailed my customer today and told him I'm not interested in becoming an Excel VBA expert, lol! But I did provide him with the worksheet and buttons he needs to use the DDE commands my application responds to... DDERequest (remoterequest), DDEPoke (remotesend) and DDEExec (remoteexec).
  1. Helpful
  1. Mark Goldsmith
  2. Sunday, 29 October 2023 19:47 PM UTC
Lol...sounds good and thanks for the update. Yes, I knew the "topic:"= was in the DDEInitiate line, just wasn't sure it was necessary to change it from a quoted string to a variable in order for it to work, but I understand now you changed it for flexibility versus trying to get it to work.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 28 October 2023 17:15 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tracy;

Can you tell us...

  • PB version & build
  • O/S version & build
  • Excel version & build

Regards ... Chris 

Comment
  1. Tracy Lamb
  2. Saturday, 28 October 2023 19:12 PM UTC
PB: 2021,1509

OS: Win10 Home, 19045

Excel: Microsoft 365, 2309, 16.0.16827.2016



I kind of got it working... at the the remotesend event is being trigger. This seems to work OK, but don't understand why I can't put literal string instead of references to cell:

Sub Button5_Click()

Dim channelNumber As Long

Dim dataSendTo As String

dataSendTo = Range("A1").Value & vbTab & Range("A4").Value

Set cellToPoke = Worksheets("Sheet1").Range("B4")

channelNumber = Application.DDEInitiate(app:="CMI Datasheet", topic:="1000453600")

Application.DDEPoke channelNumber, dataSendTo, cellToPoke

Application.DDETerminate channelNumber



End Sub

  1. Helpful
  1. Tracy Lamb
  2. Saturday, 28 October 2023 19:13 PM UTC
At least the remotesend event is being triggered.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.