I understand better what it was that I was asking.
I wanted to have a value "x" represent the any or all of the values of a
list of values. To do so, I had wanted to perform bitwise operations to add
or remove values from "x". I have determined that I need to use the
operators ("Or" and "And Not") to add or remove values from "x"
Taking from Jevon's code reduction suggestion here is the resulting code:
(Jevon, I changed the byref's to byval's; was their a reason to use byref?)
Private Sub SwitchBit(ByVal checked As Boolean, ByVal weekday As
TurmsRemote.Weekdays)
If checked = True Then
Me.WeeklyDays = Me.WeeklyDays Or CType(weekday, Byte)
Else
Me.WeeklyDays = Me.WeeklyDays And Not CType(weekday, Byte)
End If
End Sub
This seems to solve all of the operations that I need. Unless anyone has
more to add, I will commit this to the ol' noggin for later use.
Thanks gang.
"AMDRIT" <am****@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP12.phx.gbl...
Gang,
I always get confused when it comes to 1's and 0's. I would like to
perform a bitwise operation on a value based on checked boxes.
Am I doing this right?
assuming TurmsRemote.Weekdays has values of
Monday =2
Tuesday =4
Wednesday =8
Thursday = 16
Friday =32
Saturday = 64
Sunday = 128
Sub Monday_Click(Sender, E)
dim chkbox as checkbox = ctype(sender, checkbox)
If chkbox.Checked Then
If Not Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays And TurmsRemote.Weekdays.Monday
End If
Else
If Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays - TurmsRemote.Weekdays.Monday
End If
End If
End Sub