You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old September 25th, 2017, 10:31 PM   #1
sscott0203
Member
United States

sscott0203 is offline
 
Join Date: Sep 2016
Location: Ohio
Posts: 5
FTView Studio SE Project Help with VBA, SQL & on Change Events

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
Attached Files
File Type: pdf Display SnapShot.pdf (262.9 KB, 33 views)
  Reply With Quote
Old September 26th, 2017, 06:14 AM   #2
rdrast
Lifetime Supporting Member
United States

rdrast is offline
 
rdrast's Avatar
 
Join Date: Apr 2003
Location: South Carolina Lowcountry
Posts: 5,529
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
__________________
------------------------------------
How to ask questions the SMART Way!

Look First, Ask Second!

  Reply With Quote
Old September 26th, 2017, 10:30 AM   #3
sscott0203
Member
United States

sscott0203 is offline
 
Join Date: Sep 2016
Location: Ohio
Posts: 5
Quote:
Originally Posted by rdrast View Post
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.
  Reply With Quote
Old September 26th, 2017, 10:45 AM   #4
sscott0203
Member
United States

sscott0203 is offline
 
Join Date: Sep 2016
Location: Ohio
Posts: 5
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...
  Reply With Quote
Old September 26th, 2017, 03:19 PM   #5
sscott0203
Member
United States

sscott0203 is offline
 
Join Date: Sep 2016
Location: Ohio
Posts: 5
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.
  Reply With Quote
Old September 27th, 2017, 08:43 AM   #6
rdrast
Lifetime Supporting Member
United States

rdrast is offline
 
rdrast's Avatar
 
Join Date: Apr 2003
Location: South Carolina Lowcountry
Posts: 5,529
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?
__________________
------------------------------------
How to ask questions the SMART Way!

Look First, Ask Second!

  Reply With Quote
Old September 27th, 2017, 10:12 AM   #7
sscott0203
Member
United States

sscott0203 is offline
 
Join Date: Sep 2016
Location: Ohio
Posts: 5
Quote:
Originally Posted by rdrast View Post
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?
  Reply With Quote
Old September 23rd, 2022, 01:37 AM   #8
gopalsrini76
Member
United Arab Emirates

gopalsrini76 is offline
 
Join Date: Jul 2012
Location: dubai
Posts: 8
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
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
sql 2008 database for alarm and events in FTView site V7,V8 mike_dr LIVE PLC Questions And Answers 1 August 9th, 2017 02:30 AM
Migrating RSView VBA code to FTView mateus LIVE PLC Questions And Answers 1 March 7th, 2017 04:45 PM
FTView SE Tag Change VBA code ASF LIVE PLC Questions And Answers 7 June 10th, 2015 12:53 PM
FTView SE VBA - get tag value from parameter ASF LIVE PLC Questions And Answers 1 May 19th, 2015 06:17 PM
RSView Studio 3.2 SE Distributed Project Transfer Help! Doughy LIVE PLC Questions And Answers 3 January 17th, 2007 01:11 PM


All times are GMT -4. The time now is 11:44 AM.


.