Steps to reproduce the problem
- In Visual Basic, create a new ActiveX EXE
project.
- On the Project menu, click References.
- Select Microsoft Excel 2002 Object Library, and then click OK.
- On the Project menu, click Project1 Properties.
- Change the Project Name to "RTDExe", and then click OK.
- Change the Name property of the Class1 class module to "Example".
- Add the
following code to the class module.
Option Explicit
Implements IRtdServer 'Interface allows Excel to contact this RealTimeData server.
Dim nCounter As Long
Private Function IRtdServer_ConnectData(ByVal TopicID As Long, Strings() As Variant, _
GetNewValues As Boolean) As Variant
IRtdServer_ConnectData = nCounter
End Function
Private Sub IRtdServer_DisconnectData(ByVal TopicID As Long)
nCounter = 0
End Sub
Private Function IRtdServer_Heartbeat() As Long
'Do nothing.
End Function
Private Function IRtdServer_RefreshData(TopicCount As Long) As Variant()
Dim aUpdates(0 To 1, 0 To 0) As Variant
nCounter = nCounter + 1
aUpdates(0, 0) = 0 'For this sample, we only refresh topic id = 0
aUpdates(1, 0) = nCounter
TopicCount = 1
IRtdServer_RefreshData = aUpdates
End Function
Private Function IRtdServer_ServerStart(ByVal CallbackObject As Excel.IRTDUpdateEvent) As Long
nCounter = 0
Set oCallBack = CallbackObject
g_TimerID = SetTimer(0, 0, TIMER_INTERVAL, AddressOf TimerCallback)
If g_TimerID > 0 Then IRtdServer_ServerStart = 1 'Any value <1 indicates failure.
End Function
Private Sub IRtdServer_ServerTerminate()
KillTimer 0, g_TimerID
End Sub
- On the Project menu, select Add Module.
- Add the following code to the new module.
Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Public Const TIMER_INTERVAL = 5000
Public oCallBack As Excel.IRTDUpdateEvent
Public g_TimerID As Long
Public Sub TimerCallback(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
ByVal dwTime As Long)
oCallBack.UpdateNotify
End Sub
- On the File menu, click Make RTDExe.exe to build the component.
- In Excel, create a new workbook.
- In cell A1, type the following formula:
=RTD("RTDExe.Example",,"X")
The function returns 0. - After five seconds, the value in A1 increments to indicate
that the server is notifying Excel of updates.
- Start another instance of Excel, and then add a new
workbook.
- In cell A1, type the following formula:
=RTD("RTDExe.Example",,"X")
The function returns 0. - The value in A1 of the second instance of Excel continues
to update. But the value in A1 of the first instance does not. After the
heartbeat interval has elapsed (15 seconds is the default), the first instance
of Excel displays the following error message:
The
real-time data server 'rtdexe.example' is not responding. Would you like
Microsoft Excel to attempt to restart the server?
If you click Yes, the server restarts, and the first instance of Excel receives
update notifications from the server. However, after you restart the server,
the second instance of Excel then generates the same message after the
heartbeat interval has been reached.
To correct the problem so that you do not receive this error,
switch to the project in Visual Basic, change the
Instancing property of the
Example class to
SingleUse, and then rebuild the RTD server.