Jaurès Ulm Jaurès Ulm - 2 months ago 5x
Vb.net Question

Early binding against late binding

I just turned on the such option strict and discovered issues I wasn't use to deal with such as late binding. Indeed the following lines create a late binding error

Dim available_ports As Array
available_ports = SerialPort.GetPortNames()
If available_ports(0).ToString <> "" Then...

I know that an object is early bound when it is assigned to a variable declared to be of a specific object type.

I have tried several ideas but wasn't able to deal with this error. How to early bound the last line of this code?

The most interresting thing I made was

Dim available_ports As String

The error on the last line disappeared but a new one appeared on the second line to tell me it was impossible to convert
String ()


This is because the method GetPortNames() returns a String Array. The class Array does not really match, and String is not an Array...

Dim available_ports As String()

should workd