Private Sub btnSaveToFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveToFile.Click Dim sw As New StreamWriter(New FileStream("EmployeeDetails.txt", FileMode.Create, FileAccess.Write)) For Each record As EmployeeType In employees sw.Write(record.ID & ",") sw.Write(record.FirstName & ",") sw.WriteLine(record.Salary) Next sw.Close() End Sub
but it doesn't work. My array is fixed and currently has 3 elements (for testing purposes). If I enter two records and add these to the structure I get the following data saved to the text file:
How do I stop unused elements of the array being included when writing to file? Should I use a dynamic array instead and if yes, how do you use dynamic arrays with structures?