ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delegate constructor compiles in VB.NET, but not in Excel VBA (https://www.excelbanter.com/excel-programming/443092-delegate-constructor-compiles-vbulletin-net-but-not-excel-vba.html)

microsoftCraze

Delegate constructor compiles in VB.NET, but not in Excel VBA
 


I have created a DLL callback through a delegate function.
It works fine when the client is C#, or VB.NET.
I can't get it to compile in Excel VBA. I have this problem both in Excel
2003 and Excel 2007.
The DLL references setting is ok, because when I take the reference out the
compiler errors out on RemoteProcess.
What am I missing?

The snippets below are the dll code, the working vb.net client code, and the
failing vba code.

===========================================
The remoteprocess class is compiled as dll:
===========================================
Public Class RemoteProcess
Public Delegate Sub RemoteProcessResultMessage(ByVal sMsg As String)
Public Sub runIt(ByVal callback As RemoteProcessResultMessage)
callback("Hello World!")
End Sub
End Class


===========================================
The VB Client code, which works well:
===========================================
Imports RemoteProcess
Imports System.Runtime.InteropServices

Public Class Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
Dim rpResponse As
RemoteProcess.RemoteProcess.RemoteProcessResultMes sage
rpResponse = New
RemoteProcess.RemoteProcess.RemoteProcessResultMes sage(AddressOf
ServerResponse)
Dim rp As RemoteProcess.RemoteProcess
rp = New RemoteProcess.RemoteProcess
rp.runIt(rpResponse)
End Sub
Private Sub ServerResponse(ByVal sMessage As String)
MsgBox("Received response: " & sMessage)
End Sub
End Class



================================================== ====================================
The Excel VBA Client code, which does not compile.
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Expected: end of statement
---------------------------
OK Help
---------------------------
The highlight is on the open parenthesis in the constructor.
It looks like the AddressOf parameter is not expected, but we know it's needed
================================================== ====================================
Public Sub RunRemote()
Dim rpResponse As RemoteProcess.RemoteProcess.RemoteProcessResultMes sage
set rpResponse = New
RemoteProcess.RemoteProcess.RemoteProcessResultMes sage(AddressOf
ServerResponse)

Dim rp As RemoteProcess
rp = New RemoteProcess.RemoteProcess
rp.RunIt (rpResponse)
End Sub

Private Sub ServerResponse(ByVal sMessage As String)
MsgBox ("Received response: " & sMessage)
End Sub






All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com