我的代码再次存在问题,并且它在vb.net中无法使用(未经治疗的例外)

  • 本文关键字:net 存在 问题 代码 vb 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

查看'错误looke'函数。它要做的第一件事是布尔测试,它将返回真或错。为什么您会得到"如果w&lt; 1" e.t.c或"如果d&lt; 1" e.t.c,它永远不会得到他们.....我可以继续.....您正在不检查的情况下将字符串纳入小数...您正在对字符串进行计算,而不知道它们是否是数字...想想您要做的是什么。首先,停止使用VB6代码并尝试理解逻辑,也许您需要从头开始。

相关内容

最新更新