Can someone point me or show me how I can do hex addition and binary
addition? As robust as Excel with VBA, there must be a way to do this.
Tony
You can do hex addition by using the Val function to convert the hex
values (expressed as strings starting with the characters &H) to
decimal first. The decimal result can then be converted to a hex
string by the Hex function.
Sub AddHexVals()
Dim H1 As String, H2 As String
Dim DecResult As Long
Dim HexResult As String
H1 = "12fd"
H2 = "30e"
DecResult = Val("&H" & H1) + Val("&H" & H2)
HexResult = Hex(DecResult)
MsgBox HexResult
End Sub
Before you use this in your own code, carefully read the Remarks
section of the help topic about the Val function. You'll need code to
ensure that each input string really does contain only valid hex
characters -- if it doesn't, the result of the Val function will be
the value of the part of the string to the left of the first non-hex
character, or zero if there is none, but you won't get any error
message.
There's nothing like this for binary numbers. You'd have to write your
own functions to convert strings holding the binary representations to
decimal, and to convert the decimal result to binary. This code would
need error-checking for invalid characters and for buffer overflow,
and maybe some other stuff I haven't thought about.
By the way, whenever I read "There must be a way to do this", my first
thought is "not necessarily" and my second thought is "how much work
are you prepared to do?"