473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Converting UInt16 to Int16

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
4 6124
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: boki | last post by:
Dear All, I knew "&apple" could get the address of apple variable, about why we use a (UINT16 *) command before "&apple" ? What is this function for? Thank you very much for your help.
1
by: MuZZy | last post by:
HI, I would really appreciate some hwlp with this: Here is the WinAPI struct used in call to winapi function wavInGetDevCaps: typedef struct { WORD wMid; WORD wPid; MMVERSION...
7
by: djc | last post by:
I have typically always used one of the VB CType functions (not CType itself but CInt, CString, etc...) to cast/convert an input value to its proper type before passing it as a parameter to a SQL...
5
by: Sakharam Phapale | last post by:
Hi All, I am using Microsoft Speech DLL "sapi.dll". I want to use following method of "SpeechLib.SpStream" object (following is a signature which I copied from Quick Info feature of .NET code...
0
by: Mark Hollander | last post by:
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,...
3
by: Sharon | last post by:
There is an built-in types table for .NET framework type to C# type which are aliases of predefined types in the System namespace (http://msdn2.microsoft.com/en-US/library/ya5y69ds.aspx). How...
5
by: vtjumper | last post by:
I'm building a C# interface to an existing messaging system. The messaging system allows values of several types to be sent/recieved over the interface. What I want to do is use a generic...
5
by: Lint Radley | last post by:
Hello, I am looking for a way to cast a byte to Int16. I get this error: "Unable to cast object of type 'System.Byte' to type 'System.Int16'" If you're curious, I am using a library for...
12
by: cmdolcet69 | last post by:
Can anyone give me some ideas on how to convert the following program to vb 2003? I would like to jsut take this code and implement it in vb. def.h /* Global Type Definitions */ typedef ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.