From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-15-2012 08:06 AM
Hi,
here is a minimum example of the strange behaviour, usually the predefined R11-value would be a much more complex structure:
'========================================
Call Data.Root.Clear()
Call ChnLinGen("XXX", 10, -10, 21)
'prior definition of comparison variable
R11 = -11
R1 = ChnFindReverse("Ch(""XXX"")>=("""& R11 &""")")
'direct input of comparison variable
R2 = ChnFindReverse("Ch(""XXX"")>=-12")
Call MsgBox(R1 & " should be the same as " & R2)
'========================================
Am I doing something wrong?
Phex
Solved! Go to Solution.
10-15-2012 03:48 PM
If you change teh following two lines
R11 = -11
R1 = ChnFindReverse("Ch(""XXX"")>=("""& R11 &""")")
to
R11 = -12
R1 = ChnFindReverse("Ch(""XXX"")>=("& R11 &")")
it should be the same. The main difference is in the second line where I changed teh code to handle R12 as a number instead of a string
10-15-2012 05:17 PM
Hello Phex,
This has nothing to do with the ChnFindReverse function. You are comparing two different things with ChnFindReverse function in the two lines in your script. The results DIAdem delivers have something to do with the way you are comparing things in the parenthesis behind the ChnFindReverse statement.
This line is comparing a string ("-11") and not a number (-11): R1 = ChnFindReverse("Ch(""XXX"")>=("""& R11 &""")")
The result of the string comparison is that the string "-11" is greater than "-10" - because the first two characters of that string are identical, and the third character ("1" vs "0") has the result that 1 is greater than 0 (based on the ASCII code values), thus 20 (the line number of the value -9 -and the second character "9" is larger than 1) is the result of that comparison.
In the line R2 = ChnFindReverse("Ch(""XXX"")>=-12")
you are comparing an actual number to the channel values and thus receive the line number 21 (which is the first value of the channel where your condition is true).
If you change the syntax as suggested by Andreas in his post above mine, you will receive the expected result in both cases ...
Otmar
10-16-2012 03:46 AM
Thank you Andreas and Otmar for your reply and explanation. I have tried that, and it works fine for integer numbers, but as soon as I want to compare it against a real number, like R11 = -11.1, then I get the error message:
Expected ')'
What do I need to change now?
Phex
10-17-2012 11:10 AM
Can anyone please explain why this works:
R1 = ChnFindReverse("Ch(""XXX"")>=-12.1")
but this not:
R11 = -12.1
R1 = ChnFindReverse("Ch(""XXX"")>=("& R11 &")")
?
10-17-2012 11:24 AM
Not sure what ends up in teh string but the way you scripted it, you rely on teh VBscript runtime to format the value in R11.
I recommend to do this
R1 = ChnFindReverse("Ch(""XXX"")>=("& str(R11) &")")
This uses DIAdem's built in formatting function "str"
And just as an FYI: the return value of ChnFIndReverse is an Integer number. Using R1 is not wrong but either using a local VBScript variable or L1 would be more appropriate
10-17-2012 11:54 AM
Thanks for the correction. It works!
Phex