FilePut returns unhandled exception of type 'System.ArgumentException'

147 views Asked by At

I am writing in Visual Basic on Visual Studio 2013.

I have defined the Customer record structure in a module. I am trying to save to a fixed length record. However, when I try and save it comes back highlighting FilePut with the error message:

"An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll".

My code for the subroutine is below:

    'Open customer file to find what ID to use
    FileOpen("1", "CustomerRecord.dat", OpenMode.Random, OpenAccess.ReadWrite)

    'Find length of customer file
    Dim RecordLength As Integer = Len(Customer)

    'Populate customer ID with algorithm to find unique ID to use (Last ID used + 1)
    txt_CustomerID.Text = Str(LOF(1) / RecordLength + 1)

    'Find record number to write
    Dim RecordToWrite As Integer = (LOF(1) / RecordLength + 1)

    'Populate all the customer variables with the corresponding
    'textbox information
    Customer.CusID = Int(txt_CustomerID.Text)
    Customer.Title = cmb_Title.Text
    Customer.Forename = txt_Forename.Text
    Customer.Surname = txt_Surname.Text
    Customer.Postcode = txt_Postcode.Text
    Customer.NameNo = txt_HouseName.Text
    Customer.Town = txt_Town.Text
    Customer.DOB = txt_DOB.Text
    Customer.TelNo = txt_TelNo.Text
    Customer.Email = txt_Email.Text

    FilePut("1", Customer, RecordToWrite)

    FileClose(1)

How would I solve this problem?

0

There are 0 answers