EccentricDyslex
Newcomer
- Joined
- Jul 26, 2010
- Messages
- 11
Hi all,
i have a problem with the code below. Basicaly i have an integer that i need to convert to binary and show the results in check boxes. The code below takes the integer, converts it to a binary string, then depending upon where the "1"s are, will check the apropriate check box on the UI. The binary number returned has a max of 16 digits and a min of 0, so hence the 16 checkboxes.
The problem i am having is the code runs fine counting down from the left most "1" (int32768) with all the others to the right as "0"s. Halfing the int each cycle should result in the "1" moving along the checkboxes until it reaches the right most position. But its working fine down to box 9, but then it disapears!
Any ideas?
CODE-
then i loop this code 16 times. Any ideas?
Cheers!
Steve
i have a problem with the code below. Basicaly i have an integer that i need to convert to binary and show the results in check boxes. The code below takes the integer, converts it to a binary string, then depending upon where the "1"s are, will check the apropriate check box on the UI. The binary number returned has a max of 16 digits and a min of 0, so hence the 16 checkboxes.
The problem i am having is the code runs fine counting down from the left most "1" (int32768) with all the others to the right as "0"s. Halfing the int each cycle should result in the "1" moving along the checkboxes until it reaches the right most position. But its working fine down to box 9, but then it disapears!
Any ideas?
CODE-
Visual Basic:
intInputs = 32768
'convert intinputs to binary
strInputs = dec2baseN(intInputs, 2)
'find length of strInputs
intLengthofinputsstring = Len(strInputs)
'find difference between strinputs and 16 so we know how many "0"s to
add to the left of the string to keep everything in line
Dim difbetweenstrinputsand16 As Integer
difbetweenstrinputsand16 = 16 - Len(strInputs)
'if strInputs is less than 16 digits long, add 0s to the left of the
string to make length always 16 digits long
If difbetweenstrinputsand16 > 0 Then
For a = 1 To difbetweenstrinputsand16 - 1
strInputs = "0" & strInputs
Next
End If
'clear all checkboxes
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
CheckBox5.Checked = False
CheckBox6.Checked = False
CheckBox7.Checked = False
CheckBox8.Checked = False
CheckBox9.Checked = False
CheckBox10.Checked = False
CheckBox11.Checked = False
CheckBox12.Checked = False
CheckBox13.Checked = False
CheckBox14.Checked = False
CheckBox15.Checked = False
CheckBox16.Checked = False
'analise the 16digit binary string and if any of the binary digits are ones, then check the related checkbox
Dim temp As Integer
For count = intLengthofinputsstring To 1 Step -1
temp = Microsoft.VisualBasic.Mid(strInputs, count, 1)
If temp = 1 And count = 16 Then CheckBox1.Checked = True
If temp = 1 And count = 15 Then CheckBox2.Checked = True
If temp = 1 And count = 14 Then CheckBox3.Checked = True
If temp = 1 And count = 13 Then CheckBox4.Checked = True
If temp = 1 And count = 12 Then CheckBox5.Checked = True
If temp = 1 And count = 11 Then CheckBox6.Checked = True
If temp = 1 And count = 10 Then CheckBox7.Checked = True
If temp = 1 And count = 9 Then CheckBox8.Checked = True
If temp = 1 And count = 8 Then CheckBox9.Checked = True
If temp = 1 And count = 7 Then CheckBox10.Checked = True
If temp = 1 And count = 6 Then CheckBox11.Checked = True
If temp = 1 And count = 5 Then CheckBox12.Checked = True
If temp = 1 And count = 4 Then CheckBox13.Checked = True
If temp = 1 And count = 3 Then CheckBox14.Checked = True
If temp = 1 And count = 2 Then CheckBox15.Checked = True
If temp = 1 And count = 1 Then CheckBox16.Checked = True
Next
'divide intInputs by2 to move the "1" along by one step
intInputs = intInputs / 2
then i loop this code 16 times. Any ideas?
Cheers!
Steve
Last edited by a moderator: