FactoryTalk and Visual Basic

I am attempting to change the time span of a TrendX graphic display with VBA code - unsucessfully. I'm using FactoryTalk View Site Edition 8.00.00 on a Windows 7 machine. Although templates load correctly, the TrendX.XAxis.TimeSpan code produces a "type mismatch" error in both the routines below. Am I going about this entirely wrong?

Private Sub Display_AnimationStart()
TrendX.LoadTemplate "t2"
TrendX.XAxis.TimeSpan = 86400
End Sub

Private Sub btn_5_min_Released()
Dim x As XAxis
Set x = TrendX.XAxis
but_5_min.TimeSpan = 300
End Sub

Thanks for any insight.
 
You are overcomplicating it. Here is my example for 1 minute and 5 minute buttons. This allows an operator to click the button with the desired timespan after the trend has opened.

Private Sub FiveMinuteTimeSpan_Released()
Me.TrendExample.XAxis.TimeSpan = 300
End Sub

Private Sub OneMinuteTimeSpan_Released()
Me.TrendExample.XAxis.TimeSpan = 60

OG
 
Thanks for the timely reply however if you could take another look I would be appreciative. The list of error messages are

For: Me.TrendX.XAxis.TimeSpan = 300

TrendX.XAxis.TimeSpan=300
Failed to resolve item's ID 'TrendX.XAxis.TimeSpan' because it does not exist on any server
Tag 'TrenX.XAxis.TimeSpan' does not exist
VBA Code has halted. Reason: Run-time error - Type mismatch


For: TrendX.XAxis.TimeSpan = 300

VBA Code has been halted. Reason: Run-time error - Type mismatch

Thanks - Walt
 
Have you verified the name of the Trend object? Right-click on the trend and select Properties. On the Common tab the name of the object will appear. In my example, I named my trend "TrendExample".

So Me.TrendExample identifies that on the current display there is an object named "TrendExample".

Also, have you made sure to expose the trend object to VBA Control? If you right-click on the trend and select Property Panel you will see a list of properties. Make sure Expose to VBA is set to VBA Control. Same with the buttons you are using to change the timespan.

OG
 
Yes, the common tab lists the name as TrendX and property panel for TrendX is set to 'VBA Control'. I've tried other names for the object in case there was some conflict, but same results.

Is there some 'Dim', 'Set' or ActiveX config that needs to be done? It's odd to me that TrendX.LoadTemplate works fine but TrendX.XAxis.TimeSpan does not.
 
The code I posted earlier was the entirety of what I had.

Are you using the normal trend object, or the Trend Pro object? I'm not sure if the Pro one works with VBA (I've never tried it).
Is the VBA code on the display that contains the trend or are you calling it form another display?

OG
 
I assume the normal trend object as it's the only selection available and simply labled 'Trend'.

It's on the same display (named "Trend") which contains the graphic named TrendX and several buttons to change the time span and to load different templates, all of which are exposed to VBA.
 

Attachments

  • trendx.jpg
    trendx.jpg
    74.3 KB · Views: 8
Ok so not Trend Pro. Here is my VBA code. I built a new display with two buttons to load two different templates and three buttons for different timespans.

Code:
Private Sub Display_AnimationStart()

End Sub

Private Sub TimeSpan_5min_Released()
Me.TrendX.XAxis.TimeSpan = 300
End Sub

Private Sub TimeSpan_60sec_Released()
Me.TrendX.XAxis.TimeSpan = 60

End Sub

Private Sub Template1_btn_Released()
Me.TrendX.LoadTemplate "T1"
End Sub

Private Sub Template2_btn_Released()
Me.TrendX.LoadTemplate "T2"
End Sub

Private Sub TimeSpan_10sec_Released()
Me.TrendX.XAxis.TimeSpan = 10

End Sub

The templates load, and the timespans all work.





OG
 
With exactly the same code I get the errors listed above. Perhaps a reinstall or version upgrade is in my future. Thanks for all your efforts.

Walt
 
Perhaps let the autofill do it's thing and see if that helps. For this line

Me.TrendX.XAxis.TimeSpan = 300

Type "Me." (without the quotes) and you should see a drop down. See if "TrendX" appears in the list and select it. Then type period and see if XAxis shows in the list. Select it and then type period and see if Timespan shows. Select it and then add the = 300 or whatever number you choose.

Maybe that will make a difference.

OG
 
You can load more than one template at a time. This makes it possible to load your pens with one template, and your timespan with another. Use the checkboxes to specify what is or isn't in each template.

1732656262296.png
 
OG,

Did that several times. The selections are always there and add on with a double click. I can always configure the time span at run time, just not as convenient as with buttons.
 

Similar Topics

I am trying to get a local instance of FT View SE to connect to a local SQL database for some stored recipe information. All of this was backed up...
7
Replies
1,440
Views
I'm just trying to load from a text file into a string. I don't get why this doesn't work. Function LoadFile(FileName As String) As String()...
0
Replies
2,084
Views
Hello, Im trying to learn how to use VBA with factorytalk view so i can later design displays using tags from PLCs and im having some trouble...
2
Replies
4,783
Views
I have a small application where i want to use a numeric input to change the tags for another numeric input i am referring to dynamically. I am...
6
Replies
3,498
Views
from visual basic I am trying to write to a variable in factorytalk called alarm, this variable is of binary type, should not be a problem but I...
4
Replies
4,980
Views
Top