码迷,mamicode.com
首页 > 其他好文 > 详细

VB 删除txt文件的最后一行

时间:2017-07-14 21:16:03      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:ring   err   txt   error   goto   pen   string   exit   efi   

Private Sub Command1_Click()
DelTxt App.Path & "\1.txt"
End Sub
Sub DelTxt(ByVal Path As String) ‘删除txt文件的最后一行
On Error GoTo eHandler:
Dim Fc As String, Fn() As String, I As Integer, Wjh As Integer
Wjh = FreeFile
Open Path For Binary As #Wjh
Fc = Space(LOF(Wjh))
Get #Wjh, , Fc
Close #Wjh
Fn = Split(Fc, vbCrLf)
ReDim Preserve Fn(UBound(Fn) - 1)
If UBound(Fn) <= 0 Then
Open Path For Output As #Wjh
Print vbNullString
Close #Wjh
Else
ReDim Preserve Fn(UBound(Fn) - 1)
Open Path For Output As #Wjh
For I = 0 To UBound(Fn)
Print #Wjh, Fn(I)
Next
Close #Wjh
End If
Exit Sub
eHandler:
Err.Clear
End Sub

VB 删除txt文件的最后一行

标签:ring   err   txt   error   goto   pen   string   exit   efi   

原文地址:http://www.cnblogs.com/zgwxm/p/7172078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!