Я пытаюсь написать мое содержимое моего массива в файл. Его массив как структура. Кажется, у меня проблема. Кажется, я не могу прочитать файл после его написания. Приложение зависает, и если я проверю, есть ли у моего txt-файла какая-либо информация в нем, он также блокируется.Запись содержимого массива в файл VB
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Structure Person
Public strName As String
Public dblHeight As Double
Public dblWeight As Double
End Structure
Private peopleDescription(49) As Person
Dim count As Integer = 0
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
If count <= 49 Then
peopleDescription(count).strName = txtName.Text
Double.TryParse(txtHeight.Text, peopleDescription(count).dblHeight)
Double.TryParse(txtWeight.Text, peopleDescription(count).dblWeight)
count += 1
End If
txtName.Text = String.Empty
txtHeight.Text = String.Empty
txtWeight.Text = String.Empty
txtName.Focus()
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim outFile As IO.StreamWriter
Dim intC As Integer
outFile = IO.File.AppendText("persons.txt")
Do While intC < count
outFile.WriteLine(peopleDescription(intC))
Loop
outFile.Close()
End Sub
Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click
Dim inFile As IO.StreamReader
Dim strInfo As String
If IO.File.Exists("persons.txt") Then
inFile = IO.File.OpenText("persons.txt")
Do Until inFile.Peek = -1
strInfo = inFile.ReadLine
Loop
inFile.Close()
lblMessage.Text = strInfo
Else
MessageBox.Show("Can't find the persons.txt file", "Person Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
Я не знаю, чего у меня нет. Если кто-то может помочь, я был бы признателен.
Wow lol Я не могу поверить, что пропустил это. Всегда хорошо иметь вторую пару глаз спасибо! – VinceCat