FTView VBA Issue. Object-variable not set

Input_Change is called after Display_AnimationStart:
Input is an object on the display that is called.

When the display is opened I write "" to inputs by referencing directly the objects which are exposed to VBA.

When the operator changes the Input value on the display at runtime, the code checks if the input is not 0, so it can enable a button which is an object on the same display.


Where do you instantiate that [Input] object, i.e. the same way you instantiate INDICE_LISTA_AB?

See here: https://www.plctalk.net/qanda/showthread.php?p=645502#post645502; note that the [tag1] object is instantiated in Subroutine Display_AnimationStart in that code.
 
...I did more testing and found that if I delete a call to a public function that exists in other code in a module within the same project, the error doesn't happen .
At first, I didn't post the code of this function here because it is not related to the variable, but somehow I think that the variable I highlighted is losing reference after calling this public function from another module.

Here goes the code with the call:


Dim WithEvents INDICE_LISTA_AB As Tag
Dim Read As String
Dim WithEvents Ogroup As TagGroup

Private Sub Display_AnimationStart()
On Error GoTo Err
Read = "SELECT TOP (1) [Num] FROM [DB].[dbo].[Table] order by [Num] desc"
ExSQL (Read)

If Ogroup Is Nothing Then
Set Ogroup = Application.CreateTagGroup(Me.AreaName, 1000)
Ogroup.Add "{/CB/CC/DATA::[PLC]INDICE_LISTA_AB}"
End If
Ogroup.Active = True
Set INDICE_LISTA_AB = Ogroup.Item("{/CB/CC/DATA_CCO::[PLC]INDICE_LISTA_AB}")
INDICE_LISTA_AB.Value = 0
Exit Sub
Err:
LogDiagnosticsMessage Err.Description, ftDiagSeverityError
End Sub

Private Sub Input_Change()
On Error GoTo Err
If (Not INDICE_LISTA_AB.Value = 0) Then
Button.Enabled = True
Button.ForeColor = RGB(0, 0, 0)
Else
Button.Enabled = False
Button.ForeColor = RGB(192, 192, 192)
End If
Exit Sub
Err:
LogDiagnosticsMessage Err.Description, ftDiagSeverityError
End Sub



If I eliminate either the red highlighted part or the yellow one, the error does not happen.

Perhaps the red code generates an error, which jumps to the Err: label, and so the Ogroup and INDICE_LISTA_AB objects are not instantiated.

Try moving the Read = ... and ExSQL(Read) statements to just before the Exit Sub statement, after Ogroup and INDICE_LISTA_AB are instantiated.
 
In Animation_Start, if the assignment of INDICE_LISTA_AB fails, it logs an error but continues without breaking into the debugger or popups.

Is it logging a diagnostic message?

Never mind, that's the problem. The tag names are different.

Ogroup.Add "{/CB/CC/DATA::[PLC]INDICE_LISTA_AB}"

Set INDICE_LISTA_AB = Ogroup.Item("{/CB/CC/DATA_CCO::[PLC]INDICE_LISTA_AB}")
 
In Animation_Start, if the assignment of INDICE_LISTA_AB fails, it logs an error but continues without breaking into the debugger or popups.

Is it logging a diagnostic message?

Never mind, that's the problem. The tag names are different.

Sorry, this is a typo. Code here is referring to "[...]DATA_CCO[...]" both places.
No message is being logged besides the "Object-variable not.."

I'll try the other suggestions and Ill be back soon if it worked or not.
 
Where do you instantiate that [Input] object, i.e. the same way you instantiate INDICE_LISTA_AB?

See here: https://www.plctalk.net/qanda/showthread.php?p=645502#post645502; note that the [tag1] object is instantiated in Subroutine Display_AnimationStart in that code.

[Input] is not an object created in VBA code as [tag1] is. It is an Numeric Input object from FTView Studio, which is exposed to VBA. Being exposed to VBA I can call the event "_change" which means that when it's value changes (the operator set a new value on the runtime), the function below the Private Sub Input_Change() is called. Input_Change() it is a kind of function just as Display_AnimationStart() is, based on an event of an HMI object.
 
Perhaps the red code generates an error, which jumps to the Err: label, and so the Ogroup and INDICE_LISTA_AB objects are not instantiated.

Try moving the Read = ... and ExSQL(Read) statements to just before the Exit Sub statement, after Ogroup and INDICE_LISTA_AB are instantiated.

This one worked perfectly! :):geek:
Thank you very much.

Problem is solved, but now I have other question just for information. While debugging the VBA code, using "step into" (F8), the code would not jump to "Err:". Actually, while debugging, the code went through Ogroup and the Set instructions. So I still cant understand why the INDICE_LISTA_AB was not being instantiated.
But while debugging from the VBA code no error is generated at all. The error is just generated when running application I call the display. Any idea why this happen?
 
This one worked perfectly! :):geek:
Thank you very much.

Problem is solved, but now I have other question just for information. While debugging the VBA code, using "step into" (F8), the code would not jump to "Err:". Actually, while debugging, the code went through Ogroup and the Set instructions. So I still cant understand why the INDICE_LISTA_AB was not being instantiated.
But while debugging from the VBA code no error is generated at all. The error is just generated when running application I call the display. Any idea why this happen?




Timing. It's not what is happening, it is when it happens.
 
While debugging the VBA code, using "step into" (F8), the code would not jump to "Err:". Actually, while debugging, the code went through Ogroup and the Set instructions. So I still cant understand why the INDICE_LISTA_AB was not being instantiated.
But while debugging from the VBA code no error is generated at all. The error is just generated when running application I call the display. Any idea why this happen?


Which version of the code?

  • the one with the two different strings [...]DATA[...] vs. [...]DATA_CCO[...]?
  • the one where the ExSQL(Read) was executed first?
  • something else?
 
  • the one where the ExSQL(Read) was executed first?
This one


In that case, if the ExSQL(Read) statement executes and throws an error, then the Set Ogroup and Set INDICE_LISTA_AB statements never execute, because the ExSQL error causes execution to jump over those Set statements and exit the Display_AnimationStart subroutine without initializing (Setting) INDICE_LISTA_AB
 
In that case, if the ExSQL(Read) statement executes and throws an error, then the Set Ogroup and Set INDICE_LISTA_AB statements never execute, because the ExSQL error causes execution to jump over those Set statements and exit the Display_AnimationStart subroutine without initializing (Setting) INDICE_LISTA_AB

Clear. You assumed this was occurring and this fixed the error for sure.
But when I tried to debug to find the error, this "jump" wasn't happening. The code would go through the Set statement and no error would occur. Why does this only happen at runtime (which I can't debug)?
 
Clear. You assumed this was occurring and this fixed the error for sure.
But when I tried to debug to find the error, this "jump" wasn't happening. The code would go through the Set statement and no error would occur. Why does this only happen at runtime (which I can't debug)?


Ah, that is odd. Have you confirmed that at runtime it is the ExSQL statement that causes the error?
 

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
598
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
897
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,815
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,737
I have a VBA on an alarm banner that calls a large number of pop-ups alarms based on changes of digital PLC tag value. Problem is that when the...
Replies
2
Views
2,324
Back
Top Bottom