I need help with this Variable...

JFulford84

Board Regular
Joined
Jun 14, 2010
Messages
158
Can anyone help explain why I'm getting this?
When I do a MsgBox(a/b) the calculation is correct at .5 or 50%. However when I calculate that number then assigned it to variable like resultOf = a/b, it shows resultOf as being 1.

Anyone able to offer any insight?


a = 10,000
b = 20,000

MsgBox(a/b) = .5

Dim resultOf as Long
resultOf = a/b
MsgBox(resultOf) = 1
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Long is an integer type - it doesn't preserve fractional parts.
 
Upvote 0
Just as an aside, it makes a difference which way you put the slash (forward or backward):

Code:
[COLOR="Navy"]Sub[/COLOR] F00()
[COLOR="Navy"]Dim[/COLOR] ret [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Double[/COLOR]

    [COLOR="SeaGreen"]'------------------[/COLOR]
    [COLOR="SeaGreen"]'//Division[/COLOR]
    ret = 22 / 7
    [COLOR="Navy"]Debug[/COLOR].[COLOR="Navy"]Print[/COLOR] ret
    
    [COLOR="SeaGreen"]'------------------[/COLOR]
    [COLOR="SeaGreen"]'//Integer Division[/COLOR]
    ret = 22 \ 7
    [COLOR="Navy"]Debug[/COLOR].[COLOR="Navy"]Print[/COLOR] ret

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

ξ
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,337
Members
452,907
Latest member
Roland Deschain

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