06-18-2023 10:18 PM
Hi,
Not for the first time have I found a problem where a piece of code used to modify an axis system does not work at run time but does work in debug mode!
The code is meant to determine the difference between the minimum value of a plotted channel and the value at the beginning of an axis. If they are too close, then it adjusts the axis beginning by one tick distance step. A similar thing happens at the axis end. This is borrowed code from another script which works perfectly and the only change I've made is to set an object variable to represent the axis instead of writing it out longhand. I've tried the following code in both long and short hand and it fails in both. In this case, DIAdem fails to extend the end of the X axis due to the proximity of the X data. The code is as follows:
'Adjust axis scaling if curve too close to the frame
Call Report.Refresh()
R1 = 0.25
'yrate v hw x axis
Set PlotAxis = Report.Sheets("YRate v HWA").Objects("2DAxis1").XAxis
Logfilewrite HAChn.Minimum & ", " & PlotAxis.Scaling.Begin & ", " & HAChn.Maximum & ", " & PlotAxis.Scaling.End & ", " & PlotAxis.Scaling.Tick.Distance
If Abs(PlotAxis.Scaling.Begin - HAChn.Minimum) < R1*PlotAxis.Scaling.Tick.Distance Then
PlotAxis.Scaling.AutoScalingType = eAxisAutoScalingManual
PlotAxis.Scaling.Begin = PlotAxis.Scaling.Begin-PlotAxis.Scaling.Tick.Distance
PlotAxis.Scaling.Origin = PlotAxis.Scaling.Begin
End If
If Abs(PlotAxis.Scaling.End - HAChn.Maximum) < R1*PlotAxis.Scaling.Tick.Distance Then
PlotAxis.Scaling.AutoScalingType = eAxisAutoScalingManual
PlotAxis.Scaling.End = PlotAxis.Scaling.End+PlotAxis.Scaling.Tick.Distance
End If
Logfilewrite HAChn.Minimum & ", " & PlotAxis.Scaling.Begin & ", " & HAChn.Maximum & ", " & PlotAxis.Scaling.End & ", " & PlotAxis.Scaling.Tick.Distance
I've got two instances of Logfilewrite to see if the correct values are being picked up. Here are those values in Debug mode:
-5.12520400364807E-02, -2.5, 17.4436319205985, 17.5, 2.5
-5.12520400364807E-02, -2.5, 17.4436319205985, 20, 2.5
These are correct; the X axis end is less than one quarter of the tick distance from the maximum value in the X data, so it adds one tick distance to the axis end value. But here's where it gets frustrating; these are the equivalent values recorded during Run mode:
-5.12520400364807E-02, -2.5, 17.4436319205985, 20, 2.5
-5.12520400364807E-02, -2.5, 17.4436319205985, 20, 2.5
DIAdem is claiming that the end value is already large enough and so doesn't enter the relevant If statement. One look at the plot indicates this is not true. This makes it impossible to Debug the code.
Regards,
Simon.
06-19-2023 02:06 AM
By way of additional information, if I activate each sheet beforehand and then use longhand references, as per the following code, then it seems to work. Why would this be?
Report.Sheets("YRate v HWA").Activate
If Abs(Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Begin - HAMin) < R1*Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Tick.Distance Then
Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.AutoScalingType = eAxisAutoScalingManual
Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Begin = Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Begin-Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Tick.Distance
Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Origin = Report.ActiveSheet.Objects("2DAxis1").XAxis.Scaling.Begin
End If
06-19-2023 09:01 AM
Your original script worked for me?
I added
Report.Refresh()
In the end
06-19-2023 10:49 PM
Thanks for the reply, although that's even more concerning. Could it be version related? I'm using 2023 Q2.
Here's a screenshot of the plot axis numbers, where the end is correctly shown as 17.5:
And the portal where the maximum value in the channel is 17.44:
And here is my code halted using a breakpoint in Debug mode where you can see that the end value for the X axis is reported in the logfile as 20 but the live value in the pop-up is 17.5!! I don't understand how these two can disagree - how can a variable have two values at the same time?
On the plus side, at least the values reported during Run time and Debug are the same - they are now both wrong.
Regards,
Simon.
06-20-2023 09:16 AM
move the log statement to the end of the script
06-20-2023 10:10 PM
Can you explain why I should do that? I already have a record of the variable values after the code and reported that in my first post.
06-21-2023 09:55 AM
Sorry Simon I was having a hard time reproducing the error and I'm using the same version of DIAdem. Maybe share a zip of an example TDR, TDM, and VBS files that would cause this behaviour?
06-24-2023 09:20 PM
Hi,
I've attached a zip with the necessary files.
I started by commenting out all the unnecessary code and the problem went away! I then reinstated it bit by bit until the problem returned. I didn't have to go back far as it's related to the sheet not being active when the problem code is run, which starts around line 179.
Clearly, a solution is to make each sheet active before I work on it, but why is that necessary?
Even more weird is that in debug mode it will sometimes work and sometimes not!
The crux of the problem seems to be that the end value of the X axis on the first sheet is 17.5 when opened with this particular data file (the plots are set to autoscale) but DIAdem most often believes it to be 20 and so does not execute the If...Then statement needed to adjust the end value. Thus, what is shown in the Report window and what DIAdem believes the value to be disagree.
Regards,
Simon.