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

Visual Basic.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
koossa

8/22/2022 - Mon
John (Yiannis) Toutountzoglou

koossa

ASKER
I have tried that, it does not work correctly
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)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Nalin Kumar Balaji Shanmugam

What is the need of this code... What you are trying to do? May i know the situation.
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.
AndyAinscow

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
koossa

ASKER
Thank you Andy

Can you show me the vb.net code?
AndyAinscow

>>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"
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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
koossa

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

Then it is suppose to return a 7 digit serial number
AndyAinscow

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)
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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
AndyAinscow

s = s.Format("{0:X2}{1:X2}{2:X2}", 1, 2, 3)
this gives "010203"
koossa

ASKER
No, I don't think that is the same as the C++ code
ASKER CERTIFIED SOLUTION
AndyAinscow

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ess Kay

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
koossa

ASKER
Thank you for your patience!