
12-17-2001, 08:30 PM
|
|
Senior Contributor
* Guru *
|
|
Join Date: Mar 2000
Location: Christchurch, New Zealand
Posts: 470
|
|
Re: comprestion or Bit information please
|
This may help you out:
<pre><font color=blue>Private Sub</font color=blue> Command1_Click()
<font color=blue>Dim</font color=blue> hFile <font color=blue>As Long</font color=blue>
<font color=blue>Dim</font color=blue> bytData() <font color=blue>As Byte</font color=blue>
<font color=blue>Dim</font color=blue> strDisplay <font color=blue>As String</font color=blue>, strFileName <font color=blue>As String</font color=blue>
<font color=blue>Dim</font color=blue> lngBit <font color=blue>As Long</font color=blue>
<font color=blue>Dim</font color=blue> lngIndex <font color=blue>As Long</font color=blue>
<font color=blue>Dim</font color=blue> lngBitVal(0 <font color=blue>To</font color=blue> 7) <font color=blue>As Long</font color=blue>
<font color=green>' ** NOTE: ENTER YOUR FILE NAME HERE **</font color=green>
strFileName = "E:\Temp\error.log"
<font color=green>' Get a free handle to use to connect to a file</font color=green>
hFile = FreeFile
<font color=green>' Open the file in binary mode so we can read in the bytes</font color=green>
<font color=blue>Open</font color=blue> strFileName <font color=blue>For Binary</font color=blue> <font color=blue>As</font color=blue> #hFile
<font color=green>' Make the buffer big enough to read all the file and read it</font color=green>
<font color=blue>ReDim</font color=blue> bytData(1 <font color=blue>To</font color=blue> LOF(hFile) )
<font color=blue>Get</font color=blue> hFile, , bytData
<font color=blue>Close</font color=blue> hFile
<font color=green>' Build a string from the byte array so we can display it</font color=green>
strDisplay = StrConv(bytData, vbUnicode)
MsgBox strDisplay, vbInformation
<font color=green>'---------------------------------------------------------</font color=green>
<font color=green>' Now convert the first three chars to bit representations</font color=green>
<font color=green>' (This is to demonstrate how to get the bits out) </font color=green>
<font color=green>'---------------------------------------------------------</font color=green>
<font color=green>' First set up the bit vals array</font color=green>
lngBitVal(0) = 1
lngBitVal(1) = 2
lngBitVal(2) = 4
lngBitVal(3) = 8
lngBitVal(4) = 16
lngBitVal(5) = 32
lngBitVal(6) = 64
lngBitVal(7) = 128
<font color=green>' Now build a display of the first three chars from the file</font color=green>
strDisplay = ""
<font color=blue>For</font color=blue> lngIndex = 1 <font color=blue>To</font color=blue> 3
<font color=green>' Show the actual character in quotes</font color=green>
strDisplay = strDisplay & _
Chr$(34) & Chr$(bytData(lngIndex) ) & Chr$(34) & _
vbTab & " "
<font color=green>' Perform a bitwise calculation on the current byte</font color=green>
<font color=green>' and build a binary string representation</font color=green>
<font color=blue>For</font color=blue> lngBit = 7 <font color=blue>To</font color=blue> 0 Step -1
strDisplay = strDisplay & Abs(<font color=blue>CBool</font color=blue>(bytData(lngIndex) <font color=blue>And</font color=blue> lngBitVal(lngBit) ) )
<font color=blue>Next</font color=blue> lngBit
strDisplay = strDisplay & vbNewLine
<font color=blue>Next</font color=blue> lngIndex
<font color=green>' Display the results</font color=green>
strDisplay = "Binary representation of first 3 chars" & _
vbNewLine & _
strDisplay
MsgBox strDisplay, vbInformation
<font color=blue>End Sub</font color=blue>
</pre>
|
|