Sorry about that. The book wasn't precise enough. You can treat My.Computer.Ports.SerialPortNames sort of like an array as in:
Debug.WriteLine(My.Computer.Ports.SerialPortNames( 1))
But as you discovered it's really a collection. A Read-only collection in fact.
VB 2005 has gone a bit overboard with read-only collections. Generally the distinction doesn't matter and you can do things like loop through the items and see what they are but you can't modify the collection (add or remove items) and as you found you can't assign the whole thing to a string array.
> What am I missing about using
VB 2005 that would lead me to
> know the correct answer in the first place? Would the
> "Object Viewer" (which I have not used yet) have helped me
> understand this, when Intellisense did not seen to help?
There are a couple of tricks. The ObjectViewer can help. I don't like the interface nearly as much as the
VB 6 version but it's got more data in it.
IntelliSense can sometimes help. If you can get IntelliSense to appear, it often can give you a little description and data a type for a property, return types for functions, parameter types and descriptions, etc.
Finally there's the online help. It doesn't always say much more than IntelliSense but it's worth a try.
> Is the SerialPort "class", that you talk about in the remainder
> of this section of Appendix P, starting with 3rd paragraph,
> actually unrelated to the My.Computer.Ports namespace?
They are related. I think My.Computer.Ports.SerialPortNames is basically a shortcut to using the SerialPorts class's GetPortNames method. Remember that the My namespaces don't really add anything new, they're just shortcuts to features that are available elsewhere.
> Is it, perhaps, the SerialPort objects you can add to your
> form from the ToolBox under Components?
Yes. Also keep in mind that all components and controls are classes so you can create them at run time, too. You don't always have to add one to the form at design time, although that's often convenient.
> What is the
VB 2005 equivalent of such Socket devices?
Unfortunately I've done very little of this so I don't have any good examples on my site.x
Here's "An Introduction to the .Net Socket Class" that includes some examples:
http://www.vbcity.com/forums/faq.asp?fid=15&cat=Winsock
Here's an article called "
VB.NET TCP Client - Server Socket Communications:"
http://www.eggheadcafe.com/articles/20020323.asp
I hope that helps!
Rod
[email protected]
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm