Hex Pair counting
From: Khurram (scorpio05678_at_homail.com)
Date: 03/30/04
- Next message: Rick Rothstein: "Re: Find out where the function was called from"
- Previous message: Jan Hyde: "Re: flexgrid"
- Next in thread: Mike D Sutton _at_ Work: "Re: Hex Pair counting"
- Reply: Mike D Sutton _at_ Work: "Re: Hex Pair counting"
- Reply: Larry Serflaten: "Re: Hex Pair counting"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Rick Rothstein: "Re: Find out where the function was called from"
- Previous message: Jan Hyde: "Re: flexgrid"
- Next in thread: Mike D Sutton _at_ Work: "Re: Hex Pair counting"
- Reply: Mike D Sutton _at_ Work: "Re: Hex Pair counting"
- Reply: Larry Serflaten: "Re: Hex Pair counting"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|