如何比较多个文本框的值

时间:2019-01-09 13:09:39

标签: vb.net

如果panel1的文本框中的值位于min_tolerance和max_tolerance文本框中的容差字段中,我如何比较panel1的文本框中的十进制值与文本框的十进制值。

Private Sub FINAL_KONTROLA(sender As Object, e As EventArgs)
    Dim EmptyTextBoxFound As Boolean = False 'Boolean flag for empty textbox 
    Dim EmptyTextBoxName As String = ""
    Dim max_x As String = max_tolerance.Text
    Dim min_x As String = min_tolerance.Text
    For Each ctl As Control In Panel1.Controls

        If TypeOf ctl Is TextBox AndAlso ctl.Visible AndAlso ctl.Text >= max_x AndAlso ctl.Text <= min_x Then
            EmptyTextBoxName = ctl.Name
            EmptyTextBoxFound = True
            ctl.Select()
            ctl.BackColor = Color.LightSalmon
            Exit For
            If EmptyTextBoxFound = True Then
                ctl.BackColor = Color.Red
                '.. do whatever you have do
            End If
        End If
    Next

End Sub

1 个答案:

答案 0 :(得分:1)

我的解决方案,谢谢

 Private Sub FINAL_KONTROLA(sender As Object, e As EventArgs)
    Dim EmptyTextBoxFound As Boolean = False 'Boolean flag for empty textbox 
    Dim EmptyTextBoxName As String = ""
    Dim max_x As Double = max_tolerance.Text
    Dim min_x As Double = min_tolerance.Text

    For Each ctl As Control In Panel1.Controls
        If TypeOf ctl Is TextBox AndAlso ctl.Visible Then
            Dim v1 As Double = ctl.Text
            If v1 >= max_x OrElse v1 <= min_x Then

                EmptyTextBoxName = ctl.Name
                EmptyTextBoxFound = True
                ctl.Select()
                ctl.Text = ""
                ctl.BackColor = Color.LightSalmon
                MsgBox("Vyznačený záznam neodpovída tolerančnímu poli",, "Chyba")
                Exit For
                If EmptyTextBoxFound = True Then
                    ctl.BackColor = Color.Red
                    '.. do whatever you have do
                End If
            End If
        End If
    Next
End Sub