客户账户计划

时间:2015-11-15 22:33:58

标签: visual-studio-2012

我已经构建了一个程序,允许用户搜索客户或添加与该客户相关的各种信息的新用户。但是,当我运行该程序时,我收到一条错误消息,指出在附加到电话号码的Microsoft.VisualBasic.dll中发生了类型为“System.OverflowException”的未处理异常。我不确定我在这里做错了什么。 我的代码:

Imports System.IO
Public Class Form1
Dim txtFile As StreamWriter ' object variable
Dim searchFile As StreamReader ' object variable

' structure declaration
Structure CustomerAccounts
    Dim Records As StreamReader
    Dim LastName As String
    Dim FirstName As String
    Dim CustomerNumber As String
    Dim Address As String
    Dim City As String
    Dim State As String
    Dim ZIPCode As Integer
    Dim TelephoneNumber As Int64
    Dim AccountBalance As Double
    Dim DateOfLastPayment As String
End Structure

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub SaveCtrlSToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveCtrlSToolStripMenuItem.Click
    Dim CustomerRecord As CustomerAccounts ' Structure Variable
    ' Assigning data to structure variable
    CustomerRecord.LastName = txtLast.Text
    CustomerRecord.FirstName = txtFirst.Text
    CustomerRecord.CustomerNumber = txtNumber.Text
    CustomerRecord.Address = txtAddress.Text
    CustomerRecord.City = txtCity.Text
    CustomerRecord.State = txtState.Text
    CustomerRecord.ZIPCode = CInt(txtZIPCode.Text)
    CustomerRecord.TelephoneNumber = CInt(txtTelephone.Text)
    CustomerRecord.AccountBalance = CDbl(txtAccountBalance.Text)
    While CustomerRecord.AccountBalance < 0
        CustomerRecord.AccountBalance = CDbl(InputBox("Please enter a non-negative balance"))
    End While
    CustomerRecord.DateOfLastPayment = CDate(txtPayment.Text)
    ' Opening a file in append mode
    txtFile = File.CreateText("Records.txt")
    ' Writing data to a file
    txtFile.WriteLine(CustomerRecord.LastName)
    txtFile.WriteLine(CustomerRecord.FirstName)
    txtFile.WriteLine(CustomerRecord.CustomerNumber)
    txtFile.WriteLine(CustomerRecord.Address)
    txtFile.WriteLine(CustomerRecord.City)
    txtFile.WriteLine(CustomerRecord.State)
    txtFile.WriteLine(CustomerRecord.ZIPCode)
    txtFile.WriteLine(CustomerRecord.TelephoneNumber)
    txtFile.WriteLine(CustomerRecord.AccountBalance)
    txtFile.WriteLine(CustomerRecord.DateOfLastPayment)
    txtFile.Close() ' Close the data file after writing the data
    clearFields()
End Sub

Private Sub ExitCtrlQToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitCtrlQToolStripMenuItem.Click
    ' Close the form
    Me.Close()
End Sub

Private Sub SearchToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles SearchToolStripMenuItem1.Click
    ' Open a file in read mode 
    searchFile = File.OpenText("Records.Txt")
    Dim lastName As String
    Dim flag As Integer
    flag = 0

    ' get the record name from user input
    lastName = InputBox("Please enter the last name to search")
    Dim CSearchRecord As CustomerAccounts
    Try
        While Not searchFile.EndOfStream
            CSearchRecord.LastName = searchFile.ReadLine()
            CSearchRecord.FirstName = searchFile.ReadLine()
            CSearchRecord.CustomerNumber = searchFile.ReadLine()
            CSearchRecord.Address = searchFile.ReadLine()
            CSearchRecord.City = searchFile.ReadLine()
            CSearchRecord.State = searchFile.ReadLine()
            CSearchRecord.ZIPCode = searchFile.ReadLine()
            CSearchRecord.TelephoneNumber = searchFile.ReadLine()
            CSearchRecord.AccountBalance = searchFile.ReadLine()
            CSearchRecord.DateOfLastPayment = searchFile.ReadLine()

            ' Compare current record with search record
            If CSearchRecord.LastName.Equals(lastName) Then
                flag = 1
                Exit While
            End If
        End While
        ' If record found display txt fields
        If flag.Equals(1) Then
            txtLast.Text = CSearchRecord.LastName.ToString()
            txtFirst.Text = CSearchRecord.FirstName.ToString()
            txtNumber.Text = CSearchRecord.CustomerNumber.ToString()
            txtAddress.Text = CSearchRecord.Address.ToString()
            txtCity.Text = CSearchRecord.City.ToString()
            txtState.Text = CSearchRecord.City.ToString()
            txtZIPCode.Text = CSearchRecord.ZIPCode.ToString()
            txtTelephone.Text = CSearchRecord.TelephoneNumber.ToString()
            txtAccountBalance.Text = CSearchRecord.AccountBalance.ToString()
            txtPayment.Text = CSearchRecord.DateOfLastPayment.ToString()
        Else
            ' If record not found alert user
            MessageBox.Show("Record Not Found")
            clearFields()
        End If
    Catch ex As Exception

    End Try
End Sub

Private Sub ReportToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ReportToolStripMenuItem1.Click
    Dim report As String
    report = "Report of Customer Accounts" + vbNewLine
    ' Open file in read mode
    searchFile = File.OpenText("Record.txt")
    Try
        ' Reading the file until end
        While Not searchFile.EndOfStream
            report += searchFile.ReadLine() + " "
            report += searchFile.ReadLine() + " "
            report += searchFile.ReadLine() + " "
            report += searchFile.ReadLine() + " "
            report += vbNewLine
        End While
    Catch ex As Exception
    End Try
    ' Display file Content as report
    MessageBox.Show(report)
End Sub
Private Sub clearFields()
    txtAccountBalance.Clear()
    txtAddress.Clear()
    txtCity.Clear()
    txtFirst.Clear()
    txtLast.Clear()
    txtNumber.Clear()
    txtPayment.Clear()
    txtState.Clear()
    txtTelephone.Clear()
    txtZIPCode.Clear()
End Sub
End Class

任何提供的帮助将不胜感激。我只需要知道如何解决这个问题。

0 个答案:

没有答案