Vb.net vba中的错误标志已断开

Vb.net vba中的错误标志已断开,vb.net,Vb.net,因此,我有一个问题,当我输入错误的输入数据或正确的输入数据时,无论输入是什么,消息框每次都会显示相同的信息。现在,我知道这与我的错误标志有关,但我找不到它背后的问题 Public Class Form1 Dim area As Integer Dim Length As Decimal Dim Width As Decimal Dim Depth As Decimal Dim CostNo As Integer Dim CostNa As Stri

因此,我有一个问题,当我输入错误的输入数据或正确的输入数据时,无论输入是什么,消息框每次都会显示相同的信息。现在,我知道这与我的错误标志有关,但我找不到它背后的问题

Public Class Form1
    Dim area As Integer
    Dim Length As Decimal
    Dim Width As Decimal
    Dim Depth As Decimal
    Dim CostNo As Integer
    Dim CostNa As String
    Dim combo As String
    Dim ErrorFlag As String

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

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

        'getting input from the costumer number text box
        'CostNo = CostumerNo.Text
        'getting input from the costumer name text box
        'CostNa = CostumerName.Text
        'store the names together as a new variable
        'combo = CostNo & " " & CostNa

        'displays the full name in the third text box
        Result.Text = combo & " " & "Area " & a(Width, Length)
    End Sub
    'sets the boundaries for the input values
    Public Function ErrorLook(ByVal w As Decimal, ByVal l As Decimal, ByVal d As Decimal) As String
        Dim FlagError As String
        FlagError = "False"
        If txtLength.Text < 1 Or txtLength.Text > 10 Then ErrorFlag = "True"
        If txtWidth.Text < 1 Or txtWidth.Text > 10 Then ErrorFlag = "True"
        If txtDepth.Text < 1 Or txtDepth.Text > 2 Then ErrorFlag = "True"
        Return FlagError
    End Function
    'calculates the area
    Public Function a(ByVal w As Decimal, ByVal l As Decimal) As String
        Dim area2 As Decimal
        area2 = Width * Length
        Return area2
    End Function
    'calculates the width
    Public Function L(ByVal W As Decimal) As Decimal
        Width = txtWidth.Text + (2 * txtDepth.Text)
        Return Width
    End Function
    'calculates the length
    Public Function W(ByVal L As Decimal) As Decimal
        Length = txtLength.Text + (2 * txtDepth.Text)
        Return Length
    End Function
    'displays the date and time of the system it is eing run from
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        lbTime.Text = Now()
    End Sub

    'the clear button for clearing all of the fields
    Private Sub CA_Click(sender As Object, e As EventArgs) Handles CA.Click
        Reset()
        txtDepth.Text = ""
        txtLength.Text = ""
        txtWidth.Text = ""
        CostumerName.Text = ""
        CostumerNo.Text = ""
        Result.Text = ""
        output.Text = ""
    End Sub
End Class
公共类表单1
暗区为整数
十进制长度
十进制宽度
以十进制表示的暗深度
Dim CostNo作为整数
暗科斯特纳为弦
作为字符串的Dim组合
Dim ErrorFlag作为字符串
私有子区域2\u单击(发送者作为对象,e作为事件参数)处理区域2。单击
长度=txtLength.Text
宽度=txtWidth.Text
Depth=txtDepth.Text
ErrorFlag=ErrorLook(长度、宽度、深度)
如果ErrorFlag=“True”,则
MsgBox(“无效”)
ElseIf ErrorFlag=“False”则
MsgBox(“u良好”)
如果结束
'从客户编号文本框中获取输入
'CostNo=customerno.Text
'从客户名称文本框中获取输入
'CostNa=customerName.Text
'将名称作为新变量存储在一起
'combo=CostNo&'&CostNa
'在第三个文本框中显示全名
Result.Text=combo&“&”Area&&a(宽度、长度)
端接头
'设置输入值的边界
公共函数ErrorLook(ByVal w作为十进制,ByVal l作为十进制,ByVal d作为十进制)作为字符串
作为字符串的模糊鞭毛
flagror=“False”
如果txtLength.Text<1或txtLength.Text>10,则ErrorFlag=“True”
如果txtWidth.Text<1或txtWidth.Text>10,则ErrorFlag=“True”
如果txtDepth.Text<1或txtDepth.Text>2,则ErrorFlag=“True”
回击鞭炮
端函数
'计算面积
公共函数a(ByVal w作为十进制,ByVal l作为十进制)作为字符串
尺寸区域2为十进制
面积2=宽度*长度
返回区2
端函数
'计算宽度
公共函数L(ByVal W为十进制)为十进制
宽度=txtWidth.Text+(2*txtDepth.Text)
返回宽度
端函数
'计算长度
公共函数W(ByVal L表示十进制)表示十进制
长度=txtLength.Text+(2*txtDepth.Text)
返回长度
端函数
'显示运行它的系统的日期和时间
私有子Timer1\u Tick(发送方作为对象,e作为事件参数)处理Timer1.Tick
lbTime.Text=Now()
端接头
'用于清除所有字段的清除按钮
私有子CA_Click(发送者作为对象,e作为事件参数)处理CA。单击
重置()
txtDepth.Text=“”
txtLength.Text=“”
txtWidth.Text=“”
CustomerName.Text=“”
customerno.Text=“”
Result.Text=“”
output.Text=“”
端接头
末级

问题在于函数
ErrorLook
总是返回字符串
“False”
,因为变量
flageror
被返回,但从未设置为
“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

这是vb.net还是vba?…@CallumDA-从十进制的
判断,我投票支持vb.net。它的vba事件为vb formsvb.net驱动。很抱歉,这是一个错误。用字符串做算术总是一个坏主意。打开选项。这可能会突出一些困难。我认为您的标志应该是布尔值,但我认为这不是问题所在。我想你会想要一个退出子后,无效的消息。
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