新建From1(窗体),代码:
Public Function ReadText(ByVal szFileName As String) As String
Dim szTextCodes As String
Open szFileName For Binary As #1
szTextCodes = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
ReadText= szTextCodes
End Function
Public Sub SaveText(ByVal szFileName As String, ByVal sz As String)
On Error Resume Next
Open szFileName For Output As #1
Print #1, sz
Close #1
End Sub
Public Function ReadBin(ByVal strFileName As String, Optional ByVal lngStartPos As Long = 1, Optional ByVal lngFileSize As Long = -1) As Byte()
On Error Resume Next
Dim FilNum As Integer
FilNum = FreeFile
Open strFileName For Binary As #FilNum
If lngFileSize = -1 Then
ReDim ReadBin(LOF(FilNum) - lngStartPos)
Else
ReDim ReadBin(lngFileSize - 1)
End If
Get #FilNum, lngStartPos, ReadBin
Close #FilNum
End Function
Public Function SaveBin(ByVal strFileName As String, bytData() As Byte, Optional ByVal lngStartPos As Long = -1, Optional ByVal OverWrite As Boolean = True)
On Error Resume Next
Dim FilNum As Integer
FilNum = FreeFile
If OverWrite = True And Dir(strFileName) <> "" Then
Kill strFileName
End If
Open strFileName For Binary As #FilNum
If lngStartPos = -1 Then
Put #FilNum, LOF(FilNum) + 1, bytData
Else
Put #FilNum, lngStartPos, bytData
End If
Close #FilNum
End Function