1.Compute CRC32 checksum, write a quick piece of code that accepts the packet of data and returns the CRC.
2.How do you use the Mouse OFF event

Dani AI

Generated

Short, practical answers for (building on ’s pointer that low‑level APIs are an option).

CRC32 (VB.NET — compact, ready to use)
This is a small, self-contained CRC32 implementation that builds the 256-entry table once and returns the 32‑bit checksum. Use a consistent encoding when turning strings into bytes (UTF8 or ASCII) so results match other tools.

Public Class CRC32
    Private Shared ReadOnly Table As UInteger() = InitializeTable()

    Private Shared Function InitializeTable() As UInteger()
        Dim tbl(255) As UInteger
        Dim poly As UInteger = &HEDB88320UI
        For i As Integer = 0 To 255
            Dim crc As UInteger = CUInt(i)
            For j As Integer = 0 To 7
                If (crc And 1) <> 0 Then
                    crc = (crc >> 1) Xor poly
                Else
                    crc >>= 1
                End If
            Next
            tbl(i) = crc
        Next
        Return tbl
    End Function

    Public Shared Function Compute(bytes() As Byte) As UInteger
        Dim crc As UInteger = &HFFFFFFFFUI
        For Each b As Byte In bytes
            Dim idx As Integer = CInt((crc And &HFFUI) Xor CUInt(b))
            crc = (crc >> 8) Xor Table(idx)
        Next
        Return Not crc
    End Function
End Class

Usage example: Dim h As UInteger = CRC32.Compute(System.Text.Encoding.UTF8.GetBytes("hello")) — display as hex with h.ToString("X8").

Mouse "off" event

  • In modern VB.NET WinForms the built-in MouseLeave / MouseEnter events exist. Note child controls often steal mouse events, so for a reliable “mouse is anywhere on the form” test use ClientRectangle.Contains(PointToClient(Cursor.Position)), or install an IMessageFilter to watch mouse messages at the application level and detect when the cursor leaves the form area.
  • In classic VB6 there isn’t a simple managed “MouseOff” event either. A robust approach is to request a WM_MOUSELEAVE notification (via TrackMouseEvent) and handle WM_MOUSELEAVE in a subclassed window procedure. Subclassing in VB6 is powerful but must be done carefully (or via a well‑tested helper library) to avoid crashes; if subclassing isn’t an option, a short timer + client‑area check is a safe fallback.

Troubleshooting notes

  • Always pick one byte encoding for CRC input and stick with it across tools.
  • When showing CRC32 to users, present it as 8 hex digits (X8) to avoid signed/unsigned confusion.

Recommended Answers

All 3 Replies

I need a little more information than that! Mouse Off? Like, when the mouse leaves the form?

I need a little more information than that! Mouse Off? Like, when the mouse leaves the form?

Even i dint get this meaning.I got this question when i was searching for vb interview question.
I got almost all the answers except these 2 . so i thought i may get answers from daniweb and i kept in forum.

Thax for ur reply
regards
Roopa raj

Unless VB.Net has a mouse off event (which it might, I don't know), The answer is "there isn't one". I know VB6 doesn't have one. The only way to find out if the mouse has gone off the form is to use an api call. You need to use the getcursorpos api, and pass it the POINTAPI Type. This will effectively give you the current X Y coordinates of the mouse.
Then, you get the current X, Y coordinates of your form (maybe using getwindowrect, with type RECT), and then compare to see if the mouse falls within those boundaries. If it is within those boundaries, the mouse is on the form. If it's not, then it isn't. So you could use a timer control, and check every millisecond where the mouse is. As long as it's on your form, set a variable to true. When it leaves your form, set it false, and execute some kind of "off form" code. Another option, is to set a global hook on the mouse, and whenever you recieve a WM_MOUSEMOVE, check it's coordinates, compare, and execute.

As for the checksum, I found This neat information:
http://www.vbaccelerator.com/home/VB/Code/Libraries/CRC32/article.asp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.