-
VB6 Code Help
Hello friends,
I am writing a VB6 Code to serially program a RTC Module via PIC for Alarm Time.
I am interested in knowing how to build a byte variable from 8 Check Boxes to be transfered to the Chip. These Check Boxes are to be labelled Days of the week the alarm needs to be on.
regards.
-
Make things simple. Use some Text box and a Command button. Once you click on the Command button it send the whole string of the Texts boxs.
In the PIC side, you use the right modifier (HEX, DEC, STR).
If you need some VB EBook, drop me your e-mail address in my PM.
-
Hi,
Try that:
Code:
Dim my_byte_value as byte
my_byte_value = 0
If Check1.Value = 1 Then my_byte_value = my_byte_value + 1
If Check2.Value = 1 Then my_byte_value = my_byte_value + 2
If Check3.Value = 1 Then my_byte_value = my_byte_value + 4
If Check4.Value = 1 Then my_byte_value = my_byte_value + 8
If Check5.Value = 1 Then my_byte_value = my_byte_value + 16
If Check6.Value = 1 Then my_byte_value = my_byte_value + 32
If Check7.Value = 1 Then my_byte_value = my_byte_value + 64
If Check8.Value = 1 Then my_byte_value = my_byte_value + 128
Best regards,
Luciano
-
Thank U Luciano.
That was exactly what i wanted. Sorry for my ignorance.
And if i am not asking for more can you also tell me how to reverse it.
I am sure it would be simple , but still.
Now how do i break up a byte to show up in the check boxes. Tick means One !
Thank you steve. You have been a lot of help to me and one of my unsung hero's learnt a lot of programing skills from your inputs to different people on the Forum. I would surely send you a PM for that E-book
regards
-
Hi,
Try that.
Best regards,
Luciano
Code:
Dim my_byte_value As Byte
my_byte_value = 6 '(Any value from 0 to 255)
If my_byte_value And 1 Then
Check1.Value = 1
Else
Check1.Value = 0
End If
If my_byte_value And 2 Then
Check2.Value = 1
Else
Check2.Value = 0
End If
If my_byte_value And 4 Then
Check3.Value = 1
Else
Check3.Value = 0
End If
If my_byte_value And 8 Then
Check4.Value = 1
Else
Check4.Value = 0
End If
If my_byte_value And 16 Then
Check5.Value = 1
Else
Check5.Value = 0
End If
If my_byte_value And 32 Then
Check6.Value = 1
Else
Check6.Value = 0
End If
If my_byte_value And 64 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
If my_byte_value And 128 Then
Check8.Value = 1
Else
Check8.Value = 0
End If
Below is the reverse action using the OR operation:
(Same result as my first post).
Code:
Dim my_byte_value As Byte
my_byte_value = 0
If Check1.Value = 1 Then my_byte_value = my_byte_value Or 1
If Check2.Value = 1 Then my_byte_value = my_byte_value Or 2
If Check3.Value = 1 Then my_byte_value = my_byte_value Or 4
If Check4.Value = 1 Then my_byte_value = my_byte_value Or 8
If Check5.Value = 1 Then my_byte_value = my_byte_value Or 16
If Check6.Value = 1 Then my_byte_value = my_byte_value Or 32
If Check7.Value = 1 Then my_byte_value = my_byte_value Or 64
If Check8.Value = 1 Then my_byte_value = my_byte_value Or 128
-
Thank You.
Thank you once again. I hope this is helpful to other on the forum as well.
regards