Sending tag values to .txt for emailing?

buddhaman001

Member
Join Date
Feb 2014
Location
mobile, al
Posts
52
Objective.

I am trying, as the subject says, to gather tag values, put them in a .txt file, then I want to send them out over the email activex control in site edition.

My questions.

converting tags to variables for use with vba code.

i have seen this line: Dim Tag1 As Tag

I assume that tells Vb that tag1 is a tag

http://www.plctalk.net/qanda/showthread.php?t=91359&highlight=VBA+text

I have been going over this post and i get that "Combobox1.AddItem Tag1.Value" tells the vba code to place the value of tag1 in the referenced combobox.

but nowhere have I seen how to actually tell the vba code which tag you want to read

would it be something like?

Dim Tag1 as plant/waterlevel

Then i see the ability to write to word, excel, and access can the values be saved directly to a .txt file or will i need to go through word then tell word to save as a .txt file.


man I don't even know if i've stated my questions clear enough, sorry if i haven't.
 
AHA, man it was buried very deep in the help file, I think I have just found it!

Dim Tag1 As Tag
Set Tag1 = "System\Second"

would that be the very basics of it?

I will be adding in error checking as well, but this is only going to be run 3 times per day as to generate a email report.
 
If you are talking about FTView SE, look into tag groups as well.
The advantage of a tag group, is that you can force a refresh of all tags in the group at one time through VBA. If you don't do that and are using multiple tags in a report (for instance), you aren't guaranteed to get coherent data for all tags.
 
We'll be using i want to say 13 tags in the report.

so far I have

Private Sub Display_AnimationStart()

If ReportGroup Is Nothing Then
Set ReportGroup = Application.CreateTagGroup(Me.AreaName)
ReportGroup.Add "hourmeter\seconds"
ReportGroup.Add "hourmeter\hours"



Dim p10gst As Tag
Dim p8tower As Tag


Set p10gst = ReportGroup.Item("hourmeter\seconds")
Set p8tower = ReportGroup.Item("hourmeter\hours")


End If

End Sub

I'll most likely just have a hidden display that I call with a macro that runs at our three set times during the day just long enough to generate the text file (when i figure out how to do that).

Am I on the right track though?
 
Hummm
Can you please show me the pattern/format of VB code which use the PLC/HMI tags using factoryTalk view studio...
i mean from tags group to individual tag...
 
Sorry it has taken so long.

The code I have right now is at

Code:
Private Sub Display_AnimationStart()
On Error Resume Next
Dim ReportGroup As TagGroup
Set ReportGroup = Application.CreateTagGroup(Me.AreaName, 500)
ReportGroup.Add "experiment\level"
ReportGroup.Active = True


Dim p10gst As Tag
Set p10gst = ReportGroup.Item("experiment\level")

Dim line1 As String
line1 = "Level at "

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("C:\Users\buddhaman\Desktop\testfile.txt", True)
a.WriteLine (line1)
a.Close



End Sub

It will write to a text file, and it will write "Level at " on the first line but if i try to put something like

Code:
Dim plant10 As Variant
plant10 = p10gst.Value

I get an error cannot read tag wether it is mapped to a memory adress or to a plc.

If i replace p10gst.Value with a number it writes to the text file fine.

alternatively I've tried Setting the plant10 variable as an integer, and a double with the same results.

EDIT: I should also mention that I have tried running this on a client as well as in the development environment all with the same results
 
Last edited:
So this is odd.

I went through with the debugger and it is pulling the tag's value, it highlights that line, I hover over p10gst.Value and it actually shows

p10gst.Value = <correct value>

I can even read the value by pulling the number from the display (showing the correct value in debug mode) with

NumericDisplay2.Value

But when I try to copy it to an integer with like

Dim plant10 As Integer
plant10 = NumericDisplay2.Value

I get a type mismatch even though my tag is an integer.....this is all very confusing, it's like it works it just doesn't like me haha
 
GOT IT!

Code:
Private Sub Display_AnimationStart()

'Pause function to allow values to sync with HMI server
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 20
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer

'Assemble variables for message generation
Dim line1 As String
line1 = ("10GST = " & CStr(NumericDisplay2.Value))

'Write information to text file for later use
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("C:\Users\buddhaman\Desktop\testfile.txt", True)
a.WriteLine ("Report Part 1")
a.WriteLine (line1)
a.Close

MsgBox line1

End Sub

What was occuring in my case was I refreshing the tags in VB before they had refreshed in the HMI server / Display.

A 20 Second delay for my 10 second refresh time and since I already have a reports display Ill just have my scheduled event open my reports display in the background.

Now all that is left is to expand it over multiple txt files for sms, and time it with my email activex control!

Thank you guys for all of your help! :)
 

Similar Topics

Hi there, This is my first post on these forums so i'll say Hi here! I've got a bit of a query, relatable to analytics and getting data out of a...
Replies
11
Views
2,903
I have a graphic that has a display selector drop down object. The selector object allows the operator to select from one of 16 shifts. When...
Replies
3
Views
3,373
I am able to send a email to myself through a message command, but not sure how to translate a tag value, any help would be appreciated. Thanks!!
Replies
4
Views
1,795
Hi, I have 6 fillers, which all run the same. I want to send a value to the same tag address in each of the fillers using FactoryTalk Studio ME...
Replies
4
Views
2,636
Hi, I created my own tag (6 reals and 2 dints). I tried to send it via msg to another PLC, and error 16#0013 "configuration data size too...
Replies
6
Views
18,469
Back
Top Bottom