Я создаю приложение с помощью приложения Windows Forms в Visual Studio на языке vb.net.Мне нужна помощь в преобразовании структуры, которую я закодировал, в двоичный файл, который, по сути, сохраняет результаты пользователя.Я не очень хороший кодер, так что извините за плохой код.
Приведенный ниже код показывает, что я создал структуру с именем saveresults
, и, нажав button1
, он должен получить содержимое двоичного файла.и отредактируйте их, чтобы получить новый результат.Когда я запускаю код, кажется, что проблема в строке FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary)
в подпрограмме saveres
.
Structure saveresults 'Structure for saving results
Dim numright As Integer
Dim numwrong As Integer
Dim totalnum As Integer
End Structure
'Subroutine aimed at getting stats saved to a text file to eventually be displayed to the user
Sub saveres(saveresults As saveresults, correct As Boolean)
saveresults.totalnum = saveresults.totalnum + 1
'Determining the contents to be saved to the binary file
If correct = True Then
saveresults.numright = saveresults.numright + 1
ElseIf correct = False Then
saveresults.numwrong = saveresults.numwrong + 1
End If
FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary)
FilePut(1, saveresults)
FileClose(1)
End Sub
'attempt at saving results to the binary file
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim correct = True
Dim results As saveresults
FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary)
FileGet(1, results)
saveres(results, correct)
FileClose(1)
End Sub
Любая помощь приветствуется.Спасибо.