VB 文件 最後一行 倒數第二行

1

Private Sub Command4_Click()

    Text1.Text = ""
    CommonDialog1.Filter = "*.txt 文件|*.txt"
    CommonDialog1.ShowOpen
        Open CommonDialog1.FileName For Input As #1
            Do While Not EOF(1)   ' 循环至文件尾。
               Line Input #1, TextLine   ' 读入一行数据并将其赋予某变量。
               Text1.Text = TextLine
            Loop
        Close #1
End Sub

2
Open xxx For Input As #1
s = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
v=split(s,vbcrlf)
msgbox v(ubound(v))



倒數顯示
其实你可以换个思路,先把文件读入到一个数组,倒着来就是从最后一行往上了,看看这个
Dim FileN As String, i As Integer
Dim Lines() As String,s as string
FileN = "c:\123.txt"
Open FileN For Input As #1   '读取文本行数
    While Not EOF(1)
        Line Input #1, s
        i = i + 1
    Wend
Close #1
ReDim Lines(i)
Open FileN For Input As #1  '读入文本至数组
    While Not EOF(1)
        Line Input #1, Lines(i)
        i = i + 1
    Wend
Close #1
For i = UBound(Lines) To 0 Step -1  '倒序输出
    Print Lines(i)
Next
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值