MorphuisOGrady
Member
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:
Now here is the call:
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?
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
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?