DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Function string construction

Solved!
Go to solution

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.

0 Kudos
Message 1 of 11
(3,317 Views)

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

0 Kudos
Message 2 of 11
(3,285 Views)

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.

0 Kudos
Message 3 of 11
(3,283 Views)

Sorry Walter, but I checked it and it didn't work I'm afraid.

 

Regards.

0 Kudos
Message 4 of 11
(3,282 Views)

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

0 Kudos
Message 5 of 11
(3,277 Views)

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. 

0 Kudos
Message 6 of 11
(3,273 Views)

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

0 Kudos
Message 7 of 11
(3,241 Views)

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.

 

Simon_Aldworth_0-1584608627934.png

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.

 

0 Kudos
Message 8 of 11
(3,236 Views)
Solution
Accepted by topic author Simon_Aldworth

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

0 Kudos
Message 9 of 11
(3,230 Views)

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.

0 Kudos
Message 10 of 11
(3,225 Views)