VB 如何删除文本文件的最后一行 5
3个回答
展开全部
'添加按钮Command1,同时在C盘根目录放个文件c:\test.txt,然后添加下面代码
Private Sub Command1_Click()
Dim strContent$, l&
Open "c:\test.txt" For Input As #1
strContent = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
strContent = Left(strContent, InStrRev(strContent, vbCrLf) - 1)
Open "c:\test.txt" For Output As #1
Print #1, strContent
Close #1
MsgBox "处理完毕!"
End Sub
Private Sub Command1_Click()
Dim strContent$, l&
Open "c:\test.txt" For Input As #1
strContent = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
strContent = Left(strContent, InStrRev(strContent, vbCrLf) - 1)
Open "c:\test.txt" For Output As #1
Print #1, strContent
Close #1
MsgBox "处理完毕!"
End Sub
TableDI
2024-07-18 广告
2024-07-18 广告
在上海悉息信息科技有限公司,我们深知Excel在数据处理中的重要作用。在Excel中引用不同工作表(sheet)的数据是常见的操作,这有助于整合和分析跨多个工作表的信息。通过在工作表名称前加上感叹号“!”,您可以轻松地引用其他工作表中的数据...
点击进入详情页
本回答由TableDI提供
展开全部
用正则表达式的替换方法!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
F "c:\abc.txt"
End Sub
Sub F(ByVal Path As String)
On Error GoTo eHandler:
Dim Fc As String, Fn() As String, i As Integer
Open Path For Binary As #1
Fc = Space(LOF(1))
Get #1, , Fc
Close #1
Fn = Split(Fc, vbCrLf)
Do Until Fn(UBound(Fn)) <> ""
ReDim Preserve Fn(UBound(Fn) - 1)
DoEvents
Loop
If UBound(Fn) <= 0 Then
Open Path For Output As #1
Print vbNullString
Close #1
Else
ReDim Preserve Fn(UBound(Fn) - 1)
Open Path For Output As #1
For i = 0 To UBound(Fn)
Print #1, Fn(i)
Next
Close #1
End If
Exit Sub
eHandler:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & Chr(13) & Err.Description, vbCritical, "Error", Err.HelpFile, Err.HelpContext
Err.Clear
End Sub
Private Sub Form_Resize()
Form1.WindowState = 2
Command1.Left = (Form1.Width - Command1.Width) / 2
Command1.Top = Form1.Height / 2
End Sub
F "c:\abc.txt"
End Sub
Sub F(ByVal Path As String)
On Error GoTo eHandler:
Dim Fc As String, Fn() As String, i As Integer
Open Path For Binary As #1
Fc = Space(LOF(1))
Get #1, , Fc
Close #1
Fn = Split(Fc, vbCrLf)
Do Until Fn(UBound(Fn)) <> ""
ReDim Preserve Fn(UBound(Fn) - 1)
DoEvents
Loop
If UBound(Fn) <= 0 Then
Open Path For Output As #1
Print vbNullString
Close #1
Else
ReDim Preserve Fn(UBound(Fn) - 1)
Open Path For Output As #1
For i = 0 To UBound(Fn)
Print #1, Fn(i)
Next
Close #1
End If
Exit Sub
eHandler:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & Chr(13) & Err.Description, vbCritical, "Error", Err.HelpFile, Err.HelpContext
Err.Clear
End Sub
Private Sub Form_Resize()
Form1.WindowState = 2
Command1.Left = (Form1.Width - Command1.Width) / 2
Command1.Top = Form1.Height / 2
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询