Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Help with VBA Code

More
21 Aug 2016 10:43 #4305 by support
Replied by support on topic Help with VBA Code
This will work in version 5.41. You will use the new SetState method, instead of the property setter for the Set property.

It is implemented and tested; but there are no plans to release 5.41 yet, as there aren't enough significant changes accumulated yet.
The following user(s) said Thank You: cdunlap

Please Log in or Create an account to join the conversation.

More
05 Jul 2016 15:40 - 05 Jul 2016 15:41 #4194 by support
Replied by support on topic Help with VBA Code
Unfortunately I have to disappoint you. It looked like that I could make it work in version 5.40, but in the end I have figured out that it depends on factors (Microsoft) that I cannot control, and could not even determine what they precisely are. It is possible that it will work on some computers, still.

For version 5.41, I want to add a SetState method, which you will be able to use in place of the State property setter, and that should resolve it.

For now, please stick with the old approach. To somewhat easy your pain, I have found that you actually *can* use the "New" keyword (no need for "CreateObject"), you just need to stay away from *declaring* the variable as being early bound. I.e. this does not work:
    Dim MonitoredItemArguments1 As New EasyUAMonitoredItemArguments
    MonitoredItemArguments1.State = "D2"
But this does:
    Dim MonitoredItemArguments1: Set MonitoredItemArguments1 = New EasyUAMonitoredItemArguments
    MonitoredItemArguments1.State = "D2"

Regards
Last edit: 05 Jul 2016 15:41 by support.

Please Log in or Create an account to join the conversation.

More
04 Jul 2016 13:13 #4185 by support
Replied by support on topic Help with VBA Code
Will reply - please be patient.

Please Log in or Create an account to join the conversation.

More
30 Jun 2016 19:09 #4181 by cdunlap
Replied by cdunlap on topic Help with VBA Code
Hello,

I have tested this out after upgrading to v 5.40 but I still get the same error when attempting to assign a value to the state variable after I create the object via the "New" keyword instead of CreateObject.

I altered the UASubscripeToMultiple2 example's SubscribeCommandButton_Click() sub like so:
    'Dim MonitoredItemArguments1: Set MonitoredItemArguments1 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments")
    'MonitoredItemArguments1.EndpointDescriptor.UrlString = "http://opcua.demo-this.com:51211/UA/SampleServer"
    'MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/;i=10845"
    'Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters
    'MonitoredItemArguments1.State = "D2"
 
    Dim MonitoredItemArguments1 As EasyUAMonitoredItemArguments
    Set MonitoredItemArguments1 = New EasyUAMonitoredItemArguments
    MonitoredItemArguments1.EndpointDescriptor.UrlString = "http://opcua.demo-this.com:51211/UA/SampleServer"
    MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/;i=10845"
    Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters
    MonitoredItemArguments1.State = "D2"

Is there some other way I must change it to get it to work properly via the "New" keyword?

Please Log in or Create an account to join the conversation.

More
02 Apr 2016 09:47 - 02 Apr 2016 09:47 #3974 by support
Replied by support on topic Help with VBA Code
I have tested "New" with the current state of 5.40 now, and it works fine on the development computer.
Last edit: 02 Apr 2016 09:47 by support.
The following user(s) said Thank You: cdunlap

Please Log in or Create an account to join the conversation.

More
31 Mar 2016 18:54 #3972 by cdunlap
Replied by cdunlap on topic Help with VBA Code
Hello,

Do you have an update on this issue? Do you think that the "New" keyword in Excel will work now after your development in VS 2015 with the coming version 5.4, or will it still give the same behavior as before?

Thank you

Please Log in or Create an account to join the conversation.

More
30 Dec 2015 09:14 #3732 by support
Replied by support on topic Help with VBA Code
It looks like that, but I do not want to blame Microsoft without having a proof - and I do not have it at the moment.

Please Log in or Create an account to join the conversation.

More
29 Dec 2015 18:49 #3731 by cdunlap
Replied by cdunlap on topic Help with VBA Code
OK. Thanks for the info. So this seems like some kind of weird function with the COM Interop technology from Microsoft?

In any case, I will stick with CreateObject for now.

Thanks again.

Please Log in or Create an account to join the conversation.

More
29 Dec 2015 17:18 #3730 by support
Replied by support on topic Help with VBA Code
Hi C.,
I know about this - but I do not know the answer; just some hints.

In general, using 'New' in VB6/VBA requires that the object's type library is referenced & present for the compilation. VB can then use early binding on the resulting object, and provide better developer experience etc.

'CreateObject', on the other hand, is completely run-time thing. At the compilation time, VB6/VBA does not know anything about the resulting value, besides the fact that it in OLE automation object. Specifically, it does not know the methods available, their arguments and their types, etc.

Apparently I do not know enough about VB6/VBA, because in the scenario we are discussing, I would think that the results/behavior should be the same. But i know it is not, and I have noticed the same during the development of these examples. That's why I have resorted to the use of 'CreateObject', even though I would normally prefer and use 'New'.

The issue may be related to the fact how .NET generates type libraries from the C# code, and how the COM interop works at run time. I have met some other weird or unexpected things in this area as well.

Interestingly, I am now developing a new version of QuickOPC (5.40+), and have switched to Visual Studio 2015 for its development. And, without having changed anything in the relevant code, some of these COM things started behaving differently - and, as far as I can say, the change was to the better. It is possible that Microsoft has fixed a thing here and there.

Best regards

Please Log in or Create an account to join the conversation.

More
28 Dec 2015 22:03 #3729 by cdunlap
Help with VBA Code was created by cdunlap
Hi,

I am having some trouble building off of one of the VBA Excel examples and I was hoping to get some input on it. This is not specifically related to a problem with the component itself, but more on why certain code works and certain code does not work. I am sure it's more of a lack of knowledge of VBA than anything else, but i was hoping that you could help :) .

Basically, If I run the code in the UASubscribeToMultiple3.xls file, everything works great.

I have a customer that tried modifying the declaration of the MonitoredItemArguments to use the 'New' keyword as opposed to a call to CreateObject(). It will not allow anything to be assigned to the 'State' variable, and gives an error message, but I cannot figure out why.

So the original code looks like this:
    Dim MonitoredItemArguments1: Set MonitoredItemArguments1 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments")
    MonitoredItemArguments1.EndpointDescriptor.UrlString = "http://opcua.demo-this.com:51211/UA/SampleServer"
    MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/;i=10845"
    Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters
    MonitoredItemArguments1.State = "D2"

The slightly altered code looks like this:
    Dim MonitoredItemArguments1 As EasyUAMonitoredItemArguments
    Set MonitoredItemArguments1 = New EasyUAMonitoredItemArguments
 
    Dim Endpoint As String
    Dim Node As String
    Dim CellName As String
 
    Endpoint = "http://opcua.demo-this.com:51211/UA/SampleServer"
    Node = "nsu=http://test.org/UA/Data/;i=10845"
    CellName = "D2"
 
    MonitoredItemArguments1.EndpointDescriptor.UrlString = Endpoint
    MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = Node
    Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters
    ' Below is where it fails. ************************************************
    MonitoredItemArguments1.State = CellName ' Gives Runtime error 424: object required
    ' MonitoredItemArguments1.State ="D2" doesn't work either
    ' *************************************************************************

The altered code gives back an error on the line that tries to assign a value to the 'State' object that says "Run-time error '424': Object required".

From everything that I can find, it sounds like CreateObject and New are somewhat interchangeable, but that doesn't seem to be the case here.

So basically, I am stumped as to why CreateObject works, but defining it with the 'New' keyword does not. I know that this is more of a VBA question than a specific question about this component, but I was hoping I could get some insight.

Thank you in advance for the help

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.063 seconds