Hello,
I searched a lot and came up with a function that is not working the way I wanted it.
I have a simple form with an input textbox (txt_input) and a button (btn_convert) that is meant to run my function and assign the outputs (decodedArray(5)) to my output textboxes (TextBox0 through TextBox4).
Function is to take a number (less than 32) as decimal and decodes it to a 5-bit binary while all bits will be displayed in a set of textboxes. (each bit in an individual textbox)
I am trying to use an array as my output and a single input named myDecimal.
Here are my codes:
And this is what I have under my button's On-Click event:
I appreciate if you help me to fix this code and explain what you are doing.
Thanks
I searched a lot and came up with a function that is not working the way I wanted it.
I have a simple form with an input textbox (txt_input) and a button (btn_convert) that is meant to run my function and assign the outputs (decodedArray(5)) to my output textboxes (TextBox0 through TextBox4).
Function is to take a number (less than 32) as decimal and decodes it to a 5-bit binary while all bits will be displayed in a set of textboxes. (each bit in an individual textbox)
I am trying to use an array as my output and a single input named myDecimal.
Here are my codes:
Code:
Public Function convertDec2Bin(myDecimal) As Variant
Dim n As Integer
Dim decodedArray(5) As Variant
n = myDecimal
decodedArray(0) = n Mod 2
n = n / 2
Me.TextBox0 = decodedArray(0)
decodedArray(1) = n Mod 2
n = n / 2
Me.TextBox1 = decodedArray(1)
decodedArray(2) = n Mod 2
n = n / 2
Me.TextBox2 = decodedArray(2)
decodedArray(3) = n Mod 2
n = n / 2
Me.TextBox3 = decodedArray(3)
decodedArray(4) = n Mod 2
n = n / 2
Me.TextBox4 = decodedArray(4)
convertDec2Bin = decodedArray
End Function
And this is what I have under my button's On-Click event:
Code:
Private Sub btn_convert_Click()
Dim decodedArray As Variant
myDecimal = Me.txt_input
packaging = convertDec2Bin(myDecimal)
End Sub
I appreciate if you help me to fix this code and explain what you are doing.
Thanks
Last edited: