Product Selected: OPC/DDE server
Category Selected: CPU & Programming
Press "Ctrl-F" to search for specific words in this FAQ.
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 ID: 952 |