Click here to Skip to main content
16,005,552 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Usercontrol build problem Pin
Tom Deketelaere4-May-09 23:27
professionalTom Deketelaere4-May-09 23:27 
GeneralRe: Usercontrol build problem Pin
Johan Hakkesteegt5-May-09 0:11
Johan Hakkesteegt5-May-09 0:11 
GeneralRe: Usercontrol build problem Pin
Tom Deketelaere5-May-09 0:17
professionalTom Deketelaere5-May-09 0:17 
Questionscripting scheduled task Pin
TheScripter29-Apr-09 21:58
TheScripter29-Apr-09 21:58 
AnswerRe: scripting scheduled task Pin
Dave Kreskowiak30-Apr-09 13:20
mveDave Kreskowiak30-Apr-09 13:20 
QuestionVB6 - how to bitstream Pin
halsboss29-Apr-09 21:15
halsboss29-Apr-09 21:15 
AnswerRe: VB6 - how to bitstream Pin
Mycroft Holmes29-Apr-09 21:56
professionalMycroft Holmes29-Apr-09 21:56 
GeneralRe: VB6 - how to bitstream Pin
halsboss29-Apr-09 22:07
halsboss29-Apr-09 22:07 
Thanks, however did you actually read the post which stated an objective "but no .NET since an objective is to be able to run on .NET-free PCs" ? My only other choice is free Java with the netbeans IDE and I already have a VB6 framework in place...

You see how complex it can get just with just a couple of operations, from the code:
Option Explicit
Option Base 0
Option Compare Binary
Sub Main()
    ' Define and create an object for bitstream operations
    Dim BitStream As BitStreamVB6
    Set BitStream = New BitStreamVB6
    MsgBox "just created a new BitStreamVB6 object by Set variable BitStream "

    Dim b(0 To 3) As Byte
    Dim s As String
    Dim i32 As Long
    Dim i16 As Integer
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim l As Long
    Dim z As Long
    Dim lw As Long
    Dim stmp As String
    lw = &H80000000   ' 2^31 is the sign bit ?
    s = ""
    For z = 0 To 32
        s = s & " right(&H" & Hex(lw) & "," & z & ")=&H" & Hex(BitStream.i32_ShiftRight(lw, z)) & vbCrLf
    Next z
    MsgBox s
    lw = &H1&         ' 2^31 is the sign bit ?
    s = ""
    For z = 0 To 32
        s = s & " left(&H" & Hex(lw) & "," & z & ")=&H" & Hex(BitStream.i32_ShiftLeft(lw, z)) & vbCrLf
    Next z
    MsgBox s
End Sub

and the object BitStreamVB6
Option Explicit
Option Base 0
Option Compare Binary

' LITTLE-ENDIAN (x86 architecture) considerations :
' http://vbcity.com/forums/topic.asp?tid=7027
' text values                           D   C   B   A
' Bytes                                 3   2   1   0
' Integer Maths - Most significant bit 31           0 Least Significant Bit
' Appearance of string when printed (backward to storage as appears above)= A B C D
'
'ie bits         {31 30 29 28 27 26 25 24} | {23 22 21 20 19 18 17 16} | {15 14 13 12 11 10 09 08} | {07 06 05 04 03 02 01 00}
'   text values   ---------- D ----------     ---------- C ----------     ---------- B ----------     ---------- A ----------
'   byte number              3                           2                           1                           0
'
' However the sign bit causes OVERFLOW PROBLEMS in VB6 when masking and checking,
' so you have to check for it specifically and treat it separately
' eg the sign bit for LONG    it is bit 31 - base zero
'                 for INTEGER it is bit 15 - base zero
'                 for BYTE    it is bit 07 - base zero
'---------------------------------------------------------------------------------------------------
'
'byte   little-endian sequential bytes in the byte
' 0     07 06 05 04 03 02 01 00
' 1     15 14 13 12 11 10 09 08
' 2     23 22 21 20 19 18 17 16
' 3     31 30 29 28 27 26 25 24
'
' When bytes read from a file, they are byte 0,1,2,3,4,5,6...
'
' So, for an mpeg4 bitstream read from a file byte by byte,
' IS the starting bit at the LEFT or the RIGHT of each byte ?
' Need to check the C code of mpeg4modifier for the answer...
'
'---------------------------------------------------------------------------------------------------
'
' Little-endian based bit masks.
'
' To check a bit is set are return a boolean True or False, use
'   IsSet = (i32 AND i32_bit_31) = i32_bit_31 ' however in VB6 this returns a 16 byte integer FFFF=true 0000=false
' To check a bit is set are return a single bit in little-endian bit 0 (see above)
'   BitValue = IIf(((i32 And i32_bit_31) = i32_bit_31), i32_bit_00, 0)
'
Const i32_bit_00 As Long = &H1&
Const i32_bit_01 As Long = &H2&
Const i32_bit_02 As Long = &H4&
Const i32_bit_03 As Long = &H8&
Const i32_bit_04 As Long = &H10&
Const i32_bit_05 As Long = &H20&
Const i32_bit_06 As Long = &H40&
Const i32_bit_07 As Long = &H80&
Const i32_bit_08 As Long = &H100&
Const i32_bit_09 As Long = &H200&
Const i32_bit_10 As Long = &H400&
Const i32_bit_11 As Long = &H800&
Const i32_bit_12 As Long = &H1000&
Const i32_bit_13 As Long = &H2000&
Const i32_bit_14 As Long = &H4000&
Const i32_bit_15 As Long = &H8000&
Const i32_bit_16 As Long = &H10000
Const i32_bit_17 As Long = &H20000
Const i32_bit_18 As Long = &H40000
Const i32_bit_19 As Long = &H80000
Const i32_bit_20 As Long = &H100000
Const i32_bit_21 As Long = &H200000
Const i32_bit_22 As Long = &H400000
Const i32_bit_23 As Long = &H800000
Const i32_bit_24 As Long = &H1000000
Const i32_bit_25 As Long = &H2000000
Const i32_bit_26 As Long = &H4000000
Const i32_bit_27 As Long = &H8000000
Const i32_bit_28 As Long = &H10000000
Const i32_bit_29 As Long = &H20000000
Const i32_bit_30 As Long = &H40000000
Const i32_bit_31 As Long = &H80000000

Const i16_bit_00 As Integer = &H1
Const i16_bit_01 As Integer = &H2
Const i16_bit_02 As Integer = &H4
Const i16_bit_03 As Integer = &H8
Const i16_bit_04 As Integer = &H10
Const i16_bit_05 As Integer = &H20
Const i16_bit_06 As Integer = &H40
Const i16_bit_07 As Integer = &H80
Const i16_bit_08 As Integer = &H100
Const i16_bit_09 As Integer = &H200
Const i16_bit_10 As Integer = &H400
Const i16_bit_11 As Integer = &H800
Const i16_bit_12 As Integer = &H1000
Const i16_bit_13 As Integer = &H2000
Const i16_bit_14 As Integer = &H4000
Const i16_bit_15 As Integer = &H8000

Const i08_bit_00 As Byte = &H1
Const i08_bit_01 As Byte = &H2
Const i08_bit_02 As Byte = &H4
Const i08_bit_03 As Byte = &H8
Const i08_bit_04 As Byte = &H10
Const i08_bit_05 As Byte = &H20
Const i08_bit_06 As Byte = &H40
Const i08_bit_07 As Byte = &H80

Const i32_mask_byte0 As Long = &HFF&        ' *** CAREFUL HERE - if you leave the trailing "&" off then it all falls to pieces !!!!!!!!!!!!!!!!
Const i32_mask_byte1 As Long = &HFF00&      ' *** CAREFUL HERE - if you leave the trailing "&" off then it all falls to pieces !!!!!!!!!!!!!!!!
Const i32_mask_byte2 As Long = &HFF0000
Const i32_mask_byte3_nosignbit As Long = &H7F000000    ' notice this excludes the sign bit at bit07 (bit31 if the long)

Const i16_mask_byte0 As Long = &HFF
Const i16_mask_byte1_nosignbit As Long = &H7F00         ' notice this excludes the sign bit at bit07 (bit15 if the int)

Const i08_mask_byte0_nosignbit As Long = &H7F         ' notice this excludes the sign bit at bit07 (bit07 of the byte)

Private i32_bitarray(0 To 31) As Long
Private i16_bitarray(0 To 15) As Integer
Private i08_bitarray(0 To 7) As Byte

Private tmp_long As Long
Private signbit_long As Long
Private tmp_int As Integer
Private signbit_int As Integer
Private tmp_byte As Byte
Private signbit_byte As Byte

Private Sub Class_Initialize()
' Initialise bitarrays ready for use in masking by (zero-based) "bit number"
' MsgBox " in Class_Initialize in BitStreamVB6"
i32_bitarray(0) = i32_bit_00
i32_bitarray(1) = i32_bit_01
i32_bitarray(2) = i32_bit_02
i32_bitarray(3) = i32_bit_03
i32_bitarray(4) = i32_bit_04
i32_bitarray(5) = i32_bit_05
i32_bitarray(6) = i32_bit_06
i32_bitarray(7) = i32_bit_07
i32_bitarray(8) = i32_bit_08
i32_bitarray(9) = i32_bit_09
i32_bitarray(10) = i32_bit_10
i32_bitarray(11) = i32_bit_11
i32_bitarray(12) = i32_bit_12
i32_bitarray(13) = i32_bit_13
i32_bitarray(14) = i32_bit_14
i32_bitarray(15) = i32_bit_15
i32_bitarray(16) = i32_bit_16
i32_bitarray(17) = i32_bit_17
i32_bitarray(18) = i32_bit_18
i32_bitarray(19) = i32_bit_19
i32_bitarray(20) = i32_bit_20
i32_bitarray(21) = i32_bit_21
i32_bitarray(22) = i32_bit_22
i32_bitarray(23) = i32_bit_23
i32_bitarray(24) = i32_bit_24
i32_bitarray(25) = i32_bit_25
i32_bitarray(26) = i32_bit_26
i32_bitarray(27) = i32_bit_27
i32_bitarray(28) = i32_bit_28
i32_bitarray(29) = i32_bit_29
i32_bitarray(30) = i32_bit_30
i32_bitarray(31) = i32_bit_31

i16_bitarray(0) = i16_bit_00
i16_bitarray(1) = i16_bit_01
i16_bitarray(2) = i16_bit_02
i16_bitarray(3) = i16_bit_03
i16_bitarray(4) = i16_bit_04
i16_bitarray(5) = i16_bit_05
i16_bitarray(6) = i16_bit_06
i16_bitarray(7) = i16_bit_07
i16_bitarray(8) = i16_bit_08
i16_bitarray(9) = i16_bit_09
i16_bitarray(10) = i16_bit_10
i16_bitarray(11) = i16_bit_11
i16_bitarray(12) = i16_bit_12
i16_bitarray(13) = i16_bit_13
i16_bitarray(14) = i16_bit_14
i16_bitarray(15) = i16_bit_15

i08_bitarray(0) = i08_bit_00
i08_bitarray(1) = i08_bit_01
i08_bitarray(2) = i08_bit_02
i08_bitarray(3) = i08_bit_03
i08_bitarray(4) = i08_bit_04
i08_bitarray(5) = i08_bit_05
i08_bitarray(6) = i08_bit_06
i08_bitarray(7) = i08_bit_07

'MsgBox "Class_Initialize: i32 masks[0..3]=" & Hex(i32_mask_byte0) & " " & Hex(i32_mask_byte1) & " " & Hex(i32_mask_byte2) & " " & Hex(i32_mask_byte3_nosignbit)
End Sub

Private Sub Class_Terminate()
' MsgBox " in Class_Terminate in BitStreamVB6"
End Sub

Sub i32_to_bytearray(ByRef src_i32 As Long, ByRef dst_i8() As Byte)
' Copy up to 4 bytes from an i32 into a byte array
    dst_i8(0) = (src_i32 And i32_mask_byte0)
    dst_i8(1) = (src_i32 And i32_mask_byte1) \ i32_bit_08
    dst_i8(2) = (src_i32 And i32_mask_byte2) \ i32_bit_16
    dst_i8(3) = (src_i32 And i32_mask_byte3_nosignbit) \ i32_bit_24           ' notice it is masked by 7F and not FF due to the sign bit issue
    If (src_i32 And i32_bit_31) = i32_bit_31 Then               ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
        dst_i8(3) = dst_i8(3) Or i08_bit_07
    End If
End Sub

Sub i32_to_string(ByRef src_i32 As Long, ByRef dst_ch As String)
' Copy 4 bytes from an i32 into a string
    Dim stringToReturn As String
    Dim ch1 As String * 1
    Dim longwordUpperByte As Long
    dst_ch = ""
    ch1 = Chr(src_i32 And i32_mask_byte0)
    dst_ch = dst_ch & ch1
    ch1 = Chr((src_i32 And i32_mask_byte1) \ i32_bit_08)
    dst_ch = dst_ch & ch1
    ch1 = Chr((src_i32 And i32_mask_byte2) \ i32_bit_16)
    dst_ch = dst_ch & ch1
    longwordUpperByte = (src_i32 And i32_mask_byte3_nosignbit) \ i32_bit_24   ' notice it is masked by 7F and not FF due to the sign bit issue
    If (src_i32 And i32_bit_31) = i32_bit_31 Then               ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
        longwordUpperByte = longwordUpperByte Or i32_bit_07
    End If
    ch1 = Chr(longwordUpperByte)
    dst_ch = dst_ch & ch1
End Sub

Sub i16_to_bytearray(ByRef src_i16 As Integer, ByRef dst_i8() As Byte)
' Copy 2 bytes from an i16 into a byte array
    dst_i8(0) = (src_i16 And i16_mask_byte0)
    dst_i8(1) = (src_i16 And i16_mask_byte1_nosignbit) \ i16_bit_08              ' notice it is masked by 7F and not FF due to the sign bit issue
    If (src_i16 And i16_bit_15) = i16_bit_15 Then               ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
        dst_i8(1) = dst_i8(1) Or i08_bit_07
    End If
End Sub

Sub i16_to_string(ByRef src_i16 As Integer, ByRef dst_ch As String)
' Copy 4 bytes from an i32 into a string
    Dim ch1 As String * 1
    Dim wordUpperByte As Integer
    dst_ch = ""
    ch1 = Chr(src_i16 And i16_mask_byte0)
    dst_ch = dst_ch & ch1
    wordUpperByte = (src_i16 And i16_mask_byte1_nosignbit) \ i16_bit_08           ' notice it is masked by 7F and not FF due to the sign bit issue
    If (src_i16 And i16_bit_15) = i16_bit_15 Then               ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
        wordUpperByte = wordUpperByte Or i16_bit_07
    End If
    ch1 = Chr(wordUpperByte)
    dst_ch = dst_ch & ch1
End Sub

Function i32_GetBit(ByRef src_i32 As Long, ByVal src_bitno As Long) As Long
    If src_bitno < 0 Or src_bitno > 31 Then
        Err.Raise 5, "i32_is_bit_set", "bit number not in range [0..31)"
    End If
    i32_GetBit = IIf(((src_i32 And i32_bitarray(src_bitno)) = i32_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function

Function i16_GetBit(ByRef src_i16 As Integer, ByVal src_bitno As Long) As Long
    If src_bitno < 0 Or src_bitno > 15 Then
        Err.Raise 5, "i16_is_bit_set", "bit number not in range [0..15)"
    End If
    i16_GetBit = IIf(((src_i16 And i16_bitarray(src_bitno)) = i16_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function

Function i08_GetBit(ByRef src_i08 As Byte, ByVal src_bitno As Long) As Long
    If src_bitno < 0 Or src_bitno > 7 Then
        Err.Raise 5, "i08_is_bit_set", "bit number not in range [0..7)"
    End If
    i08_GetBit = IIf(((src_i08 And i08_bitarray(src_bitno)) = i08_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function

Function i32_ShiftRight(ByRef src_i32 As Long, ByVal src_nobits As Long) As Long
    If src_nobits < 0 Or src_nobits > 32 Then
        Err.Raise 5, "i32_ShiftRight", "bit number not in range [0..32)"
    End If
    If src_nobits = 0 Then  ' no shifting, zero bitshift requested :)
        i32_ShiftRight = src_i32
        Exit Function
    End If
    If src_nobits = 32 Then ' full longword bitshift requested, hence will be zero :)
        i32_ShiftRight = &H0&
        Exit Function
    End If
    ' the damn sign bit stuffs things up
    signbit_long = src_i32 And i32_bit_31   ' save the sign bit, we need to move it separately
    If src_nobits = 31 Then ' sign bit requested via a shiftright by 31 bits, so handle the special case because VB6 overflows if you don't
        i32_ShiftRight = IIf((signbit_long = i32_bit_31), 1, 0)  ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
        Exit Function
    End If
    tmp_long = src_i32 And (Not i32_bit_31) ' make a variable excluding the sign bit
    tmp_long = tmp_long / (2 ^ src_nobits)       ' shift bits right by simple division
    'now put back the sign bit also shifted right by src_nobits bits
    If signbit_long = i32_bit_31 Then
        signbit_long = i32_bitarray(31 - src_nobits) ' use a lookup to do it instead of division because VB6 hates signs
    Else
        signbit_long = &H0&
    End If
    i32_ShiftRight = tmp_long Or signbit_long
End Function

Function i32_ShiftLeft(ByRef src_i32 As Long, ByVal src_nobits As Long) As Long
    Static bit0 As Long
    Static i As Long
    Static bitmask As Long
    Static topbit As Long
    Static aLong As Long
    Static no_saved_bits As Long
    If src_nobits < 0 Or src_nobits > 32 Then
        Err.Raise 5, "i32_ShiftLeft", "bit number not in range [0..32)"
    End If
    If src_nobits = 0 Then  ' no shifting, zero bitshift requested :)
        i32_ShiftLeft = src_i32
        Exit Function
    End If
    If src_nobits = 32 Then ' full longword bitshift requested, hence will be zero :)
        i32_ShiftLeft = &H0&
        Exit Function
    End If
    ' the damn sign bit stuffs things up/
    ' calc how many bits are to be saved (from bit0) and create a bitmask
    no_saved_bits = 31 - src_nobits ' remember this is zero-based so 0 result means there is 1 bit to be saved
    bitmask = 0
    For i = 0 To no_saved_bits - 1 ' no_saved_bits=0 means move 31 bits to the left, and this FOR LOOP gets skipped :)
        bitmask = bitmask Or i32_bitarray(i)
    Next i
    ' mask them in (ie mask out the bits to be lost), shift them left, and put in the sign bit
    aLong = src_i32 And bitmask
    aLong = aLong * (2& ^ src_nobits)
    topbit = IIf((src_i32 And i32_bitarray(no_saved_bits)) = i32_bitarray(no_saved_bits), i32_bit_31, 0)
    aLong = aLong Or topbit
    i32_ShiftLeft = aLong
End Function

GeneralRe: VB6 - how to bitstream Pin
Mycroft Holmes29-Apr-09 22:21
professionalMycroft Holmes29-Apr-09 22:21 
GeneralRe: VB6 - how to bitstream Pin
halsboss30-Apr-09 1:20
halsboss30-Apr-09 1:20 
GeneralRe: VB6 - how to bitstream Pin
Dave Kreskowiak30-Apr-09 13:16
mveDave Kreskowiak30-Apr-09 13:16 
QuestionRe: VB6 - how to bitstream Pin
CPallini30-Apr-09 1:48
mveCPallini30-Apr-09 1:48 
AnswerRe: VB6 - how to bitstream Pin
halsboss8-May-09 21:54
halsboss8-May-09 21:54 
NewsRe: VB6 - how to bitstream Pin
CPallini9-May-09 1:41
mveCPallini9-May-09 1:41 
GeneralRe: VB6 - how to bitstream Pin
halsboss9-May-09 2:06
halsboss9-May-09 2:06 
GeneralRe: VB6 - how to bitstream Pin
CPallini9-May-09 4:06
mveCPallini9-May-09 4:06 
GeneralRe: VB6 - how to bitstream Pin
halsboss11-May-09 0:07
halsboss11-May-09 0:07 
GeneralRe: VB6 - how to bitstream Pin
CPallini11-May-09 0:23
mveCPallini11-May-09 0:23 
GeneralRe: VB6 - how to bitstream Pin
halsboss11-May-09 3:15
halsboss11-May-09 3:15 
Questionhow to find ascii value? Pin
JC.KaNNaN29-Apr-09 20:35
JC.KaNNaN29-Apr-09 20:35 
AnswerRe: how to find ascii value? Pin
_Damian S_29-Apr-09 20:53
professional_Damian S_29-Apr-09 20:53 
AnswerRe: how to find ascii value? Pin
Baran M30-Apr-09 1:00
Baran M30-Apr-09 1:00 
GeneralRe: how to find ascii value? Pin
JC.KaNNaN3-May-09 23:58
JC.KaNNaN3-May-09 23:58 
GeneralRe: how to find ascii value? Pin
JC.KaNNaN5-May-09 3:13
JC.KaNNaN5-May-09 3:13 
QuestionVB.NET and Access 2007 Database Engine Pin
Rick_Mutimer29-Apr-09 20:03
Rick_Mutimer29-Apr-09 20:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.