Michael
Michael

Reputation: 1

2 decimal result in VB

    If RadioButtonAC144.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 144
    ElseIf RadioButtonAC72.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 72
    ElseIf RadioButtonAC48.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 48
    ElseIf RadioButtonAC35.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 35
    ElseIf RadioButtonAC32.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 32
    ElseIf RadioButtonAC24.Checked = True Then
        TextBoxACScale.Text = TextBoxACReal.Text / 24
    End If

This is my code, I have several pages(tabs) similar to this, so it's a PITA to change it all up but if it's the only way then so be it, however I just need the result that is showing up in TextBoxACScale.Text to show up to only 2 decimal places. This code is implemented when clicking a calculate button.

Upvotes: 0

Views: 77

Answers (2)

King of kings
King of kings

Reputation: 695

If RadioButtonAC144.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 144,2)
ElseIf RadioButtonAC72.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 72,2)
ElseIf RadioButtonAC48.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 48,2)
ElseIf RadioButtonAC35.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 35,2)
ElseIf RadioButtonAC32.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 32,2)
ElseIf RadioButtonAC24.Checked = True Then
    TextBoxACScale.Text = Round(TextBoxACReal.Text / 24,2)
End If

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 415665

Dim Divisor As Integer = 1
If RadioButtonAC144.Checked Then
    Divisor = 144
ElseIf RadioButtonAC72.Checked Then
    Divisor = 72
ElseIf RadioButtonAC48.Checked Then
    Divisor = 48
ElseIf RadioButtonAC35.Checked Then
    Divisor = 35
ElseIf RadioButtonAC32.Checked Then
    Divisor = 32
ElseIf RadioButtonAC24.Checked Then
    Divisor = 24
End If
TextBoxACScale.Text = (Convert.ToDecimal(TextBoxACReal.Text) / Divisor).ToString("F2")

Upvotes: 2

Related Questions