DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing variable to Find function

Solved!
Go to solution

Hello,

 

I'm trying to find the first index where my accelerometer goes below -1G. I'm trying to use the Find function to do this, and having some syntax errors.

My code looks like this:

index = Find("Ch(""accelChannel"")<-1")

accelChannel is a variable that contains the name string of my data channel. I'm writing this script with the assumption that I won't know the name or index of the channel in my data structure. I have a dialog box that the user selects the channel and sets the accelChannel variable.

 

I'm trying to pass this string to the Find function to do the search, and I can't get it to work. Is it possible to pass a variable to the Find function?

0 Kudos
Message 1 of 4
(2,542 Views)
Solution
Accepted by sirwin

You can just create a string by resolving the value.

index = Find("Ch(""" & accelChannel & """)<-1")
Message 2 of 4
(2,515 Views)

That worked, Thanks!

0 Kudos
Message 3 of 4
(2,509 Views)

Hi sirwin,

 

I find putting the channel name with """ quotes into the formula makes it hard for me to debug when the formula gets a little more complicated.  The following approach will work in all DIAdem versions:

T1 = "accelChannel"
index = Find("Ch(T1)<-1")

 

And this nicer, object-oriented approach will work in recent DIAdem versions:

Set DataChannel = Data.GetChannel("accelChannel")
Channels = Array(DataChannel)
Symbols = Array("Accel")
index = ChnFind("Accel<-1", 1, Symbols, Channels)

 

It's much better for debugging if the "accelChannel" channel reference fails outside the Find function.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 4 of 4
(2,403 Views)