VBA to read tag from factory talk

keristos

Member
Join Date
Aug 2011
Location
Malta
Posts
65
Can someone be kind enough to help me out:

I would like to be able to have an option for the user to input a date on a screen and then I will have the system automatically scroll a trend (with datalogged data) to that time.

I've never coded with VBA so I have no idea.

I tried around and figured how to scroll the trend back to a specific date using:

Trend.XAxis.StartTime = #5/21/2014 1:20:20 PM#

Next i would like to make this variable, i.e. I would have 6 user input fields (yyyy,mm,dd,hh,mm,ss), I would then like to read them with VBA and (I assume) save them some variable, for example those with the names: yyyy,mm,dd,hh,mm,ss.

Then I should (presumably) be able to do this:

Trend.XAxis.StartTime = #yyyy-mm-dd hh:mm:ss#

so that it will scroll to user-chosen date.

Thank you for any help!
 
If you will open Help in FTView and then navigate down and open the tag object model you can find a detailed description of the tag object model and sample VBA code showing how to create a tag group, retrieve a tag object from the group, and then read or write values to the tag.
 
Were you able to make this work?
I'm able to get my Factory Talk Tags into VB, but I keep trying and getting errors trying to put variables in a Date Format.

Do you have any sample code?

Thanks for any help!
 
Were you able to make this work?
I'm able to get my Factory Talk Tags into VB, but I keep trying and getting errors trying to put variables in a Date Format.

Do you have any sample code?

Thanks for any help!

Search in the forum, I've posted a couple of ways to get tags in vb. Have a go & let me know what you've tried. I can try to help.

Ash
 
Thanks Ash,

Please see my code below:

Private Sub Button6_Released()

'Used to enter the start date and time for the trend display
Dim MyTagGroup As TagGroup


If MyTagGroup Is Nothing Then
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "COLUMN_A\ANALOG_TEST1"
MyTagGroup.Add "COLUMN_A\ANALOG_TEST2"
MyTagGroup.Add "COLUMN_A\ANALOG_TEST3"
MyTagGroup.Add "COLUMN_A\ANALOG_TEST4"

Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Tag4 As Tag
Dim Tag5 As Tag
Dim Tag6 As Tag
Dim DT As Date

'Set the tag objects
Set Tag1 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST1")
Set Tag2 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST2")
Set Tag3 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST3")
Set Tag4 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST4")
Set Tag5 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST5")
Set Tag6 = MyTagGroup.Item("COLUMN_A\ANALOG_TEST6")

'Define start time

DT = #Tag1.Value/Tag2.Value/Tag3.Value Tag4.Value:Tag5.Value:Tag6.Value AM#

'Must set Trend to pause mode. Unable to adjust x-axis

REACTA_TREND.Scroll = False

'Set the start time

REACTA_TREND.XAxis.StartTime = DT

End If

End Sub

The code is stuck at the "DT = #Tag1.Value/Tag2.Value/Tag3.Value Tag4.Value:Tag5.Value:Tag6.Value AM#".
I'm pretty sure the syntax is my main issue. I've tried putting quotes around each one, and brackets etc....
The code works, if I take out the variable and put at date into it. DT = #12/31/1998 10:30:00 AM#.

Any help will be greatly appreciated!
Thanks
 
I believe its your syntax,try:

Code:
'Define start time
DT = Tag1.Value & "/" & Tag2.Value & "/" & Tag3.Value etc...

Ash

Edit: Also take a look at the active x component "Microsoft Date & Time Picker", i use this to set the dates on a trend
 
Last edited:
Thanks Ash!

It worked, except I had to delete the time function. It kept giving me a Type mismatch error.
I tried -
DT = Tag1.Value & "/" & Tag2.Value & "/" & Tag3.Value & "10:30:00" & AM#

DT = Tag1.Value & "/" & Tag2.Value & "/" & Tag3.Value & " " & Tag4.Value & ":" & Tag5.Value & ":" & Tag6.Value & " " & AM#

DT = Tag1.Value & "/" & Tag2.Value & "/" & Tag3.Value & Tag4.Value & ":" & Tag5.Value & ":" & Tag6.Value & AM#

I have used "Microsoft Date & Time Picker" and it worked great, but as far as I know it only works with Office 2007. I don't believe Microsoft continued the Active X in Office 2010, 2013 or 2016.

Thanks for any insight!

Dale
 
Hi Ash,

I was able to figure out the time Syntax.
DT = Tag1.Value & "/" & Tag2.Value & "/" & Tag3.Value & " " & Tag4.Value & ":" & Tag5.Value & ":" & Tag6.Value & " AM"

Thank you for all your help!!
 
I know this is an old thread but after working on this for a day, it seems the simplest solution for reading one or two tags with vba is:

Dim xyz As Variant
xyz = StringDisplay1.Value

or an integer:

Dim xyz as Integer
xyz = CInt(NumbericDisplay1)

Walt
 
Last edited:

Similar Topics

Hi there, I have been looking in the forums for this and I saw a couple of examples but I still don't understand very well how to create a VBA...
Replies
4
Views
8,974
  • Poll
How to write a VBA in Factory Talk to read Alarm Tag from Alarm summary and open a display associated to that tag. Or open any desired display...
Replies
2
Views
7,038
Hi, I am trying to read data from an RFID scanner through the RS232 port of a PC into View SE. The data will eventually be written into a SLC...
Replies
0
Views
5,250
This is probably a stupid question but I searched and I've read the F Manual but I still can't figure out how to read or write a tag value in VBA...
Replies
5
Views
10,054
Hi Im currently upgrading a PV1200 project to FTV SE 5.0, and need to know how to read and write directly to tags from VBA. I can read a tag's...
Replies
3
Views
5,091
Back
Top Bottom