vb 如何知道txt有多少行
答案:6 悬赏:50 手机版
解决时间 2021-02-20 01:47
- 提问者网友:溺爱和你
- 2021-02-19 07:10
vb 如何知道txt有多少行
最佳答案
- 五星知识达人网友:封刀令
- 2021-02-19 08:19
Private Sub Command1_Click()
Open "某个txt" For Input Access Read As #1
Do While Not EOF(1)
Line Input #1, strTxt
s = s & strTxt & vbCrLf
Loop
Close #1
a = Split(s, vbCrLf)
If UBound(a) >= 6 Then
For i = 3 To UBound(a)
st = st & a(i) & vbCrLf
Next
End If
Print st
End Sub追问哥哥啊,我说的是要删除txt中的前三行,不是print追答弟弟,你把Print的结果换成覆盖输出就OK了追问帮我写个完整得代码嘛。我给你加到100分。好吗?追答Private Sub Command1_Click()
Open "某个txt" For Input Access Read As #1
Do While Not EOF(1)
Line Input #1, strTxt
s = s & strTxt & vbCrLf
Loop
Close #1
a = Split(s, vbCrLf)
If UBound(a) >= 6 Then
For i = 3 To UBound(a)
st = st & a(i) & vbCrLf
Next
End If
Open "某个txt" For Output As #1
Print st;
Close #1
End Sub
100分就不需要了,能采纳就好
Open "某个txt" For Input Access Read As #1
Do While Not EOF(1)
Line Input #1, strTxt
s = s & strTxt & vbCrLf
Loop
Close #1
a = Split(s, vbCrLf)
If UBound(a) >= 6 Then
For i = 3 To UBound(a)
st = st & a(i) & vbCrLf
Next
End If
Print st
End Sub追问哥哥啊,我说的是要删除txt中的前三行,不是print追答弟弟,你把Print的结果换成覆盖输出就OK了追问帮我写个完整得代码嘛。我给你加到100分。好吗?追答Private Sub Command1_Click()
Open "某个txt" For Input Access Read As #1
Do While Not EOF(1)
Line Input #1, strTxt
s = s & strTxt & vbCrLf
Loop
Close #1
a = Split(s, vbCrLf)
If UBound(a) >= 6 Then
For i = 3 To UBound(a)
st = st & a(i) & vbCrLf
Next
End If
Open "某个txt" For Output As #1
Print st;
Close #1
End Sub
100分就不需要了,能采纳就好
全部回答
- 1楼网友:独钓一江月
- 2021-02-19 11:37
打开后统计下有多少换行符就知道了
- 2楼网友:轻熟杀无赦
- 2021-02-19 10:31
下面的代码可以得到文本文件的总行数
CreateObject("scripting.FileSystemObject").OpenTextFile("c:\test.txt", 8).Line追问那怎么删除呢?追答HI我,留个QQ传你代码
CreateObject("scripting.FileSystemObject").OpenTextFile("c:\test.txt", 8).Line追问那怎么删除呢?追答HI我,留个QQ传你代码
- 3楼网友:琴狂剑也妄
- 2021-02-19 10:22
dim n as interger
dim sString,sPutOut as String
Open App.Path & "\1.txt" For Input As #1
n = 0
Do While Not EOF(1) '
n=n+1
Loop
Close #1
if n>=6 then
Open App.Path & "\1.txt" For Input As #1
n = 1
sString=""
Do While Not EOF(1) '
Input #1, sPutOut
if n>3 then
if n=4 then
sString=sPutOut
else
sString=Chr(13) & Chr(10) & sString & sPutOut
end if
end if
n=n+1
Loop
Close #1
end if
Open App.Path & "\1.txt" For Binary As #1
Put #1, , sString
Close #1
'''''''------这个1.txt文件就是你需要的啦!
dim sString,sPutOut as String
Open App.Path & "\1.txt" For Input As #1
n = 0
Do While Not EOF(1) '
n=n+1
Loop
Close #1
if n>=6 then
Open App.Path & "\1.txt" For Input As #1
n = 1
sString=""
Do While Not EOF(1) '
Input #1, sPutOut
if n>3 then
if n=4 then
sString=sPutOut
else
sString=Chr(13) & Chr(10) & sString & sPutOut
end if
end if
n=n+1
Loop
Close #1
end if
Open App.Path & "\1.txt" For Binary As #1
Put #1, , sString
Close #1
'''''''------这个1.txt文件就是你需要的啦!
- 4楼网友:从此江山别
- 2021-02-19 09:05
Dim s() As String, i As Long
Open "txt文件名" For Binary As #1
s = Split(Input(LOF(1), #1), vbCrLf)
Close #1
If UBound(s) >= 5 Then
Kill "txt文件名"
Open "txt文件名" For Output As #1
For i = 3 To UBound(s)
Print #1, s(i)
Next
Close #1
End If
Open "txt文件名" For Binary As #1
s = Split(Input(LOF(1), #1), vbCrLf)
Close #1
If UBound(s) >= 5 Then
Kill "txt文件名"
Open "txt文件名" For Output As #1
For i = 3 To UBound(s)
Print #1, s(i)
Next
Close #1
End If
- 5楼网友:妄饮晩冬酒
- 2021-02-19 08:58
Private Sub Command1_Click()
dim i as integer, s() as string, tem as string
i=0
Open "D:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tem
i=i+1
redim preserve s(i)
s(i)=tem
Loop
Close #1
If UBound(s) >= 6 Then
Open "D:\1.txt" For output As #1
For i = 4 To UBound(s)
print #1, s(i)
Next
close #1
End If
End Sub
dim i as integer, s() as string, tem as string
i=0
Open "D:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tem
i=i+1
redim preserve s(i)
s(i)=tem
Loop
Close #1
If UBound(s) >= 6 Then
Open "D:\1.txt" For output As #1
For i = 4 To UBound(s)
print #1, s(i)
Next
close #1
End If
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯