DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ChnFind trouble with decimal places

Solved!
Go to solution

Hi All,

 

I'm having some trouble using the ChnFind command. I'm trying to find a line in a data channel in between two values (the values "Numt" and "NumMinus") which are being taken from another data channel using an integer. The code below works, and gives the expected value, as long as I round the numbers:

        Numt = Round(oMax_Pos_LA_X_Chn.values(t))
        NumMinus = Round(oMax_Pos_LA_X_Chn.values(t-1))
                    AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > "& NumMinus &") and (Ch(""[4]/Max_Pos_RA_X"") < "& Numt &") " , 1)

 

However as soon as I leave the numbers as they are without rounding, like I have below, it gives an error saying ')' expected:

        Numt = oMax_Pos_LA_X_Chn.values(t) 
        NumMinus = oMax_Pos_LA_X_Chn.values(t-1)
                    AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > "& NumMinus &") and (Ch(""[4]/Max_Pos_RA_X"") < "& Numt &") " , 1)

 

If anyone has any insight on this I would be very grateful.

 

Thanks,

Imogen

0 Kudos
Message 1 of 5
(2,799 Views)

Hi Imogen,

 

I assume you are working with a German OS and has a comma as decimal seperator. And I assume that the values "oMax_Pos_LA_X_Chn" are text values containing "German numbers". DIAdem always use the period "." as decimal seperator. Some VBS comannds could also handle the comma.

So a fast solution is to use the CDbl command instead of Round.

A better solution would be to store the data with the correct seperator as numeric channels.

 

Hope this helps

 

Winfried


0 Kudos
Message 2 of 5
(2,786 Views)

Hi Winfried,

 

Thank you for your reply. I tried the CDbl command and it didn't work unfortunately. You're correct in saying I am using a German OS, and the decimal separator could be causing a problem. In this case I'm not sure. I tried using the actual numbers with their decimal places and it gives the same error: 
      Numt = 33.9285835625676
      NumMinus = 32.5823981184147
           AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > "& NumMinus &") and (Ch(""[4]/Max_Pos_RA_X"") < "& Numt &") " , 1)

 

But when I run this it works as it should:

       Numt = 34
       NumMinus = 33
            AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > "& NumMinus &") and (Ch(""[4]/Max_Pos_RA_X"") < "& Numt &") " , 1)

 

And, funnily enough, when I manually enter the required numbers, it also works perfectly:

         AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > 32.5823981184147) and (Ch(""[4]/Max_Pos_RA_X"") < 33.928583562567) " , 1)

 

I believe it might also be how I am using the ChnFind command. 

Thanks,

Imogen

0 Kudos
Message 3 of 5
(2,778 Views)
Solution
Accepted by topic author ImogenR

Hi Imogen

 

It is a problem of the decimal place. Whith the help of the debugger I found that on a German OS the number is converted by VBS in a numer with comma separator. So you first have to convert your number into a string to keep the decimal point:

      Numt = Str(33.9285835625676)
      NumMinus = Str(32.5823981184147)
           AffectedStep = ChnFind("(Ch(""[4]/Max_Pos_RA_X"") > "& NumMinus &") and (Ch(""[4]/Max_Pos_RA_X"") < "& Numt &") " , 1)

But you have to use the DIAdem function str instead of the VBS function cstr because cstr will also convert 32.58 to "32,58".

 

Winfried

 

 

0 Kudos
Message 4 of 5
(2,771 Views)

Hi Winfried,

 

Yes it worked! Thank you very much! 🙂

 

Kind regards,

Imogen

 

 

0 Kudos
Message 5 of 5
(2,761 Views)