FileNum = FreeFile
Open fn For Output Access Write As #FileNum
OpenWrit = True
Exit Function
OWErr:
OpenWrit = False
End Function
' 打开文件用于读
Public Function OpenRead(fn As String) As Boolean
On Error GoTo ORErr
FileNum = FreeFile
Open fn For Input Access Read As #FileNum
OpenRead = True
Exit Function
ORErr:
OpenRead = False
End Function
' 关闭文件
Public Sub CloseFile()
If FileNum > 0 Then
Close #FileNum
FileNum = 0
End If
End Sub
' 从文件中读取一行
Public Function GetLine(S As String) As Boolean
On Error GoTo NotGet
If EOF(FileNum) Then GoTo NotGet
Line Input #FileNum, S
GetLine = True
Exit Function
NotGet:
GetLine = False
End Function
' 往文件中写入一行
Public Function PutLine(Byval S As String) As Boolean
On Error GoTo NotPut
Print #FileNum, S
PutLine = True
Exit Function
NotPut:
PutLine = False
End Function
' 类在结束时,自动关闭文件
Private Sub Class_Terminate()