7,763
社区成员
发帖
与我相关
我的任务
分享
Private Sub Command1_Click()
MsgBox Replace(getchar(GetFileLastLine(App.Path & "\9056_020.csv"), ",", 3, 4), "Operation=", "")
End Sub
Function GetFileLastLine(fName As String) As String
Dim hFile As Long
Dim recNumber1 As Long, recNumber2 As Long
Dim Char As String * 1
Dim strTmp As String
recNumber2 = FileLen(fName)
hFile = FreeFile
Open fName For Binary As hFile
Do
Get #hFile, recNumber2, Char
recNumber2 = recNumber2 - 1
Loop Until Char Like "[0-9a-zA-Z]"
recNumber1 = recNumber2
Do
Get #hFile, recNumber1, Char
recNumber1 = recNumber1 - 1
Loop Until Char = vbCr Or Char = vbLf
strTmp = Space(recNumber2 - recNumber1 + 1)
Get #hFile, recNumber1 + 1, strTmp
Close
GetFileLastLine = strTmp
End Function
Private Function getchar(mstr As String, charx As String, bofnum As Integer, eofnum As Integer) As String
Dim x As Integer, strartnum As Integer, endnum As Integer
For i = 1 To Len(mstr)
If x = eofnum Then Exit For
If Mid(mstr, i, 1) = charx Then
x = x + 1
If x = bofnum Then
strartnum = i
ElseIf x = eofnum Then
endnum = i
End If
End If
Next i
getchar = Mid(mstr, strartnum + 1, endnum - strartnum - 1)
End Function
Function GetFileLastLine(fName As String) As String
Dim hFile As Long,strTmp As String,Arr() As string,I As Long
hFile = FreeFile
Open fName For Binary As hFile
strTmp=Space(LOF(hFile))
Get #hFile,,strTmp
Close #hFile
Arr=Split(strTmp,vbCrLf)
For I=Ubound(Arr) To 1 Step -1
if Len(Arr(i))>0 Then Exit For
Next
GetFileLastLine = Arr(I)
End Function