Click here to Skip to main content
15,914,225 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Help....... Pin
Nick Parker4-Apr-03 4:49
protectorNick Parker4-Apr-03 4:49 
GeneralHelp needed on Undocumented Shell "IDM_SHVIEW_NEWFOLDER". Any experts out here. Pin
Villly4-Apr-03 0:25
Villly4-Apr-03 0:25 
Generaldos commands Pin
r i s h a b h s3-Apr-03 17:22
r i s h a b h s3-Apr-03 17:22 
GeneralRe: dos commands Pin
Tim McCurdy4-Apr-03 1:35
Tim McCurdy4-Apr-03 1:35 
GeneralRe: dos commands Pin
OMalleyW19-Apr-03 7:32
OMalleyW19-Apr-03 7:32 
GeneralVB Endian Conversion Pin
mikasa3-Apr-03 10:40
mikasa3-Apr-03 10:40 
GeneralRe: VB Endian Conversion Pin
Oscar Martin3-Apr-03 21:02
Oscar Martin3-Apr-03 21:02 
GeneralRe: VB Endian Conversion Pin
J. Dunlap6-Apr-03 7:55
J. Dunlap6-Apr-03 7:55 
Here's your VB6 code:

'MakeDWord
'MakeWord
'HiByte
'LoByte
'HiWord
'LoWord
'RShWord
'LShWord
'LShDWord
'RShDWord
'DWordWSwap
'WordBSwap
'ToggleBit
'SetBit
'ClearBit
'SetBitVal
'IsBitSet

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)


'BBBB  Y   Y  TTTTT EEEEE
'B   B  Y  Y    T   E
'BBBB    Y      T   EEEEE
'B   B   Y      T   E
'BBBB   Y       T   EEEEE

'***************************


'Extract
'*********

Function LoWord(ByVal dw As Long) As Integer
CopyMemory LoWord, dw, 2
End Function

Function HiWord(ByVal dw As Long) As Integer
    CopyMemory HiWord, ByVal VarPtr(dw) + 2, 2
End Function

Function LoByte(ByVal dw As Integer) As Integer
CopyMemory LoByte, dw, 1
End Function

Function HiByte(ByVal dw As Integer) As Integer
    CopyMemory HiByte, ByVal VarPtr(dw) + 1, 1
End Function

'Swap
'*****
'(Little <--> Big Endian)

Function WordBSwap(ByVal Wd As Integer) As Integer
WordBSwap = MakeWord(HiByte(Wd), LoByte(Wd))
End Function

Function DWordWSwap(ByVal dw As Integer) As Integer
DWordWSwap = MakeDWord(HiWord(dw), LoWord(dw))
End Function

'Bit Shift
'**********

Function LShWord(ByVal Wd As Integer) As Integer
LShWord = MakeWord(HiByte(Wd), 0)
End Function

Function RShWord(ByVal Wd As Integer) As Integer
RShWord = MakeWord(0, LoByte(Wd))
End Function

Function LShDWord(ByVal dw As Long) As Long
LShDWord = MakeDWord(HiWord(dw), 0)
End Function

Function RShDWord(ByVal dw As Long) As Long
RShDWord = MakeDWord(0, LoWord(dw))
End Function

'Create
'***********

Function MakeWord(iLo As Integer, iHi As Integer) As Integer
CopyMemory MakeWord, iLo, 1
CopyMemory ByVal VarPtr(MakeWord) + 1, iHi, 1
End Function

Function MakeDWord(iLo As Integer, iHi As Integer) As Long
CopyMemory MakeDWord, iLo, 2
CopyMemory ByVal VarPtr(MakeWord) + 2, iHi, 2
End Function


'BBBB  IIIII  TTTTT
'B   B   I      T
'BBBB    I      T
'B   B   I      T
'BBBB  IIIII    T

'***************************


Sub SetBit(refByte As Integer, Bit As Integer)
      ' Create a bitmask with the 2 to the nth power bit set:
      Mask = 2 ^ Bit
      ' Set the nth Bit:
      refByte = refByte Or Mask
End Sub

Sub ToggleBit(refByte As Integer, Bit As Integer)
      ' Create a bitmask with the 2 to the nth power bit set:
      Mask% = 2 ^ Bit
      ' Toggle the nth Bit:
      refByte = refByte Xor Mask%
End Sub

 ' The ClearBit Sub clears the nth bit (Bit%) of an integer (Byte%).
Sub ClearBit(refByte As Integer, ByVal Bit As Integer)
      ' Create a bitmask with the 2 to the nth power bit set:
      Mask% = 2 ^ Bit
      ' Clear the nth Bit:
      refByte = refByte And Not Mask%
End Sub

Sub SetBitVal(refByte As Integer, ByVal Bit As Integer, ByVal Value As Boolean)
Mask% = 2 ^ Bit
If Value Then _
    refByte = refByte Or Mask _
Else _
      refByte = refByte And Not Mask%
End Sub

Function IsBitSet(refByte As Integer, ByVal Bit As Integer) As Boolean
      ' Create a bitmask with the 2 to the nth power bit set:
      Mask% = 2 ^ Bit
      ' Return the truth state of the 2 to the nth power bit:
      IsBitSet = ((refByte And Mask%) > 0)
End Function





Do unto others as you would have them do unto you - Jesus

An eye for an eye only makes the whole world blind - Mahatma Gandhi
GeneralRe: VB Endian Conversion Pin
mikasa6-Apr-03 8:07
mikasa6-Apr-03 8:07 
GeneralRe: VB Endian Conversion Pin
J. Dunlap6-Apr-03 8:40
J. Dunlap6-Apr-03 8:40 
QuestionLazy Evaluation ternary op? Pin
eidylon3-Apr-03 9:11
eidylon3-Apr-03 9:11 
AnswerRe: Lazy Evaluation ternary op? Pin
Daniel Turini3-Apr-03 9:25
Daniel Turini3-Apr-03 9:25 
GeneralRe: Lazy Evaluation ternary op? Pin
mikasa3-Apr-03 10:44
mikasa3-Apr-03 10:44 
GeneralRe: Lazy Evaluation ternary op? Pin
Daniel Turini3-Apr-03 10:48
Daniel Turini3-Apr-03 10:48 
GeneralRe: Lazy Evaluation ternary op? Pin
mikasa3-Apr-03 10:57
mikasa3-Apr-03 10:57 
GeneralPrintPreview Question 2 Pin
Fleischen3-Apr-03 5:52
Fleischen3-Apr-03 5:52 
GeneralAccess Visual Basic References Pin
Kogorman3-Apr-03 5:17
Kogorman3-Apr-03 5:17 
GeneralRe: Access Visual Basic References Pin
mikasa3-Apr-03 10:50
mikasa3-Apr-03 10:50 
GeneralVB 2 VB.NET Pin
Oscar Martin3-Apr-03 2:27
Oscar Martin3-Apr-03 2:27 
GeneralRe: VB 2 VB.NET Pin
mikasa3-Apr-03 10:59
mikasa3-Apr-03 10:59 
GeneralRe: VB 2 VB.NET Pin
mikasa3-Apr-03 11:00
mikasa3-Apr-03 11:00 
GeneralRe: VB 2 VB.NET Pin
Oscar Martin3-Apr-03 11:07
Oscar Martin3-Apr-03 11:07 
GeneralUse DLL in VBasic Pin
Martin_Viet3-Apr-03 1:44
Martin_Viet3-Apr-03 1:44 
GeneralRe: Use DLL in VBasic Pin
Villly3-Apr-03 1:52
Villly3-Apr-03 1:52 
GeneralRe: Use DLL in VBasic Pin
Martin_Viet3-Apr-03 2:26
Martin_Viet3-Apr-03 2:26 

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.