Click here to Skip to main content
15,905,785 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHELP PLEASE. BASIC EXCEL TASKS Pin
frankiebaby227-Jul-07 6:07
frankiebaby227-Jul-07 6:07 
AnswerRe: HELP PLEASE. BASIC EXCEL TASKS Pin
frankiebaby227-Jul-07 8:57
frankiebaby227-Jul-07 8:57 
Questionprint the richtextbox text Pin
eyes200727-Jul-07 5:03
eyes200727-Jul-07 5:03 
AnswerRe: print the richtextbox text Pin
Paul Conrad29-Jul-07 6:16
professionalPaul Conrad29-Jul-07 6:16 
QuestionCRC 16 Pin
Cory Kimble27-Jul-07 3:46
Cory Kimble27-Jul-07 3:46 
AnswerRe: CRC 16 Pin
kubben27-Jul-07 5:24
kubben27-Jul-07 5:24 
GeneralRe: CRC 16 Pin
Cory Kimble27-Jul-07 6:43
Cory Kimble27-Jul-07 6:43 
GeneralRe: CRC 16 Pin
Luc Pattyn27-Jul-07 13:32
sitebuilderLuc Pattyn27-Jul-07 13:32 
Hi,

I know C#, can read VB but dont speak it, and have done many CRCs
over the years.

There are thousands of CRC definitions; they vary in width, rotational
direction, polynomial value, and other details.

You will typically find two ways of implementing a CRC:
- the one you have, which is adding one item (a byte here) at a time by
iterating over its bits (that's the for loop inside); basically it says:
test the highest bit (that's H8000), if set rotate it back in at the
low end, not with value one, but with the selected polynomial value
(here H1021)
- the other standard implementation is by table lookup, where the for loop
is replaced by something that in the end does exactly the same, based
on a precalculated table (256 entries for a byte method). This way is
some ten times faster at the expense of higher complexity. Dont bother
for now.

Anyway, in the code at hand, clearly crc is a class member that needs to
be initialized once (depending
on the specific CRC that would most likely be to 0 or HFFFF), see C# code;
if no explicit initialization is present, it is an implicit zero, and
you can not reuse that class instance.

Then you feed all your data bytes to the method, one at a time, in the
intended order.

At the end, crc contains the CRC, except that for some CRC definitions
you may still have to invert it (i.e. exor with HFFFF).

The overflow occurs in one of the left shifts; the intention is to
ignore bits that "fall off"; when necessary they got noticed by the
overflow test (remember the H8000).

So either you see a way to turn them off in your code, or you must
modify your code to make sure they never happen.

I am not sure, it is likely though, that VB is defined such that
signed integers can cause overflow, and unsigned integers can not.
If so I suggest you declare both crc and nextone as unsigned.

Otherwise you must explicitly prevent overflow by first anding away
the most significant bit (and with H7FFF I guess), then do the shift left.

Some more comments:

1.
I dont see why you included nextone = Integer.Parse(dat)
I would expect nextone=dat to do exactly the same

2.
please publish code inside PRE tags, that will switch to a more
appropriate font and preserve indentation, making things easier to read.

3.
if starting from C# code it would have been wise to show that too.

One more advice:
as long as a single mistake is present in your code, the CRC will be wrong,
and so much so that you can not even start to guess what happened.
So my advice is make sure you have something else (an entire program on
your PC, on another machine, whatever) that does the same
thing correctly, and that you can feed any data you like; then
start with a single byte (try a couple of values, say H01, then H02, H04,
up to H80), and compare results from both implementations.
If not identical you must fix that first. Only then proceed to a two-byte
message (say H01 H80; or H02 H40; ...); and then a 9-byte message since
by then all integers have reached their 16-bit capacity and new bugs
]may pop up. If this also succeeds, you may be ready for real data of
arbitrary length.

Good luck with your CRC stuff.

Smile | :)


GeneralRe: CRC 16 Pin
Cory Kimble30-Jul-07 7:03
Cory Kimble30-Jul-07 7:03 
GeneralRe: CRC 16 Pin
Luc Pattyn30-Jul-07 7:21
sitebuilderLuc Pattyn30-Jul-07 7:21 
Questionremove Icon from Form Pin
Rupesh Kumar Swami27-Jul-07 2:37
Rupesh Kumar Swami27-Jul-07 2:37 
AnswerRe: remove Icon from Form Pin
Tom Deketelaere27-Jul-07 2:46
professionalTom Deketelaere27-Jul-07 2:46 
QuestionWhy does my TabPage not show? Pin
Steven J Jowett27-Jul-07 1:42
Steven J Jowett27-Jul-07 1:42 
AnswerRe: Why does my TabPage not show? Pin
kubben27-Jul-07 1:55
kubben27-Jul-07 1:55 
GeneralRe: Why does my TabPage not show? Pin
Steven J Jowett27-Jul-07 2:24
Steven J Jowett27-Jul-07 2:24 
Questionhow can use VScrollBar to Scroll a long page.... Pin
fmlove27-Jul-07 1:28
fmlove27-Jul-07 1:28 
Questionhow to get column in rich textbox and textbox ,when user is editing Pin
sourabhj27-Jul-07 1:12
sourabhj27-Jul-07 1:12 
QuestionObtaining Number Of Pages in Crystal Report Pin
KeithF27-Jul-07 1:00
KeithF27-Jul-07 1:00 
QuestionSelecting tabs on a tab control Pin
steve_rm27-Jul-07 0:33
steve_rm27-Jul-07 0:33 
AnswerRe: Selecting tabs on a tab control Pin
Tom Deketelaere27-Jul-07 1:04
professionalTom Deketelaere27-Jul-07 1:04 
AnswerRe: Selecting tabs on a tab control Pin
kubben27-Jul-07 2:03
kubben27-Jul-07 2:03 
GeneralRe: Selecting tabs on a tab control Pin
steve_rm27-Jul-07 2:47
steve_rm27-Jul-07 2:47 
GeneralRe: Selecting tabs on a tab control Pin
kubben27-Jul-07 2:49
kubben27-Jul-07 2:49 
Questionneed help for ruler Pin
eyes200726-Jul-07 23:49
eyes200726-Jul-07 23:49 
AnswerRe: need help for ruler Pin
Tom Deketelaere27-Jul-07 0:00
professionalTom Deketelaere27-Jul-07 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.