Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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




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
Adding Delegate in Outlook Dan V[_2_] Excel Programming 1 February 7th 07 09:42 PM
Is VBA Class have Constructor like java ? moonhk Excel Programming 4 October 19th 06 03:44 PM
how do i set up a delegate list in excel nckp Excel Discussion (Misc queries) 1 October 19th 05 09:56 PM
How do I set up an Excel worksheet that compiles data from other . BeginnerExceluser Excel Worksheet Functions 1 March 18th 05 09:01 PM
Code compiles but Excel ERROR Roba Excel Programming 2 May 6th 04 08:29 PM


All times are GMT +1. The time now is 02:50 AM.

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

About Us

"It's about Microsoft Excel"