图片附件: 游客没有浏览图片的权限,请
登录 或
注册
BAS代码如下:
程序代码:
Option Explicit
Public ErrorCount As Long
Public ErrorData() As String
Public iCount As Long
Public Declare Function QueryPerformanceCounter Lib "kernel32" (x As Currency) As Boolean
Public Declare Function QueryPerformanceFrequency Lib "kernel32" (x As Currency) As Boolean
Public Function UNIX2Dos(FileName As String) As String
Dim FileNum1 As Integer, FileNum2 As Integer, i As Long
Dim TempString As Byte, newFileName As String
On Error GoTo ErrorHandling
iCount = 0
newFileName = Mid(FileName, 1, InStrRev(FileName, ".") - 1) & "_new1.log"
FileNum1 = FreeFile: FileNum2 = FreeFile + 1
Open newFileName For Binary Access Write As #FileNum2
Open FileName For Binary Access Read As #FileNum1
Do While Not EOF(FileNum1)
Get #FileNum1, , TempString
If TempString = 10 Then
Put #FileNum2, , CByte(Val(13))
Put #FileNum2, , CByte(Val(10))
Else
Put #FileNum2, , CByte(Val(TempString))
End If
iCount = iCount + 1
DoEvents
Loop
Close #FileNum1, #FileNum2
UNIX2Dos = newFileName
Exit Function
ErrorHandling:
'Call ErrorWriteBuff(FileName, iCount, "TransformFile", Err.Number, Err.Description, "系統訊息")
Resume Next
End Function
Public Function UNIX2Dos2(FileName As String) As String
Dim FileNum1 As Integer, FileNum2 As Integer, i As Long
Dim TempString As Byte, newFileName As String
On Error GoTo ErrorHandling
iCount = 0
newFileName = Mid(FileName, 1, InStrRev(FileName, ".") - 1) & "_new2.log"
FileNum2 = FreeFile
Open newFileName For Binary Access Write As #FileNum2
FileNum1 = FreeFile '前面产生的文件号,打开了文件后,就可以继续使用这个函数来取下一个未使用的文件号了。
'你前面使用 +1 的办法,在极端的情况下可能导致错误。
Open FileName For Binary Access Read As #FileNum1
Do While Not EOF(FileNum1)
Get #FileNum1, , TempString
If TempString = 10 Then
'Put #FileNum2, , CByte(Val(10))
'Put #FileNum2, , CByte(Val(13))
Put #FileNum2, , vbCrLf '使用常量 ,VBcrlf 就代表 chr(10)+chr(13)
Else
'Put #FileNum2, , CByte(Val(TempString))
Put #FileNum2, , TempString '这个变量本身是 BYTE 类型的,直接写入就可以,为什么要再用 函数转格式??
End If
iCount = iCount + 1
DoEvents
Loop
Close #FileNum1, #FileNum2
UNIX2Dos2 = newFileName
Exit Function
ErrorHandling:
'Call ErrorWriteBuff(FileName, iCount, "TransformFile", Err.Number, Err.Description, "系統訊息")
Resume Next
End Function
Public Function UNIX2Dos3(FileName As String) As String
Dim FileNum1 As Integer, FileNum2 As Integer, i As Long
Dim TempString(511) As Byte, newFileName As String
Dim j As Long
On Error GoTo ErrorHandling
iCount = 0
newFileName = Mid(FileName, 1, InStrRev(FileName, ".") - 1) & "_new3.log"
FileNum2 = FreeFile
Open newFileName For Binary Access Write As #FileNum2
FileNum1 = FreeFile
Open FileName For Binary Access Read As #FileNum1
j = LOF(FileNum1)
Do While Not EOF(FileNum1)
'Get #FileNum1, , TempString
'TempString = Input(512, #FileNum1)
Get #FileNum1, , TempString
For i = 0 To 511
If TempString(i) = 10 Then
Put #FileNum2, , vbCrLf
Else
Put #FileNum2, , TempString(i)
End If
iCount = iCount + 1
If j = iCount Then Exit For
Next i
DoEvents
Loop
Close #FileNum1, #FileNum2
UNIX2Dos3 = newFileName
Exit Function
ErrorHandling:
' Call ErrorWriteBuff(FileName, iCount, "TransformFile", Err.Number, Err.Description, "系統訊息")
Resume Next
End Function
Public Function UNIX2Dos4(FileName As String) As String
Dim FileNum1 As Integer, FileNum2 As Integer, i As Long
Dim TempString(4095) As Byte, newFileName As String
Dim j As Long
On Error GoTo ErrorHandling
iCount = 0
newFileName = Mid(FileName, 1, InStrRev(FileName, ".") - 1) & "_new4.log"
FileNum2 = FreeFile
Open newFileName For Binary Access Write As #FileNum2
FileNum1 = FreeFile
Open FileName For Binary Access Read As #FileNum1
j = LOF(FileNum1)
Do While Not EOF(FileNum1)
'Get #FileNum1, , TempString
'TempString = Input(512, #FileNum1)
Get #FileNum1, , TempString
For i = 0 To 4095
If TempString(i) = 10 Then
Put #FileNum2, , vbCrLf
Else
Put #FileNum2, , TempString(i)
End If
iCount = iCount + 1
If j = iCount Then Exit For
Next i
DoEvents
Loop
Close #FileNum1, #FileNum2
UNIX2Dos4 = newFileName
Exit Function
ErrorHandling:
' Call ErrorWriteBuff(FileName, iCount, "TransformFile", Err.Number, Err.Description, "系統訊息")
Resume Next
End Function