Hi guys,
I have a machine that is spitting out torque data that I am transferring into excel. I decided to filter it so that I am not overwhelmed with data that I do not require (no torque / 0 values). The data is also converted into inch lbs from NM. New data is added to the top row of the active sheet.
What I am trying to do now is figure out a way to get the most current incoming peak value, display it in a Text box (until the next new peak value comes in) and also store it in a separate sheet.
Sample data:
I've pasted a few points from two cycles of raw data (about 50 data points for each cycle every 30 seconds). For the first cycle I need to extract the -1.035, then the -0.89. (Note: The data is -ve in the data set, but as soon as I apply my filter and conversion into inch lbs, the values will be +ve). The other tricky thing is that the torque cycle may have another relative max in it (eg. -0.645) but I don't want to record that value for that cycle since the final torque will actually be -1.035.
Any input would be greatly appreciated. Thanks!
[TABLE="width: 500"]
<tbody>[TR]
[TD]2/17/2016 3:18:17 PM[/TD]
[TD]-0.005[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:35 PM[/TD]
[TD]-0.89[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:35 PM[/TD]
[TD]-0.805[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:32 PM[/TD]
[TD]-0.51[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:30 PM[/TD]
[TD]-0.155[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:15 PM[/TD]
[TD]-0.17[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:15 PM[/TD]
[TD]-1.035[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:03 PM[/TD]
[TD]-0.445[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:01 PM[/TD]
[TD]-0.645[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:00 PM[/TD]
[TD]-0.275[/TD]
[/TR]
</tbody>[/TABLE]
I have a machine that is spitting out torque data that I am transferring into excel. I decided to filter it so that I am not overwhelmed with data that I do not require (no torque / 0 values). The data is also converted into inch lbs from NM. New data is added to the top row of the active sheet.
What I am trying to do now is figure out a way to get the most current incoming peak value, display it in a Text box (until the next new peak value comes in) and also store it in a separate sheet.
Sample data:
I've pasted a few points from two cycles of raw data (about 50 data points for each cycle every 30 seconds). For the first cycle I need to extract the -1.035, then the -0.89. (Note: The data is -ve in the data set, but as soon as I apply my filter and conversion into inch lbs, the values will be +ve). The other tricky thing is that the torque cycle may have another relative max in it (eg. -0.645) but I don't want to record that value for that cycle since the final torque will actually be -1.035.
Any input would be greatly appreciated. Thanks!
[TABLE="width: 500"]
<tbody>[TR]
[TD]2/17/2016 3:18:17 PM[/TD]
[TD]-0.005[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:35 PM[/TD]
[TD]-0.89[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:35 PM[/TD]
[TD]-0.805[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:32 PM[/TD]
[TD]-0.51[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:30 PM[/TD]
[TD]-0.155[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:15 PM[/TD]
[TD]-0.17[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:15 PM[/TD]
[TD]-1.035[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:03 PM[/TD]
[TD]-0.445[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:01 PM[/TD]
[TD]-0.645[/TD]
[/TR]
[TR]
[TD]2/17/2016 2:52:00 PM[/TD]
[TD]-0.275[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub GetSWData()
Dim Chan As Long
Dim LowLimit, InchLbs, Torque As Double
Dim MyVariantArray As Variant
Dim MyString As String
LowLimit = (-0.05)
InchLbs = (-8.850746)
ColPtr = 1
RowPtr = RowPtr + 1 ' point to the next row down
Chan = DDEInitiate("WinWedge", MyPort) ' initiate DDE link with device
MyVariantArray = DDERequest(Chan, "Field(1)") 'get Field(1) from device
If Val(MyVariantArray(1)) * InchLbs < LowLimit * InchLbs Then ' filter values below 0.05
DDETerminate Chan
Else
Torque = Val(MyVariantArray(1)) * InchLbs ' convert to inch pounds
MyString = Torque ' convert to a string
Range("A1:B1").Insert Shift:=xlDown ' insert two cells at A1 and B1 shifting all data in columns A and B down one row
Sheets(SheetName).Cells(1, ColPtr).Formula = Now ' write the current date and time to the cell A1 (row 1, column 1)
Sheets(SheetName).Cells(1, ColPtr + 1).Formula = MyString ' write the data from device to cell B1 (row 1, column 2)
DDETerminate Chan ' terminate the dde link
End If
'FIND THE MOST RECENT LOCAL MAX
'DISPLAY IN TXT BOX
'SAVE IN DIFF EXCEL SHEET
End Sub