Suppose you have a huge table of numbers on DGV and you want to perform a sort of logical function on first cell to the end cell.
The goal
is to make a small hexadecimal code to compare two huge csv files or dgv tables are different or not. Very useful in electronics logic and microcontrollers programming. However CRCs are more reliable. I mean checksum is just summing right? Instead of their more complex xor polynomial functions. The possibility to have different files with similar checksum is extremely low.
Anyways,
The problem
is where a "string" cell comes in, unless [in total numeric cells] it works fine... Program_Flash of microcontrollers are full of ASCII and unicodes but checksums are automatically generated anyway.
What I've tried
1) I tried .GetHashCode method of the file itself (an object) and that was crazy. I'm still reading about it but I have no idea what is it. Too much bytes and file name (and probably mod/acc date affects hash code) If someone can describe a bit about it I would be delighted even more since it may be useful in further coding..
2) Is there another way (similar to checksum) to compare two files are same or not with a simpler built-in functions?
3) I came up with this approach for prior idea:
- I also tried System.Text classes but I'm not sure I'm doing it right cause I didn't find .ASCIIdecoder and even I'm not sure I should use ASCII or UTF8 or something else...Code:Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim CHECKSUM As Long = 0 'MAX SHOULD BE FFFF = 65535 For row = 0 To DataGridView1.RowCount - 1 For column = 0 To DataGridView1.ColumnCount - 1 CHECKSUM = CHECKSUM + CLng(DataGridView1.Item(column, row).Value) 'REQUIRES STRING-FRIENDLY CONVERSION Next Next End Sub
Update:Code:CHECKSUM = CHECKSUM + CLng(System.Text.ASCIIEncoding.ASCII(DataGridView1.Item(column, row).Value)
1) Conversion code is false and has syntax error. Pasted it just for record.
2) Error message on try/catch exception is: Invalid cast exception was unhandled: Conversion from string "TEKST" to type 'Long' is not valid.
Note:
1) I guess performing it on an array or a collection of variable could be better but I'm watching the gridview.
2) I found this kind of thread making way more effective to discrete it in separated paragraphs.




Reply With Quote
