我的代码再次出现问题,它无法在VB.net中运行(Exception Unhandled)

时间:2018-02-09 14:16:49

标签: vb.net

Public Class Form1
    Dim area As Integer
    Dim gauge As String
    Dim cost As Decimal
    Dim Length, Width, Depth, CostNo As Decimal
    Dim CostNa, combo As String
    Dim ErrorFlag As Boolean
    Dim D1 As String
    Private Sub Area2_Click(sender As Object, e As EventArgs) Handles Area2.Click
        Length = txtLength.Text
        Width = txtWidth.Text
        Depth = txtDepth.Text
        CostNo = CostumerNo.Text
        CostNa = CostumerName.Text


        ErrorFlag = ErrorLook(Width, Length, Depth)
        If ErrorFlag = False Then
            MsgBox("Invalid")
            Reset()
            txtDepth.Text = ""
            txtLength.Text = ""
            txtWidth.Text = ""
            CostumerName.Text = ""
            CostumerNo.Text = ""
            Result.Text = ""
            output.Text = ""
            A2.Text = ""
            G1.Text = ""
            C1.Text = ""
        ElseIf ErrorFlag = True Then
            MsgBox("u Good")


        End If
        Length = L(Width)
        Width = W(Length)
        A2.Text = a(Width, Length)
        G1.Text = g(gauge)
        C1.Text = c(cost)

        FileOpen(1, "Info1.txt", OpenMode.Append)
        PrintLine(1, Result.Text & " " & CostumerName.Text & " " & CostumerNo.Text & " " & A2.Text & " " & G1.Text & " " & C1.Text)
        FileClose(1)



        FileOpen(1, "Info1.Text", OpenMode.Input)
        While Not EOF(1)
            Result.Text = LineInput(1)
        End While


    End Sub



    Function combo1() As String

    End Function
    Const Cost1 As Decimal = 1.12
    Const Cost2 As Decimal = 1.76
    Public Function c(ByVal cost As Decimal) As String
        If G1.Text = "Gauge1" Then
            Return A2.Text * Cost1
        Else
            Return A2.Text * Cost2
        End If
    End Function

    Public Function g(ByVal gauge As String) As String
        If A2.Text <= 100 Then
            Return "Gauge1"
        Else
            Return "Gauge2"
        End If
    End Function
    'sets the boundaries for the input values
    Public Function ErrorLook(ByVal w As Decimal, ByVal l As Decimal, ByVal d As Decimal) As Boolean
        If l < 1 Or l > 10 Then
            Return False
        Else
            Return True
        End If
        If w < 1 Or w > 10 Then
            Return False
        Else
            Return True
        End If
        If d < 1 Or d > 10 Then
            Return False
        Else
            Return True
        End If

    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
    'calculates the area
    Public Function a(ByVal w As Decimal, ByVal l As Decimal) As Decimal
        Dim area2 As Decimal
        area2 = w * l
        Return area2
    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 = ""
        A2.Text = ""
        G1.Text = ""
        C1.Text = ""
    End Sub
End Class

1 个答案:

答案 0 :(得分:-1)

看看&#39; ErrorLook&#39;功能。它做的第一件事是布尔测试,它将返回true或false。为什么你得到&#34;如果w&lt; 1&#34; e.t.c或&#34;如果d&lt; 1&#34; e.t.c,它永远不会到达他们.....我可以继续...... 你在没有检查的情况下获得了小数字的字符串......你在不知道它们是数字的情况下对字符串进行计算...... 想想你想做什么。首先,停止使用VB6代码并尝试理解逻辑,也许你需要从头开始。