Mmh - from System.Runtime.InteropServices I guess you are not using VBA. I tried a little VB.NET program and this one throws an exception as well. Could you try
MyTrend.AddCursor() MyTrend.CurrentCursor = 1 MyTrend.CursorTime = "*-1h"
I am using C#, but it doesn't matter.
In your example you set time for cursor "*-1h", so from which time that hour was substructed?
May I set time not relative (*-1h) but absolut (22.02.2009 13:20:30)?
Seems PB is very special with timestamps when it comes to .NET. The following code works for me
MyTrend.AddCursor() MyTrend.CurrentCursor = 1 MessageBox.Show(MyTrend.CursorTime) MyTrend.CursorTime = "*-1h" MessageBox.Show(MyTrend.CursorTime) Dim test As String test = "4/21/2011 1:00:00 PM" MyTrend.CursorTime = test MessageBox.Show(MyTrend.CursorTime)
and i had to format the test string EXACTLY as it was shown from the messageboxes priot to that call. using "4/21/2011 1:00:00" throws an exception.
Hmm, both variants
MyTrend.CursorTime = "*-1h";
MyTrend.CursorTime = "30/10/2010 8:58:55 PM"
throw the same exception.
In your example you set time for cursor "*-1h", so from which time that hour was subtracted?
"*" means now; so, "*-1h" would mean one hour ago.
Let me take one step back and ask you a basic (and maybe obvious) question. Are we sure that the time you are trying to set lies within the time range of your trend? This is regardless of the format you are using.
Another test is to try adding a cursor manually in the Run Mode and copy the exact timestamp to your code.
Another possibility would be local date/time settings which could cause ambiguities in interpreting the time string.
I am sure that time I am trying to set lies within time range of my trend.
My code is:
2. string date = trend.CursorTime;
3. trend.CursorTime = date;
After second string of code date variable is set at "01.01.1970 3:00:00". That code is working, but if I in debugger change any sign in date to any another it will be cause exception.
There is 184.108.40.206 version of ProcessBook that I have. May it cause that problem?
If you never expand the display it seems that PB wants to use 1/1/1970 for the CursorTime ("01.01.1970 3:00:00" is likely UTC 0 adjusted to your local timezone). If I open the display before adding the cursor then I don't get the exception. Try the following code:
string date = trend.CursorTime;
trend.CursorTime = date;
I have the same error as the creator of the theme (you can see the error in zip), an error occurs when creating a cursor for a few trends.
I created an example in file display to recreate the problem, i created a button to add / remove 12 trends with tag SINUSOID and button to create cursors for 12 trends at once. When debugging program the error appears in line with the assignment CursorTime in 3-5th trend, CursorTime priori equals invalid date "01/01/1970 4:00:00".
All writen methods in forum did not help me. Thanks
Was just browsing through your problem - not sure if you picked this up:
Your timestamp that you tested looks like it's dd/MM/yyyy while Andreas' example is M/dd/yyyy
Try switching the days and months around. I don't know if that will solve your problem or not as I have not tested it myself.
Andrew Thank you for answer.
Yes i am using format timestamp dd/MM/yyyy. I tryed your idea with timestamp and I have the same error.
Somebody from specialists Osisoft can help me with this problem?
@Sergey: Have you tried to utilize the CursorUTCTime property instead? Do you have the same results?
What are your regional settings with the user executing the VBA code in PI ProcessBook? The CursorTime property handles DateTime date type. This type is sensitive to your regional settings.
I have found a thread that would refer to your problem. Check this out and let me know if that fixed your problem.
Sorry for delay in my answer.
I try with CursorUTCTime and similar error occurs. CursorUTCTime for 5th priori trend is 0.
I found in the thread 2 solutions: add MsgBox («wait") and ThisDisplay.Activate. And they also did not help.
I am testing ProcessBook on Windows server 2008 R2 Enterprise Edition with Russian language and format date is "dd.MM.yyyy"
I sent a description of the error and sample test project in Support OSIsoft, I hope that they will help me.