Rico

Code Translation From C To Vb

Recommended Posts

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

'//BEGIN

Dim B(2) as Byte

Dim s as String

B(0) = 0

B(1) = 88

By(2) = 1

s = CRC16(B)

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

// BEGIN

unsigned short CRC(unsigned char *s, int len, unsigned

short 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

Share this post


Link to post
Share on other sites

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 vb

http://www.vbaccelerator.com/home/vb/Code/...C32/article.asp

sorry if someone could explain the math it would be easyier

Share this post


Link to post
Share on other sites
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 by jcl

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...