Date: 02-16-2022
Return to Index
created by gbSnippets
'This code shows how to save 2 values in a single DWord integer, but
'with the improvement over MAK of allowing the user to determine how
'many bits of the Long to use for storing each variable.
'Primary Code:
'The approach is to create a TYPE that defines how many bits to assign
'to each variable, then to use a UNION with a DWord variable to overlay
'the combined bit structure. This allows the DWord variable to contain
'both smaller values, which continuing to allow direct access to each
'smaller value
Type BitSplit
bLo As Bit * 20 In Dword
bHi As Bit * 12
End Type
Union UserData
Big As Dword
Small As BitSplit
End Union
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
Type BitSplit
bLo As Bit * 20 In Dword
bHi As Bit * 12
End Type
Union UserData
Big As Dword
Small As BitSplit
End Union
Function PBMain() As Long
Local hDlg As Dword
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Local D As UserData
D.Big = 2097156
? Str$( D.Small.blo)
? Str$( D.Small.bhi)
End If
End Function
'gbs_00998
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm