vba中的错误标志已损坏

时间:2018-02-07 09:47:14

标签: vb.net

所以,我有一个问题,当我输入错误的输入数据或正确的输入数据时,无论输入如何,消息框每次都显示相同的信息。现在,我知道这必须对我的错误标志做一些事情,但我无法找到它背后的问题。

<select name="type">
    @foreach($options as $key => $text)
        <option @if((int) old('type', $selectedOption) === $key) selected @endif value="{{ $key }}">{{ $text }}</option>
    @endforeach
</select>

1 个答案:

答案 0 :(得分:0)

问题是函数ErrorLook总是返回字符串"False",因为返回变量FlagError但从未设置为"True"。而是设置变量ErrorFlag。而且,你无法使用参数(w,l和d)。
(这同样适用于您的所有功能。)

您可以更改下面的功能,它应该可以正常工作。

Public Function ErrorLook() As String
    If txtLength.Text < 1 Or txtLength.Text > 10 Then Return "True"
    If txtWidth.Text < 1 Or txtWidth.Text > 10 Then Return "True"
    If txtDepth.Text < 1 Or txtDepth.Text > 2 Then Return "True"

    Return "False"
End Function

但是, 您应该使用Boolean而不是字符串,就像评论中已经提到的那样。

此外,您需要检查文本框的内容是否为数字。
呼叫和功能如下所示:

Private Sub Area2_Click(sender As Object, e As EventArgs) Handles Area2.Click
    Decimal.TryParse(txtLength.Text, Length)
    Decimal.TryParse(txtWidth.Text, Width)
    Decimal.TryParse(txtDepth.Text, Depth)

    If ErrorLook(Length, Width, Depth) Then
        MsgBox("Invalid")
    ElseIf ErrorFlag = False Then
        MsgBox("u Good")
    End If
    ...
End Sub

Public Function ErrorLook(ByVal w As Decimal,
                          ByVal l As Decimal,
                          ByVal d As Decimal) As Boolean

    Return w < 1 OrElse
           w > 10 OrElse
           l < 1 OrElse
           l > 10 OrElse
           d < 1 OrElse
           d > 2
End Function