03-18-2020 04:23 AM
Hello,
Can someone tell me why this code fails at the line beginning L2, due to a missing bracket, when its construction is based on the line beginning L1?
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim Freq, YRateG, YRateT, LatacG, LatacT, x0, x1
Set Freq = Data.GetChannel("Frequency")
Set LatacG = Data.GetChannel("Latac Gain")
x0 = 0.2
x1 = 0.5 * 0.019
L1 = Find("Ch(" & Freq.Name & ") >" & x0 & "")
logfilewrite(L1)
L2 = Find("Ch(" & LatacG.Name & ") <" & x1 & ", " & PNo(Freq.Name, x0) & "")
logfilewrite(L2)
A solution seems to be extra double quotation marks around the first variable but I don't understand why:
L2 = Find("Ch(""" & LatacG.Name & """) <" & x1 & ", " & PNo(Freq.Name, x0) & "")
logfilewrite(L2)
Why do the two constructions need to be different? Are there other solutions I've missed?
Thanks.
Solved! Go to Solution.
03-18-2020 09:17 AM
Hi,
The condition in FIND is a string. So your X0 and X1 must also be a string like this:
Dim Freq, YRateG, YRateT, LatacG, LatacT, x0, x1
Set Freq = Data.GetChannel("Zeit")
Set LatacG = Data.GetChannel("Drehzahl")
x0 = 0.2
x1 = 0.5 * 0.019
L1 = Find("Ch(" & Freq.Name & ") >" & str(x0) & "")
logfilewrite(L1)
L2 = Find("Ch(" & LatacG.Name & ") <" & str(x1) & ", " & PNo(Freq.Name, x0) & "")
logfilewrite(L2)
Greetings
Walter
03-18-2020 09:20 AM
Thanks Walter. So, why does the line beginning L1 work without the str function? And why would adding extra double quotes around the variable LatacG.Name work?
Regards.
03-18-2020 09:24 AM
Sorry Walter, but I checked it and it didn't work I'm afraid.
Regards.
03-18-2020 09:43 AM
Definition of FIND:
ReturnValue = Find(Condition as String [,ChannelLine as Integer])
So correct for L2 is
L2 = Find("Ch(" & LatacG.Name & ") <" & str(x1) , PNo(Freq.Name, x0))
If this doesn't work, which DIAdem version do you use?
Greetings
Walter
03-18-2020 10:34 AM
Hi Walter,
I'm using 2019 SP1.
The error message is:
Error in <NoName(2).VBS> (Line: 19, Column: 1):
FIND("Ch(Latac Gain) <0.0095, 6") Close bracket ")" expected for field index.
It seems to be able to interpret the variable values ok, but doesn't like the syntax.
Regards.
03-19-2020 03:06 AM
Hi Simon,
The error message says that the line number (in your case 6) is part of the condition. Correct would be to have the quotation mark before the comma and not after the 6.
Please can you run this script part (which works fine on my DIAdem):
Dim Freq, YRateG, YRateT, LatacG, LatacT, x0, x1
Set Freq = Data.GetChannel("Frequency")
Set LatacG = Data.GetChannel("Latac Gain")
x0 = 0.2
x1 = 0.5 * 0.019
L1 = Find("Ch(" & Freq.Name & ") >" & str(x0) & "")
logfilewrite(L1)
L2 = Find("Ch(" & LatacG.Name & ") <" & str(x1) , PNo(Freq.Name, x0))
logfilewrite(L2)
Greetings
Walter
03-19-2020 04:07 AM
Hi Walter,
I understand what you mean and can see how to interpret the error message now. Unfortunately, the latest code didn't work either. The error message is the same, even though the string construction is different.
It does seem to be pointing towards the treatment of the channel name, even though the same syntax is used in the equation for L1. Incidentally, the ampersand and pair of double quotes at the end of the equation for L1 are redundant.
Regards.
03-19-2020 04:43 AM
Hi Simon,
I just saw that the channel name has no quotation marks. Please test this here:
Dim Freq, YRateG, YRateT, LatacG, LatacT, x0, x1
Set Freq = Data.GetChannel("Frequency")
Set LatacG = Data.GetChannel("Latac Gain")
x0 = 0.2
x1 = 0.5 * 0.019
L1 = Find("Ch(""" & Freq.Name & """) >" & str(x0))
logfilewrite(L1)
L2 = Find("Ch(""" & LatacG.Name & """) <" & str(x1), PNo(Freq.Name, x0))
logfilewrite(L2)
Greetings
Walter
03-19-2020 04:51 AM
Hi Walter,
This works. So in the end it was the channel name that needed the extra quotation marks - but only for L2! The str function is not required in either L1 or L2, and neither are the channel name quotation marks in L1. The inconsistency is rather difficult to cope with!
All of these work for L1:
L1 = Find("Ch(""" & Freq.Name & """) >" & str(x0))
L1 = Find("Ch(" & Freq.Name & ") >" & str(x0))
L1 = Find("Ch(" & Freq.Name & ") >" & x0)
However, for L2, which incorporates the PNo function, the extra double quotation marks around the channel name are required.
Many thanks.
Simon.