PDA

View Full Version : Solved: Display result to 3DP?



blackie42
10-23-2008, 03:39 AM
Hi

I'm developing some compensation calculators and have the following code in a userform.

Sub CALCULATE()
Dim X As Integer
X = (TextBox1.Value / TextBox2.Value) - (TextBox1.Value / TextBox3.Value)
If X <= 1 Then
MsgBox ("Disadvantaged by " & X & " shares")
Else
MsgBox ("Advantaged by " & X & " shares")
End If
End Sub

I'd like the message box to display the value of X to 3 DP.

Any help appreciated

thanks

RonMcK
10-23-2008, 06:17 AM
blackie42,

Here is code that should work for you. Notice that you need to change the type of your variable X so you will get decimal values since integers have 0 decimal places.Sub CALCULATE()
Dim X As Double
If X <= 1 Then
MsgBox ("Disadvantaged by " & Format(X, "0.###") & " shares")
Else
MsgBox ("Advantaged by " & Format(X, "0.###") & " shares")
End If
End Sub

HTH,

blackie42
10-23-2008, 06:28 AM
Thanks Ron - works well

Learn a little more each day from this great forum

regards

Jon

RonMcK
10-23-2008, 06:30 AM
G'day, Jon,

Glad to help.!

Cheers,