我做了一个读取和写入文件的小东西 ,但是在写入文件的时候总是把原来的给覆盖了`
我知道在写顺序文件的时候是可以加在后面的
但是我用在二进制文件的时候就不行` 我想请教各位!
下面是我的代码:
Option Explicit
Private Type Student
StuID As Integer
SName As String
Marks As Integer
Grade As String
End Type
Private Sub Command1_Click()
Dim Emp1 As Student
Dim RecordNumber As Integer
RecordNumber = 1
If TxtID.Text = "" Or TxtName.Text = "" Or TxtMark.Text = "" Or TxtGrade.Text = "" Then
MsgBox "不能为空!", 64
End If
Dim fileNumber As Long
fileNumber = FreeFile
Open App.Path & "\File.txt" For Binary As #fileNumber
Emp1.StuID = TxtID.Text
Emp1.SName = TxtName.Text
Emp1.Marks = TxtMark.Text
Emp1.Grade = TxtGrade.Text
Put #fileNumber, , Emp1
Close #fileNumber
End Sub
Private Sub Command2_Click()
Dim Emp1 As Student
Dim RecordNumber As Integer
RecordNumber = 1
Dim fileNumber As Long
fileNumber = FreeFile
Open App.Path & "\File.txt" For Binary As #fileNumber
Get #fileNumber, , Emp1
Debug.Print Emp1.StuID
Debug.Print Emp1.SName
Debug.Print Emp1.Marks
Debug.Print Emp1.Grade
Close #fileNumber
End Sub
Private Sub Command3_Click()
End
End Sub