标题:关于读取,写入二进制文件的问题
只看楼主
shiyide
Rank: 2
等 级:新手上路
威 望:4
帖 子:297
专家分:0
注 册:2006-2-22
 问题点数:0 回复次数:0 
关于读取,写入二进制文件的问题

我做了一个读取和写入文件的小东西 ,但是在写入文件的时候总是把原来的给覆盖了`
我知道在写顺序文件的时候是可以加在后面的
但是我用在二进制文件的时候就不行` 我想请教各位!
下面是我的代码:
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

搜索更多相关主题的帖子: 二进制 文件 
2006-03-17 17:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-51078-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.144151 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved