Reading an objects connection tag in VBA

awhite

Member
Join Date
Apr 2013
Location
NH
Posts
17
Is it possible to read from an object (button, pushbutton, or multistate indicator, etc.) the connection tag from within VBA?
 
What software are you using?

Assuming you are in FTView (I'm not quite clairvoyant yet 🍺 ) then open FTV help. Browse help to find VBA programming and find the tag object model. Open it and you'll find a description of the object model to access tags and some program examples on how to do that.
 
Last edited:
Yes, FT View SE. I cannot see the connection tag listed in the object model that I was able to download from the Rockwell site. EIther I'm not looking in the right spot or the help file isn't much help on this.
 
That's the plan. But how do I get VB to pull the tag from the button?

Button.Tag <=> PLC
Button.Tag >- VB <=> PLC

I really need to get it to work this way. There are a few hundred of these to put in and will reduce up keep by 50% if the tag changes.
 
OK, I need to find a way to get you to stop fixating on the button and forget about it for a little while because you can't access a tag through a button object, that's not how the tag object model works. Since I haven't explained that very well so far, at the risk of seeming a little pedantic while trying to help you look at the problem from the right angle, I'm going to ask you to follow along.

Step 1 is drastic. Open your screen and delete the button. Nuke it, get it out of sight and out of mind and make it not exist. We can recreate it later. (At this point you're tempted to read ahead... stop and go back and delete that button.)

Now that the button no longer exists and can no longer be the object of your focus I want you to look to the left of your screen and find Tags in the project tree. Open it and browse to the tag for the PLC address you want to read/write to using VBA. If the tag doesn't exist yet then create it. Highlight this tag. This is the object you will be accessing by name in VBA. (you read ahead, didn't you?)

Now go back to your HMI screen. Right click in a blank spot and access the VBA code. Here is where we will create code to do the following:
1)Create a tag group, lets call it MyTagGroup.
2)Using MyTagGroup's add method we are going to add a tag by name to the group. The name we will use is the full name of the tag including any folders as seen in the Tag DB in the previous step.
3)Now we can access the tag as an object in VBA. By reading and writing to the .value property you can change the value of the tag in VBA.

Think of it this way: Your tag is a well. The VBA is Jill. The button is Jack. Jill can take water from the well. Jill can toss a wishing coin in the well. Jill can leave and go home and never talk to Jack. Jack can take water from the well. Jack can toss a wishing coin in the well. Jack can fall down and never see Jill. The two never need cross paths, but both can take from the well or add to the well as they please. Jill can go to another well and take from it or toss a wishing coin in it. Jack cannot.

I am at home right now so I don't have the VBA tag model available to give you the exact syntax, but if you will open up help and look under VBA for the TAG OBJECT model (remember, you should have deleted your button so you aren't looking for anything that has the word button in it) then you will find sample code on how to create a tag object group, how to add a tag to the group by name, and how to access a tag in the group as an object. Once you see the sample code you'll have an 'Ah Ha!" moment.

I hope that helps you see it from the right angle.

🍺
 
Last edited:
To access a few hundred of these then you will add a few hundred tags to the tag group. You can put the tag names in an array or add an entire tag folder to the tag group to make this easier. You can then pass the tags as objects to subroutines so that you can reuse code and simplify maintenance. You can do bulk operations on the entire tag group using the FOR EACH statement and the WITH statement.

Later you can add your button(s) back in and use a click event to execute VBA code when the button is pressed if you want. Each button will need its own click event subroutine, but that subroutine can re-use other VBA code as much as you want.
 
Last edited:
You too have missed the mark. There are 180 screens with multiple items per screen across many PLCs and not a single tag in the tag database.

I knew all of what you said before you typed the first word. All that needed to be done was confirm the reason I can't see the connection tag in VBA is that it cannot be done. It's not part of the VBA object model.

I have a few options at this point. A less precise VBA script, change the multistate (only 2 states anyway) and Up/Down Toggle bit pushbuttons to two buttons, possibly in a global with a paramterized tag, which solves a series of the issues at once, or go the route you outlined (I doubt since they don't use the tag database to access PLC values.
 

Similar Topics

Trying to setup a message read via Ethernet. I have the path setup as 1, 1, 2, 192.168.66.10 I get an error code 1, ext err 315. I am beating...
Replies
9
Views
224
Dear all, I don't know why setup of password became challenging and weird. After setting up the password and try to upload the ladder from the plc...
Replies
3
Views
165
hi all, i have a plc i need to get info from for a site im working on: I have a 1764 Micro Logix 1500 LSP Series C (See Attached Image) im...
Replies
2
Views
367
Hi to everybody. I need to read the first 12 characters of the message that a barcode reader sends to the ascii card (1734-rs232 ascii) and I...
Replies
8
Views
719
Hey, I have a PowerMonitor1000 I'm using for voltage control. The problem is it doesn't seem to read voltage until it gets to about 200V...
Replies
0
Views
360
Back
Top Bottom