thegreatescape
New Member
- Joined
- Jul 15, 2016
- Messages
- 3
I am writing a base64 encoder to learn more deeply VBA. The first step I am taking is to convert a decimal to binary. Here is what I have done so far (below). I have spent some time trying different approaches but my mental powers fail me. So hopefully I can learn from skilled members here as to how they would continue from my base code below. Thank you so much.
Code:
Private Sub numToBinary()
Dim goal As Integer
goal = 19
base64Array = Array(64, 32, 16, 8, 4, 2, 1)
'pseudo: recursively total each element of the array checking each calculation if goal is reached, once hit, map which elements were used in the calculation
'to binary, the goal above is 19, so the result would be 0010011
'the getArrayIndex() function I wrote anticipating I would need to get the index from the base64array during the calculation.
End Sub
'function to return the index of an element in an array
Private Function getArrayIndex(Arr, value) As Integer
Dim i As Integer
For i = LBound(Arr) To UBound(Arr)
If value = Arr(i) Then
getArrayIndex = i
Exit For
End If
Next i
End Function