Converting UInt16 to Int16

M

Mark Hollander

Hi,

Is there an easier way to convert a UInt16 to Int16 than the way I am
currently doing it

Dim iValue As Int16
Dim uValue As UInt16
Try
uValue = GetValue(WMI.NetworkAdapter, "Availability")
iValue = CType(uValue.ToString, Int16)
Catch ex As Exception
ErrorSystem.ErrMsg(ex)
iValue = -1
End Try
Return iValue

I have tried

Dim iValue As Int32
Try
iValue = CType(GetValue(WMI.NetworkAdapter, "InterfaceIndex"), Int32)
Catch ex As Exception
ErrorSystem.ErrMsg(ex)
iValue = -1
End Try
Return iValue

but get the following exception

System.InvalidCastException: Cast from type 'UInt32' to type 'Integer'
is not valid.
at
Microsoft.VisualBasic.CompilerServices.IntegerType.FromObject(Object
Value)
at Assimilator.SDK.Network.NICProperties.get_ConfigManagerErrorCode()
in V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
190



Thank You
Mark Hollander
 
S

Shiva

Use System.Convert.ToInt16()

Hi,

Is there an easier way to convert a UInt16 to Int16 than the way I am
currently doing it

Dim iValue As Int16
Dim uValue As UInt16
Try
uValue = GetValue(WMI.NetworkAdapter, "Availability")
iValue = CType(uValue.ToString, Int16)
Catch ex As Exception
ErrorSystem.ErrMsg(ex)
iValue = -1
End Try
Return iValue

I have tried

Dim iValue As Int32
Try
iValue = CType(GetValue(WMI.NetworkAdapter, "InterfaceIndex"), Int32)
Catch ex As Exception
ErrorSystem.ErrMsg(ex)
iValue = -1
End Try
Return iValue

but get the following exception

System.InvalidCastException: Cast from type 'UInt32' to type 'Integer'
is not valid.
at
Microsoft.VisualBasic.CompilerServices.IntegerType.FromObject(Object
Value)
at Assimilator.SDK.Network.NICProperties.get_ConfigManagerErrorCode()
in V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
190



Thank You
Mark Hollander
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top