ajetrumpet
Banned for being rude
- Joined
- Apr 12, 2008
- Messages
- 569
- Office Version
- 365
- 2016
- 2007
- Platform
- Windows
all,
my coding stopped at the same spot all of a sudden, and I believe I corrupted my entire excel file by having the code break when a hex() function tried to return an unacceptable value. I can't remember what I did, but the input to hex() was using 3 nested cast functions. something like:
---> hex(cdbl(calledFunction return as string)))
now when I type hex() in the immed. window it's messed up. This:
errors out completely, when it should return 'F'. This:
returns 15. NOT 'F'.
so obviously it's not working properly now. Anyone got any suggestions for me? Tried copying all of my code into a new instance of excel with a new file created - same thing happened. It couldn't be my entire excel program that's screwed now, could it be?
the entire code I was using was:
my coding stopped at the same spot all of a sudden, and I believe I corrupted my entire excel file by having the code break when a hex() function tried to return an unacceptable value. I can't remember what I did, but the input to hex() was using 3 nested cast functions. something like:
---> hex(cdbl(calledFunction return as string)))
now when I type hex() in the immed. window it's messed up. This:
Code:
?hex(15)
Code:
?hex 15
so obviously it's not working properly now. Anyone got any suggestions for me? Tried copying all of my code into a new instance of excel with a new file created - same thing happened. It couldn't be my entire excel program that's screwed now, could it be?
the entire code I was using was:
Code:
Dim tempDbl As Double
tempDbl = CDbl(BinaryToDecimal("", "", "11111111"))
debug.print hex(tempDbl) 'ERRORS HERE (type mismatch)
----------------------------------------------------------------------------
Function BinaryToDecimal(InputCell As String, OutputCell As String, _
Optional convertVal As String) As Variant
'2 to 10 (quotient/remainder method does not work converting FROM binary!)
On Error GoTo eh
If convertVal Then
binary = convertVal
Else
binary = Range(InputCell)
End If
dec = 0
CharCount = Len(Trim(binary))
power = CharCount - 1
For i = 1 To CharCount
If Mid(binary, i, 1) = "1" Then
dec = dec + (base2 ^ power)
End If
power = power - 1
Next i
If convertVal Then
BinaryToDecimal = dec
Else
Range(OutputCell) = CStr(dec)
End If
eh:
End Function
Last edited: