VBA FTView SE to Write to a PLC tag (Direct reference)

Join Date
Jul 2007
Location
Kiruna
Posts
600
Hi Guys,

I am having some difficulty getting some VBA to work.My VBA is bad...

I want to write a subroutine which takes 2 parameters 1. Value to write, 2. Tag Name and write the value to the respective tag.

Here is the sub:

Code:
Sub SetTagValue(valueToWrite As Integer, tagName As String)
On Error Resume Next

Dim oTag As Tag

'Make sure the tag group exists
If Not OGroup Is Nothing Then

Set oTag = OGroup.Item(tagName)

Err.Clear 'Clear out any old errors before the write
 oTag.value = valueToWrite
 

Select Case Err.Number
Case 0:
'Write completed successfully... log a message (If desired)
LogDiagnosticsMessage "Write to tag " & oTag.Name & _
" was successful."

Case tagErrorReadOnlyAccess:
MsgBox "Unable to write tag value. Client is read-only."

Case tagErrorWriteValue:
If oTag.LastErrorNumber = tagErrorInvalidSecurity Then

MsgBox "Unable to write tag value. The current user " & _
"does not have security rights."
Else

MsgBox "Error writing tag value. Error: " & _
oTag.LastErrorString
End If
Case tagErrorOperationFailed:

MsgBox "Failed to write to tag. Error: " & Err.Description
End Select
End If

End Sub
Now here is the call:

Code:
Private Sub Prefill_ComboBox_Change()
On Error GoTo ErrorHandler

If Prefill_ComboBox.value = "Not Selected" Then
    SetTagValue(0, "{::[Metso]Program:TUBE_1.Selections.Val_Prefill_Selection}")
    
ElseIf Prefill_ComboBox.value = "Prefill On Time" Then
     SetTagValue(1, "{::[Metso]Program:TUBE_1.Selections.Val_Prefill_Selection}")
ElseIf Prefill_ComboBox.value = "Prefill On Pressure" Then
    SetTagValue(2, "{::[Metso]Program:TUBE_1.Selections.Val_Prefill_Selection}")
    End If

But i get a compile error on:
If Prefill_ComboBox.value = "Not Selected" Then
SetTagValue(0, "{::[Metso]Program:TUBE_1.Selections.Val_Prefill_Selection}") saying

Compile Error := expected.

Has anyone any idea what is wrong?
 

Similar Topics

Hi all. Currently I'm working on a VBa script for FTView. I would like to understand a bit better about some commands. 1) What are the...
Replies
3
Views
589
Hi all. I'm running a VBA code on my FTView which is actually working, but everytime I open the display that calls the VBA code, it throws the...
Replies
28
Views
1,774
Greetings, I have this question: How can I add a tag, in my case LS:0 {#5} (literal string of tag #5), to a variable using VBA? I couldn't find...
Replies
4
Views
889
Hello Every one, I need a help on vba code for getting data from MSSQL server 2014 to display in FTview SE client version 12 . Thanks. Please...
Replies
4
Views
1,803
I've been messing around with trying to find a way to clear all PlantPAx AOI latched alarms via the Alarm Banner or Summary objects. So far, I can...
Replies
2
Views
1,727
Back
Top Bottom