Visual Basic" Do While"环

时间:2014-09-11 23:51:55

标签: vb.net loops while-loop

我正在编写一个基本程序,允许用户根据半径长度,边长,高度等信息计算形状(2d和3d)上的有用数据。

我想创建一个设置菜单,允许用户设置他们想要答案的小数位数,所以我做的是

    Private Sub btnSettings_Click(sender As Object, e As EventArgs) Handles btnSettings.Click

    If btnSettings.Text = "Settings" Then
        btnSettings.Text = "Back"
    ElseIf btnSettings.Text = "Back" Then
        btnSettings.Text = "Settings"
    End If

    Do While btnSettings.Text = "Back"

        'makes IO elements invisible
        lblEnter.Visible = False
        lblEnter2.Visible = False
        lblData1.Visible = False
        lblData2.Visible = False
        lblData3.Visible = False
        lblAnswer1.Visible = False
        lblAnswer2.Visible = False
        lblAnswer3.Visible = False
        txtEnter.Visible = False
        txtEnter2.Visible = False
        btnClearTxt1.Visible = False
        lblEnter3.Visible = False
        txtEnter3.Visible = False
        chkBox.Visible = False
        btnCalculate.Visible = False
        btnClear.Visible = False

        'Makes shape selection elements invisible
        picCircle.Visible = False
        picSquare.Visible = False
        picTriangle.Visible = False
        rdoCircle.Visible = False
        rdoSquare.Visible = False
        rdoTriangle.Visible = False
        btn3D.Visible = False

        'Changes texts on necessary elements
        lblSelectShape.Text = "Settings"
    Loop

End Sub

正如您所看到的,当" btnSettings"显示文本"设置",屏幕上的元素对用户是可见的,但是只要" btnSettings"将文字更改为"返回" (表示用户在设置菜单中)屏幕上的所有元素都消失,为设置菜单中的元素腾出空间。但是,每当我按下设置按钮调试程序时,程序就会崩溃。

有任何帮助吗?感谢

1 个答案:

答案 0 :(得分:2)

使用Select Case

Select Case shapeType
 Case shapeType.Circle
   'logic for this
 '...
End Select