Syste.String[] problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Syste.String[] problem

mrodriguezcmrodriguezc Posts: 2Member
Hi all, Im really new with .NET, I tried to make a little program on VB. NET, Im really new with this, and I cant contionue because I cant convert the system.string[] into a normal string, Ihave this:

Dim management As ManagementClass = New Management.ManagementClass("Win32_NetworkAdapterConfiguration")
Dim colNicConfig As ManagementObjectCollection = management.GetInstances()

Dim txtDireccionIP() As String
For Each mgr As ManagementObject In management.GetInstances()
If mgr.Item("IPEnabled") Then
txtDireccionIP = mgr.Item("IPAddress").ToString.Split(",")
Exit For
End If

Next

but txtDireccionIP variable just show system.string[], why? because is an array?, I tried split it, get elements with a for each but nothing, what Im missing?

I just found the element IPEnabled as:
IPAddress
Data type: string array
Access type: Read-only

Array of all of the IP addresses associated with the current network adapter.

Example: "172.16.22.0"

but then how can I get the real value??

or pls where can I get more information??, I found a routine that makes almost the same, but it was written on C# and of course I want to do it by myself.

Thanks everyone...


Mauricio Rdgz
newbie


Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    Remove the parenthesis in red ...

    [code]
    Dim management As ManagementClass = New Management.ManagementClass("Win32_NetworkAdapterConfiguration")
    Dim colNicConfig As ManagementObjectCollection = management.GetInstances()

    Dim txtDireccionIP[red]()[/red] As String
    For Each mgr As ManagementObject In management.GetInstances()
    If mgr.Item("IPEnabled") Then
    txtDireccionIP = mgr.Item("IPAddress").ToString.Split(",")
    Exit For
    End If
    Next
    [/code]

    Basically, when you define a variable name followed by parenthesis like so ...

    [code]
    Dim x() As Integer
    [/code]

    You are defining an empty array ... in the case of x() you are creating an empty array of integers NOT an integer ...
  • mrodriguezcmrodriguezc Posts: 2Member
    Thanks iwilldoit, I solve by doing this:

    direccionIP.Text = CType(mgr.Item("IPAddress")(0), String)

    didnt create a variable, and took the array element from the item directly and later convert to a string.

    Thanks for your help!


    : Remove the parenthesis in red ...
    :
    : [code]
    : Dim management As ManagementClass = New Management.ManagementClass("Win32_NetworkAdapterConfiguration")
    : Dim colNicConfig As ManagementObjectCollection = management.GetInstances()
    :
    : Dim txtDireccionIP[red]()[/red] As String
    : For Each mgr As ManagementObject In management.GetInstances()
    : If mgr.Item("IPEnabled") Then
    : txtDireccionIP = mgr.Item("IPAddress").ToString.Split(",")
    : Exit For
    : End If
    : Next
    : [/code]
    :
    : Basically, when you define a variable name followed by parenthesis like so ...
    :
    : [code]
    : Dim x() As Integer
    : [/code]
    :
    : You are defining an empty array ... in the case of x() you are creating an empty array of integers NOT an integer ...
    :

  • iwilld0itiwilld0it Posts: 1,134Member
    Now that I am looking at this code again, you can do it like so ... at least it should work ...

    [code]
    Dim management As ManagementClass = New Management.ManagementClass("Win32_NetworkAdapterConfiguration")
    Dim colNicConfig As ManagementObjectCollection = management.GetInstances()

    Dim txtDireccionIP() As String
    For Each mgr As ManagementObject In management.GetInstances()
    If mgr.Item("IPEnabled") Then
    txtDireccionIP = [red]CType(mgr.Item("IPAddress"), String())[/red]
    Exit For
    End If

    Next
    [/code]
Sign In or Register to comment.