1

円錐の体積を計算する Visual Basic 電卓があります。

1 つは mm 立方体で、もう 1 つは立方メートル (小数点以下 2 桁) で四捨五入されます。しかし、メートルが 0.01 以上になったら立方メートルのみを表示したいと思います。

ここに私の計算コードがあります

Private Sub txtSidea_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtHeight.Leave, txtRadius.Leave
    'calculate volume cubic mm using V= 1/3 pi R*2*H  
    Const PI As Double = System.Math.PI
    lbAnswerlVolumeMM.Text = (1 / 3 * PI * ((Val(txtRadius.Text) ^ 2) * Val(txtHeight.Text))).ToString("#") + " :Cuibic mm"
    'calculate volume cubic meter using V= 1/3 pi R*2*H / 10^9
    lblAnswerVolumeMetres.Text = ((1 / 3 * PI * ((Val(txtRadius.Text) ^ 2) * Val(txtHeight.Text))) / 10 ^ 9).ToString("#.##") + " :Cubic Metre"
End Sub

例は次のとおりです。高さ50mm、半径30mm。これは 47124 mm の立方体を出力します。しかし、メートル キューブには何も表示されないため、メートル キューブの答えが 0.01 未満の場合は、0.01 を超えるまでラベルを非表示にしてから結果を表示したいと考えています。

4

1 に答える 1

0

これを試して:

Private Sub txtSidea_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtHeight.Leave, txtRadius.Leave
    'calculate volume cubic mm using V= 1/3 pi R*2*H  
    Const PI As Double = System.Math.PI
    lbAnswerlVolumeMM.Text = (1 / 3 * PI * ((Val(txtRadius.Text) ^ 2) * Val(txtHeight.Text))).ToString("#")
    'calculate volume cubic meter using V= 1/3 pi R*2*H / 10^9
    lblAnswerVolumeMetres.Text = ((1 / 3 * PI * ((Val(txtRadius.Text) ^ 2) * Val(txtHeight.Text))) / 10 ^ 9).ToString("#.##")

    '--Decide which to hide
    If lblAnswerVolumeMetres.Text >= 0.01 then
        lblAnswerVolumeMetres.Visible = True
        lbAnswerlVolumeMM.Visible = False
    Else
        lblAnswerVolumeMetres.Visible = False
        lbAnswerlVolumeMM.Visible = True
    End If
    '--Shift the description to after the decision is made based on the number.
    lblAnswerVolumeMetres.Text &= " :Cubic mm"
    lbAnswerlVolumeMM &= " :Cubic Metre"
End Sub
于 2013-03-21T05:58:21.753 に答える