Are you facing the "Object-variable or With block variable not set" error when running a VBA code on FTView? Even though the code is functioning, the error appears every time you open the display that triggers the VBA code. Since the issue line was not identified during debugging, the code had to be divided into parts to pinpoint the problem. Here's a snippet of the code with the problematic line highlighted: Within the code, the PLC tag is a DINT. If you encounter this error, you can fix it by carefully analyzing and adjusting the highlighted line in the provided code. Don't hesitate to seek further assistance if needed.
If you are trying to reference an object that has been set to Nothing or access an undeclared element in an array variable, you may encounter an error. This could happen if the array is treated as an object with no elements. Another common mistake is trying to access code within a With...End With block before initializing the block. To avoid these errors, make sure to initialize the With...End With block by executing the With statement entry point. Enabling Option Strict can help identify errors more easily. This way, the compiler will point out where the issue lies.
Parky mentioned that you may be encountering an error in VBA due to referencing an object that has been set to Nothing, accessing an undeclared element of an array variable, or trying to access code within a With...End With block before it has been initialized. To solve this issue, it is recommended to turn on Option Strict in order for the compiler to identify the exact location of the error. Unfortunately, if you are not well-versed in VBA, finding where the improper referencing or declaration occurred can be challenging. Also, keep in mind that the "With" instruction is not being utilized and Option Strict may not be available, resulting in a compile error message.
Where is the Input_Change() function triggered from? If the variable INDICE_LISTA_AB has not been assigned a value, it is not uncommon to encounter an error (refer to parky's first point). Although I am not familiar with using VBA in a PV, is it possible to set an initial value using the DIM statement? For example, something similar to: Code: [COLOR=Blue]Dim WithEvents INDICE_LISTA_AB [B][U]= 0 [/U][/B]As Tag[/COLOR]. It is unlikely that this will work as is, but a similar approach may be successful. Alternatively, it is important to ensure that the variable is initialized before it is utilized.
Joseph_e2 asked about the calling of Input_Change() function and mentioned that if the variable INDICE_LISTA_AB is not set, encountering an error is understandable. The possibility of assigning an initial value using the DIM statement was considered. For example, DIM WithEvents INDICE_LISTA_AB = 0 As Tag might be a solution, although it may require adjustments. It is crucial to ensure the variable is initialized before using it. In FactoryTalk View, "Input_Change()" is triggered by a numeric input object's value change. If the value changes, the code should verify that INDICE_LISTA_AB is not 0 before enabling the "Button" object in FTView. An attempt was made to set the initial value with the line: INDICE_LISTA_AB.Value = 0. However, the code may not work due to Tag not being a variable type but an object with properties like ".Value" that can be Integer or String. Nonetheless, the value of 0 is set at the display's startup before the "Input_Change()" event occurs.
If you are using a PLC tag to determine the visibility of a button, consider utilizing the "states" tab in the button properties for a more efficient solution. You can also assign different tags for the button's value and indicator on the "Connection" tab. Although I have attempted to implement VBA a few times for this, I have not achieved consistent results on the panel interface, even when running simulations successfully.
It sounds like your issue might stem from an uninitialized object variable. Before you use an object variable, it needs to be set using the Set statement. If you happen to skip this initialization and call a method or property on the variable, VBA will throw the "Object variable or With block variable not set" error you're seeing. My suggestion is to review your problematic line of code and make sure you have properly initialized all the objects that you're utilizing in it.
Your issue could actually be stemming from a variable that was not properly initiated before running the code. Sometimes when the code references an object before setting it, an "Object-variable or With block variable not set" error occurs. I found it helpful to ensure that all variables are correctly initialized before running the code. Try looking through your code again to see if you may have missed initializing a variable. Hope this helps!
This issue could be arising due to a reference to an Object or a With block variable that hasn't been set yet. There's a good chance the object you're attempting to reference is not fully instantiated when the code is run. I'd recommend checking the timing of when your objects are being set vs when they're actually first being called. Also, confirm the scope of these variables to ensure each subroutine correctly has access. Hope this helps!
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Answer: - This error indicates that there is an issue with a variable or object not being properly initialized before use in the VBA code.
Answer: - To troubleshoot this error, you may need to divide the VBA code into parts and carefully analyze each section to identify the problematic line causing the error.
Answer: - The PLC tag causing the error in the VBA code was a DINT type.
Answer: - If you encounter this error with a DINT PLC tag, you can fix it by carefully reviewing and adjusting the highlighted line in the VBA code that interacts with the PLC tag.
Answer: - If you are unable to identify the problematic line during debugging, consider seeking further assistance or consulting with experts to help pinpoint and resolve the issue.
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.