I was under the impression that the slope and intercept lines are inaccessible in VBA for Processbook. Could you post some sample code so we could get a better idea of how you're retrieving them?
Thanks for adding the code to your post.
I wasn't able to reproduce this behavior of type mismatch on the first pass through the VBA code. I agree with you on both points, that these do need to be cast in as they are stored as strings and that CSng is the way to go for this. Are you able to replicate this issue on machines other than your own? Correct me if I'm wrong here, but it gives you the type mismatch the first time you run the script after opening Processbook, or after making changes and saving it? What version of Processbook are you using?
On a side note, I would recommend using "If curSymbol.Type = pbSymbolXYPlot" over "If Symbols.Item(i).Type = 29" for clarity's sake.
1 of 1 people found this helpful
I'm using Processbook 2014 Version 22.214.171.124 on a remote desktop connection (because PI server is not accessible from local machine)
This only applies after opening the Processbook Display. But not after changing and saving.
I have done some more step into runs and I realised that on the first run, the XYPlot stats are not generated, and all stats show as "NA", which causes the problem when CSng("NA").
Every run after that shows normal XYPlot stats and code works fine.
Is there any reason why the stats do not show in the first run after opening the Display? I also tried to add a 0.05sec pause ProcessBook VBA Short Pause just in case it needed a delay to process but it does not fix the problem.
Edit: I realised that the XYPlot.stats method is returning the previous stats. For example, if I change the XYPlot time range from "*-2d","*-1d" to "*-1d","*", the XYPlot will update to the new time range, but the XYPlot.stats will still maintain the slope and coefficients of the old time range.
Because my old time range did not have any data on first run, it was showing "N/A" as old time range. Therefore, even though my script updated the XYPlot, the stats remained "N/A" until the second run, where the stats belongs to the first run.