Hi all,
I am not familiar with C# at all and in fact only familiar with VBA. I am trying to translate a C# function into VBA so i can use it. The high level function purpose is
and the function as
my question is if a simple string was fed to this function with no footer i.e TEST22 would the function be testing each letter to generate the Checksum value as i dont understand what it means by : Break each record into four byte (character) sections
Apology if the nature of the question is a stupid one. But any simple explanation of what its doing would be much appreciated.
Regards
Tony
I am not familiar with C# at all and in fact only familiar with VBA. I am trying to translate a C# function into VBA so i can use it. The high level function purpose is
- Init result variable to 0
- consider each record in turn (including header, but excluding footer)
- Break each record into four byte (character) sections (excluding the end of the line character), padded with nulls if required, and exclusive OR (XOR) them into the result variable
C#:
num_chars = strlen (record_buffer)
FOR (i = 0;i < num_chars;i++)
value = 0
FOR (j = 0; j < 4; i++, j++)
IF i < num_chars
value = ((value << 8 ) + record_buffer[i])
ELSE
value = value << 8
END IF
ENDFOR
result = result XOR value
ENDFOR
C#:
var result = 0;
var num_chars = record_buffer.Length;
for (int i = 0; i < num_chars;i++)
{
var value = 0;
for (int j = 0; j < 4;i++, j++)
{
if (i < num_chars)
value = ((value << 8) + record_buffer[i]);
else
value = value << 8;
}
result = result ^ value;
}
Apology if the nature of the question is a stupid one. But any simple explanation of what its doing would be much appreciated.
Regards
Tony
Last edited by a moderator: