Writing String Value to Controllogix using VBA

D.Chris

Member
Join Date
Jun 2013
Location
Jakarta
Posts
21
PLC Gurus, I need a little bit help here..

A little background, we're working on a project using PlantPAx from Rockwell.. We use some of their built-in global objects and create some of our own.. The thing is, the string tag which will be used to display tag names are stored in the controller as a tag inside the add-on defined tag (Cfg_Label)..

Since manually writing them one by one would be time consuming (deadlines...deadlines..), I'm trying to utilise the VBA feature of FTView Studio to write on them all at once..
This is roughly what I have at the moment:

Dim Tagname As String
Tagname = [PATH]PLCTag

Dim Cmd as String
sCmd = "Set {" & Tagname & "} & InputValue

I've tried for other data type (BOOL, DINT) in the input value, and it's working well.. The problem is when I want to write String values, the VBA will alwas looking for the tagname with the name as my String value..

The plan is to have Tagname and InputValue as arrays and put the above code in a for loop..

Any suggestions on how to do this?

Thanks
Dan
 
Hi Dan,

I've done a few things with vb in factory talk, so far its mainly been reading out the tags and creating csv logs but i just tested this out from a button and it works OK:

Code:
Private Sub Button_Released()

'Declare Variables
Dim MyTagGroup As Object
Dim tagName As String
Dim engUnits As String

'Create tag group, then add required tags
If MyTagGroup Is Nothing Then
    Set MyTagGroup = Application.CreateTagGroup("/")
    
' Set the values of the required tags
    tagName = "{[CaskYard]PT7000.Eng_Units}"
    engUnits = "Bar"
    
    Set tagValue = MyTagGroup.Add(tagName)
    
    tagValue.Value = engUnits
    
End If

End Sub

Hopefully this helps you, i'm not sure if this differs from what your trying to achieve?
If im off the mark just get back in touch & ill try again (one of those days so far šŸ™ƒ)

Ash
 
Thanks for the reply Ash.
Just had the time to test the code this week.

I managed to get it work using your code as the reference.
The thing is, when I do it like this:

Set tagValue = MyTagGroup.Add(tagArray[1])
tagValue.Value = tagEU[1]

The program is not working.




But if I do it like this:

tagName = tagArray[1]
engUnits = tagEU[1]

Set tagValue = MyTagGroup.Add(tagName)
tagValue.Value = engUnits

It's working.




I'm still quite newbie in VBA, does anybody know what makes the second code works and not the first one? Just curious.
Anyway, thanks for the help!

Regards,
Dan
 
I've only got enough VBA knowledge to be dangerous, but at a quick glance, I'd try putting quotation marks around tagArray[1] in your first example and see if that makes it work...
 
Hey Dan, sorry i didnt see this reply sooner.

Is tagEU[1] a tag in your PLC?
If so use:
Code:
Set tagValue = MyTagGroup.Add(tagArray[1]) 
Set tagEU = MyTagGroup.Add(tagEU[1]) 

tagValue.Value = tagEU.Value

If not then i think i had to set the string then pass that into the PLC tag because factory talks version of VB wants to to do so, it will not allow the direct string (I think)

im not near my development laptop at the moment but will try later on

Ash
 

Similar Topics

How can i write aHint or dialog Text box when runtime manger already running .
Replies
0
Views
1,645
Hello All This is my first Transaction Manager project. I have a working configuration in Transaction Manager 10.20 that successfully writes...
Replies
3
Views
7,631
RSlogix5000 - Here is what I would like to accomplish and what I am running into. Currently this is a scanner ASCII gateway to PLC set up. A)...
Replies
9
Views
3,975
Using FTV 9 SE Local Windows 10 Trying to use a little VB to write to a string. Keep getting an error. 'Taggroup\Tagname is a string Dim Note...
Replies
1
Views
2,011
Could somebody please point me in the right direction? I'm trying to incorporate a table into each motor's faceplate. It's a simple, two...
Replies
2
Views
3,201
Back
Top Bottom