Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I receive subject error, after executing the following code.

VB
'set up device
Select Case PLCType
    Case eABPLCType.Logix
        mDevice = New Logix.Device(tTag.PLC_IP)


The error occurs in the following line of code.

VB
mChannel.Devices.Add(mDevice)


My big question is why New doesn't give me the error, and how can I tell if I am looking for a class or what?

I am stepping over the following code.

VB
Private WithEvents mDevice As Device<code></code>


How can I trace through this?
Posted
Updated 16-May-12 8:44am
v2
Comments
ledtech3 15-May-12 17:38pm    
Not all classes have instances of them. Sometimes you have to “Create” an instance to the class before you can use them. By using the "New" keyword you created an instance to the class, thus allowing you to be able to interface with it.
The best I know (I’m still learning this stuff myself) you can study Interface and abstract classes to get a better understanding. Here is a link to MSDN to get you started. http://msdn.microsoft.com/en-us/library/9cc659c4(v=vs.71)
Hope this helps some.

As far as I can see either mChannel or mChannel.Devices is Nothing.
mDevice = New Logix.Device has little to do with it... Unless tTag is Nothing or tTag.PLC_IP is Nothing and it is used in the constructor.
Make sure all of these variables get a value somewhere (either by creating a new instance or assigning them an already existing one).
Little more I can tell from the code you posted...
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 15-May-12 17:35pm    
My 5.
--SA
Sander Rossel 15-May-12 17:49pm    
Thank you.
VJ Reddy 15-May-12 21:02pm    
Good answer. 5!
Sander Rossel 16-May-12 1:11am    
Thanks! :)
This is because mChannel can null, or else, however unlikely, mChannel.Devices can be null (Nothing). This kind of exception is one of the easiest to figure out and fix. Either make sure the member/variable is initialized before use, or check it for null and avoid de-referencing it. Always use the debugger to find out what's going on. Actually, you need to use the debugger before asking questions like this one. You also need to use it if you have a slightest concern about your run-time behavior.

—SA
 
Share this answer
 
v4
Comments
Sander Rossel 15-May-12 17:34pm    
Correct, and posted at exactly the same time. My 5 :)
Sergey Alexandrovich Kryukov 15-May-12 17:35pm    
I see, thank you, Naerling. I voted, too.
--SA
VJ Reddy 15-May-12 21:02pm    
Good answer. 5!
Sergey Alexandrovich Kryukov 15-May-12 21:57pm    
Thank you, VJ.
--SA
jonsey29847 16-May-12 8:38am    
I am using the debugger, I have been in debug mode with this code for about two weeks now. The application is running out in the field, so my assumption is that everything needed for the application is in the Studio project on the network under the job directories.

I need to validate a change, and my step one is to get the code to build, then proceed.

This site is very helpful, and I usually continue to work on an issue after posting, as is the case here. Its just the time constraint I have, that requires a multi-tiered approach.

Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900