01-23-2019 10:06 AM
Hi,
I have a Report page with a graph that contains a text box in which I would like to enter a value from a channel. I am using the following text entry:
Roll Gradient = @@Str(ChD(ChnFind("InStr(1,Ch(""Metric Values/Metrics""),""Roll Grad [deg/'g']"",1)<>0"),"Metric Values/Values"), "dd.d")@@ deg/'g'
When the channels Metric Values/Metrics and Metric Values/Values exist then it works perfectly. However, if I open the Report file when those channels don't exist then several errors are thrown because, it seems, DIAdem is trying to evaluate the above text entry and failing to find the channels.
Is there a way of making this kind of text entry more robust so that errors are not thrown just because it can't be evaluated?
Ideally, script solutions should not be used, as I would like the end user to be able to open the Report file at times when those channels may not be present.
Thanks.
Simon.
Solved! Go to Solution.
01-24-2019 08:47 AM
Hello Simon,
My first idea on this is to extend the VB code a bit, to test if the channels exist, like:
Roll Gradient = @@if((CNo("Metric Values/Metrics")+CNo("Metric Values/Values"))>0) then (Str(ChD(ChnFind("InStr(1,Ch(""Metric Values/Metrics""),""Roll Grad [deg/'g']"",1)<>0"),"Metric Values/Values"), "dd.d")) else "Channel(s) unknown" end if@@ deg/'g'
Would this condition statement work in a report?
01-24-2019 08:57 AM - edited 01-24-2019 08:57 AM
No, it doesn't.
01-24-2019 10:00 AM - edited 01-24-2019 10:01 AM
Hello Simon,
Can you share a bit more information on your setup please? What version of DIAdem are you using? What to you perform when you "open the report file"?
I tested your code here with the default example database, it looks fine. Using existing channels, I get the expected output. Typing non-existing group names, channel names, or both into the text definition, the VB section returns empty:
Works.
Fails.
Here, the IIF function also works inline.
01-25-2019 03:05 AM
Hi,
I'm using DIAdem 2011. I get a syntax error when I try the line of code you suggested in a Report comment box. I don't follow your third question I'm afraid.
I can't see the content of the images you share as they are too small.
Regards.
01-25-2019 04:19 AM
I tried converting your statement to an inline if, using IIF, and running it in script to test it, as follows:
Call MsgBoxDisp (iif((CNo("Metric Values/Metrics")+CNo("Metric Values/Values"))>0, (Str(ChD(ChnFind("InStr(1,Ch(""Metric Values/Metrics""),""Roll Grad [deg/'g']"",1)<>0"),"Metric Values/Values"), "dd.d")), "Channel(s) unknown"))
I get an error message stating that DIAdem cannot execute the calculation because the input channel "CH(Metric Values/Metrics)" is unknown.
I checked the conditional expression, as follows:
Call MsgBoxDisp (iif((CNo("Metric Values/Metrics")+CNo("Metric Values/Values"))>0, "Channels exist", "Channel(s) unknown"))
This works fine. So the problem must be in the parameter that is returned when the condition is true. This is obviously a code problem for DIAdem - it is still checking whether the whole line can be evaluated even when the condition is false.
Regards.
01-25-2019 04:55 AM
Further work shows that this line won't run if the channel is not available:
Call MsgBoxDisp (ChnFind("InStr(1,Ch(""Metric Values/Metrics""),""Roll Grad"",1)<>0"))
If anyone knows of a way around this then I'd be very grateful.
Regards.
02-01-2019 03:41 AM
Hello Simon,
Sorry about the delay.
Here are the images again:
Channel not available (Please note that the calculator shows 0.63 still from the last calculation).
Channel available.
As you can see, the lines are evaluated here, and when the channel does not exist, that part is gracefully ignored. Is this a different behavior from the one you are seeing? Then upgrading could be a solution. I am using DIAdem 2017 SP1 here.
Or is my test to simple?
02-01-2019 10:21 AM
Hi,
I have copied your code, I think. Your image is difficult to read as the text is so small so could you check how well I've copied it please? Below is when the channel is present:
And this is when the channel is not available (and I press refresh):
Examining the log file reveals this:
66 16:16:25 Error: 67 Error message from DIAdem command kernel: Cannot execute calculation because the input channel "CH(Results_Noise data/StatisticsText)" is unknown. 68 The error occurred in object "Comment1", type "Comment".
In theory I could accept the errors and move on but that's a rather inelegant solution and would confuse the user.
I'm using DIAdem 2011 at the moment, but will move to 2018 soon.
Regards.
02-01-2019 01:21 PM
Hi Simon,
I am really sorry about the issues with the screenshots. I posted the new ones in full resolution, but somehow the zoom function of the forum software does not allow me viewing them in full scale either.
So here is the code I am using as text in the report that works:
Value:@@str(ChD(chnfind("InStr(1,Ch(""Results_Noise data/StatisticsText""),""Maximum value"",1)<>0"),"Results_Noise data/Res_Noise_1"), "d.dd")@@:end
The "Value:" in front and ":end" in the end is just to show something around the number. For the line above I see a "Value:0.63:end" in the reports text box.
When I change the channels given in the line above by adding random characters, e.g.
Value:@@str(ChD(chnfind("InStr(1,Ch(""ResultXXXXXXXXXXs_Noise data/StatisticsText""),""Maximum value"",1)<>0"),"Results_Noise data/Res_Noise_1"), "d.dd")@@:end
I get "Value::end" instead. No matter if I change the first group name, first channel name, second group name, second channel name, or all of them.
Do you still get the error message when using exact this code? Then seems quite clear to me that this behavior was like this in DIAdem 2011, but changed since. Unfortunately I don't have a version older than 2017 SP1 installed to test.