Solution
To display the difference between the left and right edge of the band cursor, you can use the P1 and P2 of the cursor object.
This corresponds to the index for the two channel values that you want to calculate. To display this value somewhere, you could add a text area to your layout.
The event View.Events.OnCursorChanged can be used so that the calculated value in the text area is updated when the band cursor is moved. It must be implemented as a user command.
Try to carry out these steps:
-
Add a text area to your layout.
-
Copy the script and change the number of your text area in the script in line 23.
-
Register the script file as a user command in module SCRIPT under Settings»Extensions»User Commands.
Option Explicit
call AddUserCommandToEvent("View.Events.OnCursorChanged", "OnViewCursorChanged")
Sub OnViewCursorChanged(oCursor)
dim LeftIndex, RightIndex, ChnReference, ChnObj, TextArea
if oCursor.P1 < oCursor.P2 then
LeftIndex = oCursor.P1
RightIndex = oCursor.P2
else
LeftIndex = oCursor.P2
RightIndex = oCursor.P1
end if
if LeftIndex > 0 and RightIndex > 0 and oCursor.Sheet.Areas(1).DisplayObjType = "CurveChart2D" then
' Get the channel you want to calculate, for example the y-channel of the first curve.
ChnReference = oCursor.Sheet.Areas(1).DisplayObj.Curves2D(1).YChannelName
set ChnObj = Data.GetChannel(ChnReference)
if oCursor.Sheet.Areas.Count > 1 then
' In this example the text area is the third one. Adjust the value!
set TextArea = oCursor.Sheet.Areas(3)
' Better is to use a named area. Rename your text area to, for example "CalcTextArea".
'set TextArea = oCursor.Sheet.Areas("CalcTextArea")
if TextArea.DisplayObjType = "TextBox" then
' Do the calculation and set the value into the text area.
TextArea.DisplayObj.Text = "Difference: " & str(ChnObj.Values(RightIndex) - ChnObj.Values(LeftIndex))
end if
end if
end if
End Sub
Everything is set up and ready to go. Proceed to move and adjust the band cursor in the VIEW section.