case 语句为真但不执行 true case 条件下的代码

case statement is true but the code under the true case condition is not executed

我有一个包含组合框的应用程序。在这些组合框中,我希望单位自动填充。我已经构建了一个代码,其中有 select..case 条件。 case 语句为 true,但不执行 true case 语句后面的代码。我已经通过断点分析过了,也显示了True但是没有执行,跳到最后。请指教

Private Sub Load_units_combo_boxes()

    Dim ComboBoxes As New ArrayList

    For Each ComboBox In Me.Controls
        If ComboBox.Name.Contains("Units") And TypeOf ComboBox Is ComboBox Then
            ComboBoxes.Add(ComboBox)
        End If
    Next

    For Each ComboBox In ComboBoxes
        Select Case ComboBox.name.ToString
            Case ComboBox.name.ToString.Contains("Pressure")
                For Each unit In _units
                    If unit.contains("Pressure") Then
                        unit.replace("Pressure", "")
                        ComboBox.items.add(unit)
                    End If
                Next

            Case ComboBox.name.ToString.Contains("Distance")
                For Each unit In _units
                    If unit.contains("Distance") Then
                        unit.replace("Distance", "")
                        ComboBox.items.add(unit)
                    End If
                Next
        End Select
    Next

End Sub

Public _units As New ArrayList

Private Sub units_collection()

    Dim units As New Units_and_conversions
    Dim properties = units.GetType().GetProperties()

    For Each prop In properties
        _units.Add(prop.Name)
    Next


End Sub

Public Class Units_and_conversions

Private universal_distance_unit As Double = 1
Private universal_pressure_unite As Double = 1


Public Property Distance_Meter() As Double
    Get
        Return universal_distance_unit
    End Get
    Set(value As Double)
        value = universal_distance_unit
    End Set
End Property

Public Property Distance_MilliMeter() As Double

    Get
        Return 0.001 * universal_distance_unit
    End Get
    Set(value As Double)
        value = 0.001 * universal_distance_unit

    End Set
End Property

结束Class

此代码失败。

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 
 Button1.Click

    Dim s As String = "abcdefghijklmnopqrstuvwxyz"

    Select Case s
        Case s.Contains("g")
            MsgBox("Case Select Fails")
    End Select

    If s.Contains("g") Then
        MsgBox("If statement works")
    End If

End Sub

"Case Select" 未设置为布尔问题,因此失败。以下代码将起作用。

此代码有效

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 
  Button1.Click

    Dim s As String = "abcdefghijklmnopqrstuvwxyz"

    Select Case True
        Case s.Contains("g")
            MsgBox("Case Select Works")
    End Select

    If s.Contains("g") Then
        MsgBox("If statement works")
    End If
End Sub

此代码有效,因为该问题已正确设置为布尔问题而不是字符串比较。