|
-
Jan 15th, 2013, 11:57 AM
#1
[RESOLVED] Integer cannot be converted to UShort
I have this piece of code in C#:
vb.net Code:
return ((UInt16)(((0xFF00 & input) >> 8) | ((0x00FF & input) << 8)));
Here is the VB code:
vb.net Code:
Return DirectCast(((&HFF00 And input) >> 8) Or ((&H00FF And input) << 8), UInt16)
But the VB code is throwing the following error:
Value of type 'Integer' cannot be converted to 'UShort'.
Any ideas why I am getting it ? I was stumped because the C# code is not throwing that error!
Thanks in advance
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jan 15th, 2013, 12:06 PM
#2
Re: Integer cannot be converted to UShort
Try this:
Code:
Return Convert.ToUInt16(((&HFF00 And input) >> 8) Or ((&HFF And input) << 8))
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Jan 15th, 2013, 12:09 PM
#3
Re: Integer cannot be converted to UShort
Use CType instead of DirectCast and all your problems will disappear!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 15th, 2013, 12:09 PM
#4
Re: Integer cannot be converted to UShort
Thanks 
Both solutions seems to be working
Last edited by akhileshbc; Jan 15th, 2013 at 12:11 PM.
Reason: dunfiddin's solution was also tested
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|