Reading through ArrayList Objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have some code below that works, but I have to turn option strict off.
Basically I am allowing a user to change the IP of an Adapter. Since they may
have multiple adapters I read the Description and associated ServiceName from
the registry and then bind the arraylist to a combo box. I want to make sure
the adapter that has "MT" is selected by default. I always know the hardware,
since it is running XP embedded on a specific platform.

The line that is not correct is
enumNicServiceName.Current.Description.ToString. How do I make the
Description, which is a property of an object in the arraylist, safe or
strongly typed or what ever it needs to be.

Dim NICServiceName As ArrayList 'populated by a function in another
class not shown here
Dim enumNicServiceName As IEnumerator = NICServiceName.GetEnumerator()

'searches for both strings "M" and "T" and makes sure they are found
as "MT"
Do While enumNicServiceName.MoveNext
DefaultNic = enumNicServiceName.Current.Description.ToString
firstChar = InStr(DefaultNic, "M", CompareMethod.Text)
If firstChar > 0 Then
secondChar = InStr(firstChar, DefaultNic, "T",
CompareMethod.Binary)
If firstChar + 1 = secondChar Then
selectedNic = i
Exit Do
End If
End If
selectedNic = i

i += 1
Loop
 
Chrisg,

Basicly is this always very simple.
Set option string on.

Then you get a message that the casting is wrong. Object bla bla bla.

See than what Type is needed and type.

a = CType(myobject,TheTypeThatIsToldItHasToBe)

Mostly resolves that your problem. (This is not always the best way, however
we are than talking about futilities, which you can improve when you are
more used to it).

And when that does not work. Tell us than what Type that is told that it has
to be.

I hope this helps?

Cor
 
Back
Top