AutomationDirect Technical Support
AutomationDirect | Direct Sales in US and Canada | 1-800-633-0405

OPC/DDE server Frequently Asked Questions AutomationDirect Logo


Question

With DsData 4.0 connected to a PLC, I want to be able to store data in integer variables within a Excel visual basic macro so I can manipulate them before placing the values into the spreadsheet.

Answer

The following macro should work:

Sub GetSomeData()

Channel = DDEInitiate("dsdata", "topic")
Fred = DDERequest (Channel, "V7747") 'V7747 was picked because in most DL PLCs this is a changing clock value.

'A little known fact is that the DDERequest returns an array data type. So now Fred is an array.

Cells(1, 1) = Fred 'Displays the value from V7747 in Cell A1.
Wilma = Fred(1) + 1000 'To use Fred in an expression, you must use its array form.
Cells(2, 1) = Wilma 'Displays the new value in A2.

DDETerminate (channel)

End Sub

Every time this macro is executed, the variable "Fred" will have data in it from V7747 in the type of an array. Then using it like an array, you can use it in an expression before outputting it to a cell.

Host Eng.
support@hosteng.com



FAQ Subcategory: CPU & Programming

This item was last updated on 2003-08-28
Document ID: 952


The information provided in the AutomationDirect knowledge base is provided "as is" without warranty of any kind. AutomationDirect disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall AutomationDirect or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if AutomationDirect or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion of limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.


Copyright © 1999- AutomationDirect.com. ALL RIGHTS RESERVED