Hex Pair counting

From: Khurram (scorpio05678_at_homail.com)
Date: 03/30/04


Date: Tue, 30 Mar 2004 08:09:59 +0000 (UTC)

hi guys
HI

I am writing an app which sends message to server/client and display them in
the rich text box. All the messages send and recieved are displyed in Hex .
Each line should display 16 hex pairs (0 to 15) with their starting and end
index(in 4 digit hex).

EG
********************
Text: "This is a test for displaying index in decimal and it appears to be
working"

Hex:
0000-0015 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 66
0016-0031 6F 72 20 64 69 73 70 6C 61 79 69 6E 67 20 69 6E
0032-0047 64 65 78 20 69 6E 20 64 65 63 69 6D 61 6C 20 61
0048-0063 6E 64 20 69 74 20 61 70 70 65 61 72 73 20 74 6F
0064-0073 20 62 65 20 77 6F 72 6B 69 6E 67

**********************

I have tried to do it but it doesn't work properly and below is the
code.(some times it displays 2 less on the last line and sometime not and
also on boundary condition (i.e. when there are 17 hex pair) first line is
ok (0000-000F) but on 2nd line it displays 0010-0011 instead of 0010-0010

This method takes a line of hex and chop it into line of 16 hex pair(32
chars) and 16 spaces(i.e. allowedHexLength = 48 ) and store it into temprory
UDT. Then calculate the starting and ending Index and store at appropriate
place in Array of UDT. I have used "hexBytes" to count the number of pair on
1 line when length of line is less then 48 so that i can add it to find the
ending index for that line.

I need to store all this info in Array of UDT for my other method to just
display it on the screen when and if needed.

******************************
   Private Type hexMessages
         hexLine As String
        startIndex As String
        endIndex As String
    End Type

    Private hexMessageArray() As hexMessages

    Dim thisLength As Integer
    Dim thisIndex As Double
    Dim thisStartIndex As Integer
    Dim thisEndIndex As Integer

    'calculate the length of line
    thisLength = Len(thisHexLine)
    'create appropriate size buffer for each line(Array of UDT)
    If thisLength > allowedHexLength Then
       ReDim hexMessageArray(thisLength \ allowedHexLength)
    Else
        ReDim hexMessageArray(0)
    End If
    'start putting the maximum allowed hex line in the buffer
    For thisIndex = LBound(hexMessageArray) To UBound(hexMessageArray)
        For intPlace = 1 To allowedHexLength
            strChar = Mid$(thisHexLine, intPlace, 1) 'Get 1 chars at a time
            If strChar = "" Then 'means end of line
                hexBytes = hexBytes + 2
                Exit For
            End If
            If strChar = " " Then ' means 1 pair is done ,increase the pair
counter and also add space
                hexMessageArray(thisIndex).hexLine =
hexMessageArray(thisIndex).hexLine + " "
                hexBytes = hexBytes + 1
            Else
                hexMessageArray(thisIndex).hexLine =
hexMessageArray(thisIndex).hexLine + strChar 'Add it to the current word
            End If
        Next
       'calculate the starting and ending index
       If thisIndex = 0 Then ' for 1st loop only coz starting it from 0
            hexMessageArray(thisIndex).startIndex = "0"
            hexMessageArray(thisIndex).endIndex =
Val((hexMessageArray(thisIndex).startIndex) + (hexBytes - 1))
        Else
            hexMessageArray(thisIndex).startIndex =
Val((hexMessageArray(thisIndex - 1).endIndex) + 1)
            hexMessageArray(thisIndex).endIndex =
Val((hexMessageArray(thisIndex).startIndex) + (hexBytes - 1))
        End If
Next

can any one help me on above

cheers
SC



Relevant Pages

  • Re: Hex Display Subcircuit
    ... LED display that I'm using is high efficiency -- it runs 16mcd@10mA -- so ... using a 16-key keypad. ... (This circuit started out using a 16F872, ... Unfortunately, I need a *hex* display, and none of these ...
    (sci.electronics.design)
  • Re: cant get ce to run with a flat panel display.
    ... Currently I have the display outputting to the VGA but I ... I see the following registry settings relating to the LCD. ... Hex - 0 ... be one that enables CRT, LCD or both LCD and CRT. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: lab help
    ... display '. ... it is best to use XOR instead of mov. ... BCD numbers are already coded in hex. ...
    (comp.lang.asm.x86)
  • Re: Get Statement Not Retrieving Record Correctly
    ... ascii file. ... missing "2" and the record seems to display as a character longer than ... Viewing the data file in a Hex editor for the values in question "1/2" ...
    (microsoft.public.vb.general.discussion)
  • Re: Hex Pair counting
    ... All the messages send and recieved are displyed in Hex. ... I would suggest you delay breaking up the data until you need to display it. ... Dim Text As String ...
    (microsoft.public.vb.general.discussion)

Quantcast