DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an EventSearch with variable as condition Within a For Loop

Hello,

 

I am trying to create a For Loop, and within the for loop, event searches would be performed for different channel values. 

 

Is it possible to use a variable such as 'x' in the event search command so that it can loop?

 

Thank you,

 

Claudia 

0 Kudos
Message 1 of 8
(2,994 Views)

Sorry, can you clarify:

 

What are "event searches"? What is a "variable"? What is "it" that should loop? ...?

0 Kudos
Message 2 of 8
(2,974 Views)

Hi, yes sorry---

 

In DIAdem, there is a function/command that is ChnEventxxx. Basically it searches channels for something you specify, and you can do AND/OR Operations between channels. 

 

What I am trying to do is do the ChnEventxxx command for multiple ranges of data. For example, 45-47; 47-49; etc. That is what would change in every loop. 

 

I tried setting a 'variable' x=45. And used it the bounds within the event search command, but an error occurred and said that it is an invalid input.

 

So basically my question is: Is it possible to have a loop around ChnEventxxx commands, where what is changing is within the command? 

0 Kudos
Message 3 of 8
(2,966 Views)

Dim x  'Declare Variables

x = 0.5   'Define Variables

For x = 0.5 to 0.975

ChnEventList1 = ChnEventDetectionWindow("", "[6]X_Avg", x, x+0.025, 0, 0)

...

...

...

Next

 

Here is the script I have. Is this more clear? So for each loop, the range (bolded) changes. 

 

Thank you for any info you can provide!

0 Kudos
Message 4 of 8
(2,919 Views)

Yes, it is possible to use ChnEvent... function in a loop like you did.

The reason for the error is caused by other problems. If you send us a dataset and script part we can try to reproduce it and analyse the problem.

Greetings

Walter

0 Kudos
Message 5 of 8
(2,893 Views)

Hello, 

 

I can not send the data because the file is too large. However, can you explain what my error is and how I can attempt to fix it? Is there a specific syntax I must use with the variable, "x" to use it within the command? 

 

Thank you,

 

CJ

0 Kudos
Message 6 of 8
(2,880 Views)

Hi CJ,

 

I have a couple thoughts on the script you have provided.

 

First of all, the two parameters you have filled with "x" and "x+0.025" in the "ChnEventDetectionWindow()" function in your script-- those parameters define the vertical window within which the data must reside in order to count as a desired event.  So really these are Y1 and Y2 parameters.  If you're trying to loop from left to right along the X axis of your data curve using the "x" variable, then you're setting the window values incorrectly.

 

Second of all, a FOR loop in VBScript only works with integers.  There's no way to run a FOR loop from "x = 0.5 to 0.975" directly.  If you do want to run sequential event searches with an iteratively moving vertical window, you could do something like this, converting from integer FOR looping to an analog Y range:

 

 

For n = 0 TO nMax
  Y1 = 0.5 + 0.025*(n+0)
  Y2 = 0.5 + 0.025*(n+1)
  ChnEventList1 = ChnEventDetectionWindow("", "[6]/X_Avg", Y1, Y2, 0, 0)
Next\bradt\AppData\Local\Programs\Python\Python36\"

 

 

 

Third, your "[6]X_Avg" channel reference needs a Group/Channel separator => "[6]/X_Avg"

 

Brad Turpin

Principal Technical Support Engineer

National Instruments

0 Kudos
Message 7 of 8
(2,850 Views)

 

Hi Brad,

 

Thank you for the response. 

 

I am looking to identify the Y1 and Y2 range, I see my variable name decisions are misleading. 

 

I also have now: 

for x=0.5 to 0.975 step 0.025 

 

and it seems to be working. 

 

Thanks, 

 

Claudia 

 

 

0 Kudos
Message 8 of 8
(2,822 Views)