Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.