Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

File already open?

$
0
0
Imports System.IO

Public Class addCustomer
    Dim intCusNumbers As Integer = 0
    Dim boolAgeVerified As Boolean
    Dim intAgeVerify As Integer


    Sub cusDetailsArrayAdd()
        FileReader = New StreamReader(customersTxt)

        intCusNumbers = FileReader.ReadLine
        ReDim strCusArray(intCusNumbers)

        For intCounter = 1 To intCusNumbers
            strCusArray(intCusNumbers).strCusNum = FileReader.ReadLine
            strCusArray(intCounter).strFirstName = FileReader.ReadLine
            strCusArray(intCounter).strLastName = FileReader.ReadLine
            strCusArray(intCounter).intAge = FileReader.ReadLine
            strCusArray(intCounter).strAddress = FileReader.ReadLine
            strCusArray(intCounter).strTown = FileReader.ReadLine
            strCusArray(intCounter).strPostcode = FileReader.ReadLine
            strCusArray(intCounter).strCusNum = FileReader.ReadLine
        Next

        FileReader.Close()
    End Sub
    Sub AddCustomers()

        FileWriter = New StreamWriter(customersTxt)

        Call increaseCusArray()

        Call AddRecsToFile()

        FileWriter.Close()

    End Sub
    Sub increaseCusArray()
        Dim customerID As Guid = Guid.NewGuid()

        intCusNumbers = intCusNumbers + 1



        ReDim Preserve strCusArray(intCusNumbers)

        strCusArray(intCusNumbers).strCusNum = intCusNumbers
        strCusArray(intCusNumbers).strFirstName = txtFirstName.Text
        strCusArray(intCusNumbers).strLastName = txtLastName.Text
        strCusArray(intCusNumbers).intAge = txtAge.Text
        strCusArray(intCusNumbers).strAddress = txtAddress.Text
        strCusArray(intCusNumbers).strTown = txtTown.Text
        strCusArray(intCusNumbers).strPostcode = txtPost.Text



    End Sub
    Sub AddRecsToFile()

        FileWriter.WriteLine(intCusNumbers)

        For intCounter = 1 To intCusNumbers
            FileWriter.WriteLine(strCusArray(intCounter).strCusNum)
            FileWriter.WriteLine(strCusArray(intCounter).strFirstName)
            FileWriter.WriteLine(strCusArray(intCounter).strLastName)
            FileWriter.WriteLine(strCusArray(intCounter).intAge)
            FileWriter.WriteLine(strCusArray(intCounter).strAddress)
            FileWriter.WriteLine(strCusArray(intCounter).strTown)
            FileWriter.WriteLine(strCusArray(intCounter).strPostcode)

        Next
    End Sub

    
    Private Sub btnCreateAcc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateAcc.Click
        intAgeVerify = txtAge.Text

        If intAgeVerify <= 5 Then
            MsgBox("Unfortunately this customer isn't old enough to view this performance.")
            btnCreateAcc.Enabled = False
            boolAgeVerified = False

        Else
            Call AddCustomers()
            MsgBox("Account Created. Customer Account number is: ")
            Me.Close()
            Customers.Visible = True
        End If



    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
        Customers.Visible = True
    End Sub

    Private Sub addCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Computer.FileSystem.FileExists("customers.txt") = True Then
            Call cusDetailsArrayAdd()
        End If
    End Sub
End Class


Here is a customer registration form that works when adding customers. However if you close that form and return to the main menu and then reopen it and add another customer, it says that the file is being used by another process but i can't see why.

The streamreader/writer are declared in my module.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>