0

Hello there,

I have some codes with me to plot my graph that looks like this, but I can't really understand what is going on in the codes below that is used to calculate the Y-coordinate in order to plot out the graph:

```
Function findY(ByVal index As Integer) As Long
'Calculate the y-value (equals average of data through the point)
Dim i As Long
Dim startx As Long
Dim endx As Long
Static prevYneg As Boolean
startx = Int(index / Picture1.ScaleWidth * pWaveHeader.dwBufferLength / 2)
endx = Int((index + 1) / Picture1.ScaleWidth * pWaveHeader.dwBufferLength / 2)
If endx > pcSamplesPerSecond * pcMaxSeconds Then endx = pcSamplesPerSecond * pcMaxSeconds
findY = 0
If (startx = endx) Then
findY = data(startx)
Else
'findY = data(startx)
For i = startx To endx
findY = findY + data(i)
Next i
findY = findY / (startx - endx)
End If
findY = findY / 2 ^ 16 * Picture1.ScaleHeight
If (prevYneg) Then
If (findY > TriggerLevel.Text * Picture1.ScaleHeight / 2) Then
edge_trigger (index)
prevYneg = False
End If
ElseIf (findY < TriggerLevel.Text * Picture1.ScaleHeight / 2) Then
prevYneg = True
End If
If (maxY < findY) Then maxY = findY
End Function
```

Can someone care to explain?