Showing results for 
Search instead for 
Did you mean: 

Get value of a Channel by row number

Go to solution



I have recorded a script that calculates the N peak values of a channel and saves them into a new channel. Each channel contains the X value and the Y values of the selected peaks (PeakX and PeakY)


Now, I want to get the value of a channel on the PeakX values that I have saved from the Peaks calculation.


Groups = Data.Root.ChannelGroups.Count

Set oMyChannel = Data.Root.ChannelGroups(Groups).Channels("PeakX")

for i = 1 to Data.Root.ChannelGroups(Groups).Channels("PeakX").Properties("length").Value

' Find the row where the "[1]/Time" matches with PeakX calculated values rowToFind= pno("[1]/[1]",oMyChannel.Values(i))

'How to get the value of a 3rd channel on the rowToFind row next

 How can I get the values of a 3rd Channel on the rowToFind row?


Thanks in advance.




0 Kudos
Message 1 of 4

There is a function in DIAdem - "ChnFind()".  Very handy.  Example:

Dim intMyResult
intMyResult = ChnFind("Ch(""Group1/Channel"")>10",250)

intMyResult will contain the first row above 10 and it will start searching from the 250th row in "Group1/Channel" (speeds up search in many cases). So in your case, 

rowToFind = ChnFind("Ch(""[1]/[1]"")=" &oMyChannel.Values(i),1)
Dim ThirdChannelValue: ThirdChannelValue = oMyThirdChannel.Values(rowToFind)

Hope I understood you question.

P.S. there is a ChnFindReverse() function as well (starts the search from the end of the channel)

0 Kudos
Message 2 of 4
Accepted by topic author iparra

Hi iparra,

here is my interpretation of your request:

dim i, iRowToFind, iNewChnIndex, iLastGroupNo, oChnTime, oChnSource, oChnPeakX, oChnNew

iLastGroupNo = Data.Root.ChannelGroups.Count

set oChnTime   = Data.Root.ChannelGroups(1).Channels("Time")
set oChnSource = Data.Root.ChannelGroups(1).Channels("MySourceChn")
Set oChnPeakX  = Data.Root.ChannelGroups(iLastGroupNo).Channels("PeakX")
set oChnNew    = Data.Root.ChannelGroups(iLastGroupNo).Channels.Add("MyNewChannel", DataTypeChnFloat64)

iNewChnIndex = 0
for i = 1 to oChnPeakX.Size
  ' Find the row where the "[1]/Time" matches with PeakX calculated values
  iRowToFind = pno(oChnTime, oChnPeakX(i))
  'How to get the value of a 3rd channel on the rowToFind row
  if iRowToFind > 0 then
    iNewChnIndex = iNewChnIndex + 1
    oChnNew(iNewChnIndex) = oChnSource(iRowToFind)
    exit for
  end if




Message 3 of 4

The link below shows how to use several DIAdem functions to get the row corresponding to a channel value.  PNo() is the easiest and fastest.  



0 Kudos
Message 4 of 4