Link to home
Start Free TrialLog in
Avatar of Sheritlw
SheritlwFlag for United States of America

asked on

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

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

Try:

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

Open in new window

Avatar of Haver Ramirez
Haver Ramirez

Avatar of Sheritlw

ASKER

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
Sorry, I forgot a paren:

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

Open in new window

I now receive the following error.

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

Thanks
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial