FTV SE VBA Coding

JonAW

Member
Join Date
Sep 2013
Location
Somewhere
Posts
121
Hi Guys,

I'm a complete novice at anything VBA. I've been reading and reading threads on this site and others to be able to understand it a little better. Anyway on the project I'm doing at the moment it would be really nice to have a drop down menu to be able to select materials for a mix. I can use the standard factorytalk SE List boxes but they are not very aesthetically pleasing.

What I'd like to use is the ActiveX combobox. I have been trying to get this to work but it has beaten me so far. I can populate the drop down menu's with standard text singularly no problem and also populate with arrays using the .list command, but I'd really like to direct reference tags in my plc (compactlogix) so these drop down lists change with the plc data. I've come across posts where people direct reference micrologix plc tags and have tried to copy this method by placing a tag similar to the following in place {[Compactlogix process]Sample_tag]}. However the VBA system doesn't like the outside brackets unless I put quotation marks at either side in which case it displays the text inside the quotation marks. It's Very frustrating and I'm sure perfectly simple to seasoned VBA guys.

I have absolutely no experience with VBA of any kind or other similar programming software so please any help is appreciated.

thanks

Jonny
 
Open up help and find the VBA tag object model and read and understand how the object model is constructed, the follow the examples shown there. You have to create a tag object, then assign that tag object to a tag. All tag value reading and changing happens with the tag object. If you are using a large number of tags then use a tag group.
 
Hi TConnolly,

Thanks for your reply. I'd prefer answers which make me do a bit more digging, that way I understand things better.
Anyway I had previously looked at the manual but couldn't get my head around the language. After reading your reply, I remembered a saying an old Maths teacher said once when a couple of the people in the class where struggling. He said 'you don't have to fully understand what your doing, just follow the set procedure, applying the variables that apply to you and you'll get the result.' Granted this saying simplifies things maybe too much but I applied this logic to the examples shown in the VBA manual. Eventually I got there with a bit of hair pulling. I still don't fully understand what I've just done but it works!.

This is the code I used to get this to work, I've since added 100 tags as required:

'Set Ingredient as a Taggroup
Dim WithEvents Ingredient As TagGroup
'Set Tagn as a Tag object
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 Tag7 As Tag
Dim Tag8 As Tag
Dim Tag9 As Tag
Dim Tag10 As Tag
'Set Runonce As an integer Tag
Dim Runonce As Integer
Private Sub Combobox1_DropButtonClick()
If Runonce = 0 Then
On Error Resume Next
Err.Clear
'Populate Combobox With Tag Values
Combobox1.AddItem Tag1.Value
Combobox1.AddItem Tag2.Value
Combobox1.AddItem Tag3.Value
Combobox1.AddItem Tag4.Value
Combobox1.AddItem Tag5.Value
Combobox1.AddItem Tag6.Value
Combobox1.AddItem Tag7.Value
Combobox1.AddItem Tag8.Value
Combobox1.AddItem Tag9.Value
Combobox1.AddItem Tag10.Value
'Set Runonce tag to 1 to inhibit repopulating dropbutton on this instance
Runonce = 1
End If
End Sub

'When Display is Closed Clear the Combobox1 List and reset Runonce Tag to 0
Private Sub Display_Unload()
Combobox1.Clear
Runonce = 0
End Sub
Private Sub Display_Load()
'On Display load Setup the Ingredient Taggroup to look at external source for values
On Error Resume Next
Err.Clear
If Ingredient Is Nothing Then
Set Ingredient = Application.CreateTaggroup(Me.AreaName, 500)
If Err.Number Then
LogDiagnosticsMessage "Error creating TagGroup. Error: " & Err.Description, ftDiagSeverityError
Exit Sub
End If
'Add PLC tags to taggroup
Ingredient.add "[CompactLogix Processor]Ingredient_List[0]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[1]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[2]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[3]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[4]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[5]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[6]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[7]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[8]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[9]"
Ingredient.add "[CompactLogix Processor]Ingredient_List[10]"


Ingredient.Active = True
End If
'Set Tagn to alias tags in the Ingredient taggroup
Set Tag1 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[0]}")
Set Tag2 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[1]}")
Set Tag3 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[2]}")
Set Tag4 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[3]}")
Set Tag5 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[4]}")
Set Tag6 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[5]}")
Set Tag7 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[6]}")
Set Tag8 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[7]}")
Set Tag9 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[8]}")
Set Tag10 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[9]}")
Set Tag11 = Ingredient.Item("{[CompactLogix Processor]Ingredient_List[10]}")

End Sub


thanks again,

Jonny
 
Last edited:
Ftv se

Hi guys
I want change Time Span on Trend with Slider (eg. from minute to month).
Does anyone know how to solve the problem ( I guess with using VBA code).
o_O
 

Similar Topics

Anybody know of a complete (or relatively complete) resource for VBA functions available to FTV SE? I know there are specific functions and...
Replies
6
Views
1,587
Dear SIR , We are having some problem regarding VBA code for FTV 8.10. We had a project in which we had to convert the old SCADA RSVIEW 32 with...
Replies
0
Views
1,681
Can you help me with the following? I know when creating an expression using the "display" command I can use different switches to cause the...
Replies
0
Views
1,018
I’m trying to disable a button after a popup is opened using VBA. It works and the button looks disabled but I can keep clicking the button until...
Replies
5
Views
2,162
Back
Top Bottom