I am trying to convert a column of hexadecimal values to binary values and then write the binary values to a binary file. However, I am having trouble with the conversion of the hex values to binary...
I found this thread: Convert hex value string to Binary string
I have been trying to do as the answers suggest and convert each hex character to binary and then append the results to a string representing the full binary number. However, I am getting errors when trying to convert my hexadecimal string characters... Here is what I am currently trying to do:
Dim hexString As String
Dim binaryString As String
hexString = ""
binaryString = ""
Dim rangeOfCells As Range
Set rangeOfCells = Range ("C5: C100")
Dim hexCell As Range
For Each hexCell In rangeOfCells.Cells
If Not isEmpty(hexCell.value) Then
hexString = hexCell.Value
Dim counter As Integer
For counter = 1 to Len(hexString)
binaryString = binaryString & Convert.ToString(Convert.ToInt32(Mid(hexString, counter, 1), 16), 2)
Next
End If
Next
I keep getting this error on the line converting the hexString character to binary and appending the value to the binaryString:
Run-time error '424': Object required
I have tried simplifying the line of code and continue to get the error event when just trying to convert my hexString to an Int (ie: Convert.ToInt32(hexString)).
Any help on this issue is greatly appreciated. Thank you!
Convert.ToStringis VB.NET, not VBA