Consulting

Results 1 to 4 of 4

Thread: Solved: Display result to 3DP?

  1. #1

    Solved: Display result to 3DP?

    Hi

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

    [VBA]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[/VBA]

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

    Any help appreciated

    thanks

  2. #2
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    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.[vba]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
    [/vba]
    HTH,
    Ron
    Windermere, FL

  3. #3
    Thanks Ron - works well

    Learn a little more each day from this great forum

    regards

    Jon

  4. #4
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    G'day, Jon,

    Glad to help.!

    Cheers,
    Ron
    Windermere, FL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •