VB.net中具有多个变量的嵌套案例结构

时间:2018-02-27 15:45:20

标签: vb.net nested

我正在为我的编程类简介开发一个项目并且坚持这个问题:https://i.imgur.com/rdLUXeq.png

到目前为止,这是我的代码

Private Sub btnShoe_Click(sender As Object, e As EventArgs) Handles btnShoe.Click
    Dim Name, Gender, Foot As String
    Name = InputBox("Enter Your Name", "Name")
    Gender = InputBox("Enter Your Gender (M/F)", "Gender")
    Foot = InputBox("Enter your foot size in inches", "Foot Size")
    'User Input Name, Gender, Foot Size

    Select Case Gender.ToUpper
        Case "M" To "F"
            Select Case Foot
                Case "9.5"
                    MessageBox.Show("Your Size is a Mens 7")
                    Case "9.6"
                    MessageBox.Show("Your Size is a Mens 7")
                        Case "9.7" To "9.9"
                        MessageBox.Show("Your Size is a Mens 8")
                Case "10" To "10.3"
                    MessageBox.Show("Your Size is a Mens 9")
                                Case "10.4" To "10.6"
                                MessageBox.Show("Your Size is a Mens 10")
                                    Case "10.7" To "10.9"
                                    MessageBox.Show("Your Size is a Mens 11")
                                        Case "11" To "11.3"
                                        MessageBox.Show("Your Size is a Mens 12")
                                            Case "11.4" To "11.6"
                                            MessageBox.Show("Your Size is a Mens 13")
                Case Else
                    MessageBox.Show("Size Unknown")

                    Select Case Gender.ToUpper
                        Case "F"
                            Select Case Foot
                                Case "8.6" To "8.7"
                                    MessageBox.Show("Your Size is a Womens 6")
                                Case "8.8" To "9.3"
                                    MessageBox.Show("Your Size is a Womens 7")
                                Case "9.4" To "9.5"
                                    MessageBox.Show("Your Size is a Womens 8")
                                Case "9.6" To "9.9"
                                    MessageBox.Show("Your Size is a Womens 9")
                                Case "10" To "10.2"
                                    MessageBox.Show("Your Size is a Womens 10")
                                Case "10.3" To "10.5"
                                    MessageBox.Show("Your Size is a Womens 11")
                                Case Else
                                    MessageBox.Show("Size Unknown")


                            End Select
                    End Select
            End Select
    End Selectenter code here

但是当我运行它时,男性尺寸很好但如果用户输入女性,则没有错误,但没有显示消息框。

1 个答案:

答案 0 :(得分:1)

您不需要两个Select Case Gender.ToUpper;并且Case "M" To "F"应该是Case "M"您还需要End Select进行内部选择。我不会为你重写你的代码,但是这里有一些伪代码可以让你走上正确的轨道:

Select Case Gender.ToUpper
    Case "M":
        Select Case Foot
            ....
        End Select
    Case "F":
        Select Case Foot
            ....
        End Select
End Select