FTView Studio SE Project Help with VBA, SQL & on Change Events

sscott0203

Member
Join Date
Sep 2016
Location
Ohio
Posts
5
I've been working on a fairly large project for the last couple months and have come to a road block for the last week. I've spent countless hours searching and trying different methods and after many failed attempts, I'm hoping a knowledgeable fresh set of eyes can help get me back on the right track.

I'm designing a FTView Studio SE display screen that displays railcars in our railyard, utilizing RFID scanners we're scanning the railcar to get it's car ID number into a database so we can determine the contents and insure it get's unloaded to the correct destination.

So I have a display that I had planned to use across all 5 HMI Clients throughout our plant, but do to issues, have decided its best for now to get it working for 1 client, as all 5 are not a requirement, but would be nice eventually.

When this Display loads, I'm querying a SQL database and populating this data into an array, this all works as it should.

I'm stuck in a couple places..
1. getting the VB Code to consistently fire on grouped polygon click event. I'm using the touch to set a tag to a new unload destination (works fine) and then trying to run VB code on that click to refresh my combo box railcar values (works 80% of them time) it's like the click isn't always recognized.

2. The Captions will update correctly when the display is loaded, and my combo boxes populate correctly using a SQL select statement and using the captions in my WHERE clause. However I have really struggled to get this to work when the display is already loaded, thinking it's because I'm writing the new value to the tag through VB and then attempting to read it and then update the caption. Not sure what I'm missing here...

This is my first display from scratch, I have wrote VB in the past in excel and access, but this is new to me and I'm self taught, so any advise will be greatly appreciated.

Attached is a snap shot of the display with some comments, sorry if this ends up being a long post, just wanted to be as detailed as possible.


Code:
Option Explicit
Public WithEvents RailyardTagGroup As TagGroup

Private Sub Display_AnimationStart()
On Error GoTo ErrHandler
If RailyardTagGroup Is Nothing Then
Set RailyardTagGroup = Application.CreateTagGroup(Me.AreaName)

'Create a tag group based on the Area that the Display is located in
RailyardTagGroup.Add ("Railcar\ID0")

'Controller Tags to determine the current API Code and Supplier for each Silo
RailyardTagGroup.Add ("[CLGX1]SILO1_Code")
RailyardTagGroup.Add ("[CLGX1]SILO1_ResinSupplier")

'Controller Tags to determine the current silo destination selected for each System
RailyardTagGroup.Add ("[CLGX2]Unload1_Destination")

'Set the Tag Group that was created above to Active
RailyardTagGroup.Active = True

    End If
    
'Set the Database Connection String
Call SetDB2
    
'Refresh Controller Tags for each Silo's API Code Number and Supplier to insure Tag was placed on scan

RailyardTagGroup.Item("[CLGX1]SILO1_Code").RefreshFromSource
RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").RefreshFromSource


'Created text field labels that are set using the Captions through VB in order to get Controller Tag Values and use them for a SQL Where Clause when Querying the Database

lblSilo1Code.Caption = RailyardTagGroup.Item("[CLGX1]SILO1_Code").Value
lblSilo1Supplier.Caption = RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").Value

'Call the UserForms to refresh OnTrack Inventory and both Systems Combo Box Values (additional code within each UserForm)

Call RefreshTrackInventory
Call RefreshSys1ComboBox
Call RefreshSys2ComboBox

Exit Sub

ErrHandler:
ThisDisplay.Application.LogDiagnosticsMessage "FactoryTalk View VBA Error" & Err.Number & ":" & Err.Description
      MsgBox ("Factory TalkView VBA Error" & Err.Number & ": " & Err.Description)
Resume Next
End Sub

1st attempt to get the captions to set correctly

Code:
Private Sub StrDisplay_Silo1Suppler_Sys1_Change()

On Error GoTo ErrHandler

ThisDisplay.lblSilo1Supplier.Caption = ""
RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").RefreshFromSource

ThisDisplay.lblSilo1Supplier.Caption = RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").Value

ErrHandler:
ThisDisplay.Application.LogDiagnosticsMessage "FactoryTalk View VBA Error" & Err.Number & ":" & Err.Description
      MsgBox ("Factory TalkView VBA Error" & Err.Number & ": " & Err.Description)

Resume Next
End Sub

Another attempt to get the captions to set correctly

Code:
Private Sub grpSilo2Supplier_Sys1_Click()
Dim intChangeConfirm
Dim frm As frmEnterCode
Dim intEmptyConfirm

Set frm = New frmEnterCode

 intChangeConfirm = MsgBox("Are you sure you want to assign a different Supplier to Silo 2?", vbExclamation + vbYesNo)

        If intChangeConfirm = 6 Then
            intEmptyConfirm = MsgBox("Have you confirmed that Silo 2 is EMPTY?", vbExclamation + vbYesNo)

                If intEmptyConfirm = 6 Then
                   ThisDisplay.lblSilo2Supplier.Caption = ""
                    frm.InstanceTag = "Silo 2"
                    frm.PLCTag = "[CLGX1]SILO2_ResinSupplier"
                    frm.show

                    On Error Resume Next
                    Set frm = Nothing
                 
RailyardTagGroup.Item("[CLGX1]SILO2_ResinSupplier").RefreshFromSource

lblSilo2Supplier.Caption = RailyardTagGroup.Item("[CLGX1]SILO2_ResinSupplier").Value

Call RefreshSys1ComboBox
Call RefreshSys2ComboBox   
 
End If
End If
 
End Sub


Code:
'REFRESH SYSTEM 1 RAILCAR SELECTION COMBO BOX UPON A NEW SILO DESTINATION SELECTION/CLICK (Grouped Polygon's)

Private Sub grp_Sys1_Silo1_Click()

ThisDisplay.Sys1_RailcarSelection_ComboBox.Clear
Call RefreshSys1ComboBox

End Sub
 
It's FTView, nothing works like you think it should. VBA is going to try to immediately generate the caption, BEFORE the tag's value actually updates. (most likely).

Try updating the captions from local strings, updated from the tag value.

Code:
RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").RefreshFromSource
MyString = RailyardTagGroup.Item("[CLGX1]SILO2_ResinSupplier").Value
ThisDisplay.lblSilo1Supplier.Caption = MyString
 
It's FTView, nothing works like you think it should. VBA is going to try to immediately generate the caption, BEFORE the tag's value actually updates. (most likely).

Try updating the captions from local strings, updated from the tag value.

Code:
RailyardTagGroup.Item("[CLGX1]SILO1_ResinSupplier").RefreshFromSource
MyString = RailyardTagGroup.Item("[CLGX1]SILO2_ResinSupplier").Value
ThisDisplay.lblSilo1Supplier.Caption = MyString

Thanks for the suggestion, you have posted valuable information in this forum as I see your name often while searching for answers and was hoping you would see this post.

This method worked on the first attempt, but when I changed the value a 2nd time, the caption did not update and retained the previous value.
 
Once it doesn't update the caption and the caption contains the previous value, I try and change the string value, but really just enter the same value again and the caption clears and still puts the previous value in..... frustrating...
 
I may have figured it out finally.
I can change the tag value in Studio 5000 and everything works as it should.
I believe the issue is trying to write a value to a tag in VB and then read it and update the caption.

Will advise, in case this will be helpful to anyone else.
 
Sadly, FTView is absolute garbage.
Ignition handles this perfectly well, no matter what route you use to do it.

RefreshFromSource by the way, doesn't actually always refresh from the PLC. It is perfectly happy to grab a cached value from LinxEnterprise if it is within the update period. Maybe put those tags on a display (this one or hidden) with an insane display update time?
 
Sadly, FTView is absolute garbage.
Ignition handles this perfectly well, no matter what route you use to do it.

RefreshFromSource by the way, doesn't actually always refresh from the PLC. It is perfectly happy to grab a cached value from LinxEnterprise if it is within the update period. Maybe put those tags on a display (this one or hidden) with an insane display update time?

It's very critical that my captions are updated with the new tag value so as I double check I was thinking about doing the following and wanted to know your opinion.

When my string display which is displaying a controller tag (Tag1), is changed, I update a text caption(Caption1) through VBA that is used in a SQL WHERE Clause.

What if after the caption was set through VBA, I took the text caption value and wrote that caption value to a new controller tag (Tag2) that I would create. Then in Studio 5000, compare the caption controller tag (Tag2) to (Tag1), if they don't match I could then flag the HMI Client that there is a problem. If they don't match, the caption didn't update correctly and the SQL WHERE Clause would be incorrect.

Just trying to add an extra fail safe in place. Thoughts?
 
Hi,

Though its been many years from the date you have posted, I am also in the same situation like you. Did you find any solution? I trying to check as what you have done. However I am trying to check with a HMI memory tag and I want the Memory tag to get updated based on the condition.

I am not able to have value refreshed when the Display is active. However when I navigate to another display and back to the original, the value gets updated

Kindly suggest me or if possible try to send the working code
 

Similar Topics

Hello everyone, I had a problem that happening with FactoryTalk View Studio SE (V12) (Network Distributed). If i create a new project...
Replies
0
Views
615
Hello Experts, I am trying to create a SINE Wave generator and i cannot seem to make it smoother. I have done this before but i forgot the exact...
Replies
6
Views
240
Hello all. Is there a way to upload alarm tags at the bit level to my FTView studio? I export them from my PLC thinking I will upload them to...
Replies
2
Views
391
Hello all. Many years ago I programmed an Omron PLC and HMI and I was able to control which display was being shown on the HMI from the PLC. Is...
Replies
5
Views
320
Hello all. I am trying to establish my connections in FTView Studio. Normally, after I have set up my offline tag file in communication setup I...
Replies
3
Views
628
Back
Top Bottom