Results 1 to 4 of 4

Thread: Please help convert code to VB

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    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;

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    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;

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    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

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    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;
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width