[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert a few lines of a C# formula to VB.Net

Posted on 2012-09-17
6
Medium Priority
?
976 Views
Last Modified: 2012-10-05
I have a line of code written in C# that I need to convert to Vb.Net.
All converters out there does not produce a result.

In C#

I have this block...

 // Calculate number of 64K blocks
      uint          rowsPerBlock = _MAXBLOCK/widthLength;
      uint          blockSize = rowsPerBlock*widthLength;
      uint          blockCount;
      ushort        length;
      uint          remainder=dcSize;

Open in new window


Later the length variable is assigned a value and used for other calculations

 length = (ushort)((remainder < blockSize) ? remainder : blockSize);
        
        if (length == remainder)
        {
          comp.WriteByte(0x01);
        }
        else
        {
          comp.WriteByte(0x00);
        }
        
        comp.Write(BitConverter.GetBytes(length), 0, 2);
        
        // Write one's compliment of LEN

Open in new window


All of the above I have converted, except the following line.

 
 comp.Write(BitConverter.GetBytes((ushort)~length), 0, 2);

Open in new window


What would be the correct conversion for this line?

Thanks
0
Comment
Question by:Sheritlw
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38406359
Try:

comp.Write(BitConverter.GetBytes(DirectCast(Not length, UShort), 0, 2)

Open in new window

0
 
LVL 8

Expert Comment

by:Crashman
ID: 38406405
0
 

Author Comment

by:Sheritlw
ID: 38406537
Unfortunately ... the code, comp.Write(BitConverter.GetBytes(DirectCast(Not length, UShort), 0, 2) did not work.  There is no GetBytes overload that accepts this number of arguments

And the developerfusion site I have used for years.  Unfortunately it has not worked correctly for a while.  I have tried other conversion tools, with no luck.

Any other ideas?

Thanks
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38406566
Sorry, I forgot a paren:

comp.Write(BitConverter.GetBytes(DirectCast(Not length, UShort)), 0, 2)

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 38406615
I now receive the following error.

Warning      5      Using DirectCast operator to cast a value-type to the same type is obsolete.      

Thanks
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38406647
Ok, so remove the DirectCast  = )

comp.Write(BitConverter.GetBytes(Not length), 0, 2)

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question