Rico Posted May 12, 2006 Report Share Posted May 12, 2006 I am attempting to recreate a bit of C code into VB code however it is not cooperating. I have sample input and output of what the results should be in C lanugage but I have been unable to make a function in VB6 which will emulate the action. Simply put, I need to create a 16 bit CRC CCITT check that will produce the following...'// The following code is what I intend to accomplish (but have been unable to) in VB6 with actual inputs and actual results'//BEGINDim B(2) as ByteDim s as StringB(0) = 0B(1) = 88By(2) = 1s = CRC16(s = "47EB"'//END'// The following code is what I have been provided with in C language, supposedly it is the code that is'// used to produce the above information// BEGINunsigned short CRC(unsigned char *s, int len, unsignedshort crcv){register unsigned c,q;for (; len; len--){c = *s++;q = (crcv ^ c) & 017;crcv = (crcv >> 4) ^ (q * 010201);q = (crcv ^ (c >> 4)) & 017;crcv = (crcv >> 4) ^ (q * 010201);}return (crcv);}//END '// So far I have been unable to get any translated code to work in VB6, I always get overflows. I am not skilled with C languages unfortuantly.'// Any help would be greatly appreciated Quote Link to post Share on other sites
iccaros Posted May 16, 2006 Report Share Posted May 16, 2006 wow I don't even have a clueas to what that does.. can you explain it.. and why who ever wrote it is really dumb as things like q,c and s are horrable vairable names.. here are some examples of a crc check in vbhttp://www.vbaccelerator.com/home/vb/Code/...C32/article.aspsorry if someone could explain the math it would be easyier Quote Link to post Share on other sites
jcl Posted May 16, 2006 Report Share Posted May 16, 2006 (edited) and why who ever wrote it is really dumb as things like q,c and s are horrable vairable names..Eh. It follows the standard C naming convention: short, no complete words, no vowels. c and s are reasonable (if incorrect) and I can't think of a more meaningful name for q. Edited May 16, 2006 by jcl Quote Link to post Share on other sites
iccaros Posted May 16, 2006 Report Share Posted May 16, 2006 hmmm, so your saying its standard to write unreadable or hard to read code?? at lest comment the code so normal humans can read it. or least so I can understand the math... but thats just my openion.. and that all its worth. Quote Link to post Share on other sites
jcl Posted May 17, 2006 Report Share Posted May 17, 2006 hmmm, so your saying its standard to write unreadable or hard to read code??I was sort of kidding. It's not unusual for C to be optimized for terseness. Single letter variables aren't unusual if the meaning is fairly clear or if they don't have any real meaning. 'c' and 's' are examples of the former (meaning character and string, respectively) and 'q' is a just a bucket for intermediate values. 's' is incorrect in this case since the object is a char array rather than a string and 'c' is borderline but I didn't have any trouble understanding what was intended.I might have used 'bytes' and 'byte' or 'octets' and 'octet' or something similar instead of 's' and 'c'. 'q' probably would have ended up being a meaningless name.It would be nice if the C example was commented. At least a note indicating what the function is supposed to do. But it really doesn't matter if all he has to do is translate it into VB. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.