1

我有一个计算圆锥体积的 Visual Basic 计算器。

我有两个答案,一个以毫米立方为单位,另一个以米立方为单位(四舍五入到最接近的百分之一(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

一个例子是;高度 50 毫米,半径 30 毫米。这将输出 47124 毫米立方体,这很好。但它没有显示米立方体,所以如果米立方体的答案低于 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 回答