Excel VBA to VB (DCOM)

I have inherited an Excel VBA spreadsheet. I was instructed to convert it to VB.

I think the application receives data from the PLC using the DCOM object. The following code launches sub SBR1Select when updating MX1.0.

Sub Workbook_Open() ActiveWorkbook.SetLinkOnData "dassidirect|strandburner!MX1.0", "SBR1Select" End Sub 

When I open the control panel → “Administration” → “Component Services”, and then go to “Console Root” → “Component Services” → “Computers” → “My Computer” → “DCOM”, select the “DASSIDirect” item which I I consider what Excel links.

How to connect the VB code to the PLC through the DASSIDIRECT component?

NOTE. DASSIDIRECT is also a Windows service (not sure if this will help answer the question).

+4
source share
3 answers

I worked with the PLC for a while and asked one of my old colleagues. He says you need InTouch from WonderWare, which has a set of compatible .Net 2 assemblies that will work with DASSIDIRECT to give you what you need.

Here is the latest version, and I hope this is what you are looking for.

+1
source

Wow, DDE. DDE, as I'm sure you know, is pretty old. Network DDE has already depreciated and will no longer work in Vista. I can only imagine that the trend is likely to continue. However, the DDE API in user32 still works (link here: http://msdn.microsoft.com/en-us/library/ms674605(VS.85).aspx ), and you can call this from .net applications using a bit composition. The only examples I could find were for VB6, and they were old even then. As I am sure you can imagine it hurts a little. Anyway, I dug this example from the API guide (from Mentalis). This is not .Net, but you still need to start:

 'This application shows you how to use DDE to create a better PrevInstance-function. 'Compile this sample and start it two times 'The first instance minimizes itself and when the second instance is started, it will 'send a message to the first instance to maximize itself. 'in a module Public Const VBServerName = "TestServer" Public Const VBTopicName = "SHOW_YOUR_MAIN_WINDOW" Public Const XCLASS_BOOL = &H1000 Public Const XTYPF_NOBLOCK = &H2 ' CBR_BLOCK will not work Public Const XTYP_CONNECT = &H60 Or XCLASS_BOOL Or XTYPF_NOBLOCK Public Const CP_WINANSI = 1004 ' default codepage for windows & old DDE convs. Public Const SW_RESTORE = 9 Public Const DDE_FACK = &H8000 Public Const XCLASS_FLAGS = &H4000 Public Const XTYP_EXECUTE = &H50 Or XCLASS_FLAGS Public Const DNS_REGISTER = &H1 Public Const DNS_UNREGISTER = &H2 Public Declare Function DdeInitialize Lib "user32" Alias "DdeInitializeA" (pidInst As Long, ByVal pfnCallback As Long, ByVal afCmd As Long, ByVal ulRes As Long) As Integer Public Declare Function DdeCreateStringHandle Lib "user32" Alias "DdeCreateStringHandleA" (ByVal idInst As Long, ByVal psz As String, ByVal iCodePage As Long) As Long Public Declare Function DdeConnect Lib "user32" (ByVal idInst As Long, ByVal hszService As Long, ByVal hszTopic As Long, pCC As Any) As Long Public Declare Function DdeNameService Lib "user32" (ByVal idInst As Long, ByVal hsz1 As Long, ByVal hsz2 As Long, ByVal afCmd As Long) As Long Public Declare Function DdeFreeStringHandle Lib "user32" (ByVal idInst As Long, ByVal hsz As Long) As Long Public Declare Function DdeQueryString Lib "user32" Alias "DdeQueryStringA" (ByVal idInst As Long, ByVal hsz As Long, ByVal psz As String, ByVal cchMax As Long, ByVal iCodePage As Long) As Long Public Declare Function DdeUninitialize Lib "user32" (ByVal idInst As Long) As Long Function DdeCllback(ByVal uType As Long, ByVal uFmt As Long, ByVal hConv As Long, ByVal hszTopic As Long, ByVal hszItem As Long, ByVal hData As Long, ByVal dwData1 As Long, ByVal dwData2 As Long) As Long DdeCllback = Form1.AppDdeCallback(uType, uFmt, hConv, hszTopic, hszItem, hData, dwData1, dwData2) End Function 'in a form Dim isRun As Boolean, idInst As Long, hszVBServer As Long, hszVBTopic As Long Dim hconvVBServer As Long, dderesult As Long Private Sub Form_Load() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net If DdeInitialize(idInst, AddressOf DdeCllback, 0, 0) Then Exit Sub hszVBServer = DdeCreateStringHandle(idInst, VBServerName, CP_WINANSI) hszVBTopic = DdeCreateStringHandle(idInst, VBTopicName, CP_WINANSI) 'try to find the first instance hconvVBServer = DdeConnect(idInst, hszVBServer, hszVBTopic, ByVal 0&) If hconvVBServer Then Unload Me Exit Sub End If DdeNameService idInst, hszVBServer, 0, DNS_REGISTER Me.WindowState = vbMinimized End Sub Private Sub Form_Unload(Cancel As Integer) DdeFreeStringHandle idInst, hszVBServer DdeFreeStringHandle idInst, hszVBTopic 'only unregister the DDE server for first instance If isRun Then If DdeNameService(idInst, hszVBServer, 0, DNS_UNREGISTER) Then MsgBox "in ServiceUnRegister", vbOKOnly, "Error" End If End If DdeUninitialize idInst End Sub Function AppDdeCallback(ByVal wType As Long, ByVal wFmt As Long, ByVal hConv As Long, ByVal hszTopic As Long, ByVal hszItem As Long, ByVal hData As Long, ByVal lData1 As Long, ByVal lData2 As Long) As Long Dim iCount As Long, Buffers As String, Ret As Long Select Case wType Case XTYP_CONNECT iCount = DdeQueryString(idInst, hszTopic, vbNullString, 0, CP_WINANSI) Buffers = Space(iCount) DdeQueryString idInst, hszTopic, Buffers, iCount + 1, CP_WINANSI If Buffers = VBTopicName Then Me.WindowState = vbNormal 'add any code for the first instance have found the second one is launch Ret = DDE_FACK End If AppDdeCallback = Ret Case XTYP_EXECUTE AppDdeCallback = Ret End Select End Function 
0
source

The easiest way to handle this is to use VB 6 and create an "ActiveX EXE" that passes the DDE to SIDirect. Running DDE with VB 6 is trivial. Then create the primary interaction assembly for the VB 6 module using tlbimp or just an EXE link as a COM component from your C # code.

0
source

All Articles