By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Converting UInt16 to Int16

P: n/a
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_ConfigMa nagerErrorCode()
in V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
190

Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Use System.Convert.ToInt16()

"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:eM**************@TK2MSFTNGP14.phx.gbl...
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_ConfigMa nagerErrorCode()
in V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
190

Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #2

P: n/a
Use System.Convert.ToInt16()

"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:eM**************@TK2MSFTNGP14.phx.gbl...
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_ConfigMa nagerErrorCode()
in V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
190

Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

P: n/a
Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4

P: n/a
Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.