Help with Mod and / Functions in VBA

pokeManiac

New Member
Joined
Dec 9, 2014
Messages
3
Hi,

I need help with writing the Mod and / functions in VBA in a different way. I read in another thread that these two intrinsically produce results of the Long data type. But I need more than that. This is my convertToHex function which takes in as argument a decimal number:

result = ""
while decNum > 16
result = choose(decNum Mod 16 + 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F") & result
decNum = Int(decNum / 16)
wend
convertToHex = choose(decNum + 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F") & result

It works fine for a hexadecimal value with seven digits. But when the computation produces an eighth, I get an overflow error.

Help!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi and welcome to the board,

Couldn't you just use HEX(123456) or EVALUATE("DEC2HEX(123456)") rather than write a function?
 
Upvote 0
Hahahahaha! I didn't know there was a HEX function in vba. That would certainly simplify everything. I would just like to know though how EVALUATE works. I tried looking it up on Excel's help tool but nothing came up.
 
Upvote 0
I tried using the HEX function but I'm still getting an overflow error. This is how my statement now looks like:

doXorCalc = Hex(convertToDec(hexValue1) Xor convertToDec(hexValue2))

where hexValue1 and hexValue2 are string representations of the hexadecimal values I want to do the XOR operation on and doXorCalc is the function returning the result. I even tried converting the data type to DECIMAL with the CDEC function after getting the decimal values but it still would not work.

What am I doing wrong here?
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top