Link to home
Start Free TrialLog in
Avatar of koossa
koossa

asked on

C# to VB.net

How would I do this in VB.net

strTemp.Format( _T("%02X%02X%02X"), arrData[ 5 ] & 0xFF, arrData[ 6 ] & 0xFF, arrData[ 7 ] & 0xFF);

Open in new window

Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Avatar of koossa
koossa

ASKER

I have tried that, it does not work correctly
Avatar of Nalin Kumar Balaji Shanmugam
Check here. http://converter.telerik.com/
Some times you have to try some options to make the code without syntax error. This will help you somewhat( Reduce the typing of Vb.net)
What is the need of this code... What you are trying to do? May i know the situation.
Avatar of koossa

ASKER

When converting it, the vb.net does not understand the _T in the code.
I don't know what this code do, but there are 3 bytes and it convert it to a serial number with this code.  I have that 3 bytes in vb.net and I also want to get the serial number.
A couple of points.
Your original code is NOT in C#, it is in fact C++, unmanaged code using an MFC specific macro - the _T thingy.
What the _T macro does is convert a string literal to UNICODE when that is defined in the project and convert it to ASCII when unicode is not a project setting.

As .net (VB and C#) all use unicode then the solution is simple.  Just delete the _T( and the closing ) from the code.
Avatar of koossa

ASKER

Thank you Andy

Can you show me the vb.net code?
>>When converting it, the vb.net does not understand the _T in the code.

As I said, just delete the _T and the braces () that went with it from your vb.net code.

eg
_T("%02X%02X%02X")
becomes
"%02X%02X%02X"
Avatar of koossa

ASKER

Ok, that is what I did, but it does not work, the strTemp is empty

strTemp.Format("%02X%02X%02X", arrData(5) & &HFF, arrData(6) & &HFF, arrData(7) & &HFF)

Open in new window

Avatar of koossa

ASKER

arrData(5) = 112
arrData(6) = 55
arrData(7) = 97

Then it is suppose to return a 7 digit serial number
Have you followed the advice of the other experts re the formatting ?  (I assume that is what the links refer to - I'm more for C++, C# code)
Avatar of koossa

ASKER

Hi Andy, as far as I can see the other posts is only links to C# to Vb.net converters, I don't see the formatting that you are talking about?
s = s.Format("{0:X2}{1:X2}{2:X2}", 1, 2, 3)
this gives "010203"
Avatar of koossa

ASKER

No, I don't think that is the same as the C++ code
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland 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
Avatar of koossa

ASKER

Thank you for your patience!