|
-
May 22nd, 2007, 11:08 AM
#1
Thread Starter
New Member
Please help convert code to VB
Im trying duplicate a program that sends a checksum at end of string, I got the code from original program in C, don't quite understand what they are doing, Im a VB programmer,, I know very little about C. here is the code.
// Convert to HEX and then
// take the last digits of our HEX value (should be two)
CString sCheckSum;
sCheckSum.Format(_T("%0*X"), iChecksumLength, iCheckSum);
if(sCheckSum.GetLength() > iChecksumLength)
{
sCheckSum = sCheckSum.Right(iChecksumLength);
}
return sCheckSum;
-
May 22nd, 2007, 12:21 PM
#2
Thread Starter
New Member
Re: Please help convert code to VB
Sorry, I forgot part of the code
CString sWork = sStringToCheck;
int iCheckSum = 0;
int iChecksumEndPos = sWork.GetLength();
for(int i = 0; i < iChecksumEndPos; i++)
{
CString sX = sWork[i];
iCheckSum += sWork[i];
}
// Convert to HEX and then
// take the last digits of our HEX value (should be two)
CString sCheckSum;
sCheckSum.Format(_T("%0*X"), iChecksumLength, iCheckSum);
if(sCheckSum.GetLength() > iChecksumLength)
{
sCheckSum = sCheckSum.Right(iChecksumLength);
}
return sCheckSum;
-
May 22nd, 2007, 03:10 PM
#3
Thread Starter
New Member
Re: Please help convert code to VB
I notice allot of people are viewing but no replys,, I really dont need the conversion,, if somebody could just tell me what it is doing that would be great,, Just trying to figure out how they are calculating the checksum, I think they are adding all the hex values then converting to ascii to get checksum (LRC), but I must be missing something in this code.
Thanks allot
-
May 22nd, 2007, 03:53 PM
#4
Re: Please help convert code to VB
i don't use c# but from what i know of c, it looks like it is calling an object called checksum. but here's what it looks like at the start.
CString sWork = sStringToCheck;
dim iChecksum as Ineger
dim sChecksum$
iCheckSum = 0
dim iChecksumEndPos as integer
iChecksumEndPos = len(sWork)
for i = 0 to ichecksumendpos
sx = CStr(sWork(i) 'don't know why this line is here
iCheckSum = ichecksum + sWork(i)
next i
' Convert to HEX and then
' take the last digits of our HEX value (should be two)
sCheckSum = cstr(ichecksum)
i didn't mess with the rest below here but basically it is taking every byte in the array and adding them to themselves and taking just the last byte of the value and generating the checksum from that.
CheckSum =Format(schecksum, "&H"+*X"), iChecksumLength, iCheckSum);
if(sCheckSum.GetLength() > iChecksumLength)
{
sCheckSum = sCheckSum.Right(iChecksumLength);
}
return sCheckSum;
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
|