最好读到数组中先,数组可以是动态分配的。用Preserve
例如Dim strTxtFile() As String
Open "C:\1.txt" For Input As #1
While Not(EOf(1))
ReDim Preserve strTxtFile(i)
Input #1,strTxtFile(i)
i=i+1
Wend
ReDim Preserve strTxtFile(i)
strTxtFile(i)="~~~Last~~~Line~~~String~~~"然后在Form_KeyPress中写(注意:Form的KeyPreView属性应设为True)
Private Sub Form_KeyPress(KeyAscii As Integer)
Static i As Long
If strTxtFile(i)="~~~Last~~~Line~~~String~~~" Then
MsgBox "Show Done!"
Else
Text1=strTxtFile(i)
i=i+1
End If
End Sub
凭空写得,没有亲自试,wish.
例如Dim strTxtFile() As String
Open "C:\1.txt" For Input As #1
While Not(EOf(1))
ReDim Preserve strTxtFile(i)
Input #1,strTxtFile(i)
i=i+1
Wend
ReDim Preserve strTxtFile(i)
strTxtFile(i)="~~~Last~~~Line~~~String~~~"然后在Form_KeyPress中写(注意:Form的KeyPreView属性应设为True)
Private Sub Form_KeyPress(KeyAscii As Integer)
Static i As Long
If strTxtFile(i)="~~~Last~~~Line~~~String~~~" Then
MsgBox "Show Done!"
Else
Text1=strTxtFile(i)
i=i+1
End If
End Sub
凭空写得,没有亲自试,wish.
然后在mainform_onkeypress里加入对应的处理函数,
先假定你已经打开了文件
dim distext as string '你要显示的行的内容
dim myfile as string '要打开的文件名
dim filehandle as long '文件句柄
filehandle=freefile
myfile="c:\temp\test.txt"
open myfile for input as #filehandle然后在keypreview中捕捉用户按的键
if Keyascii=#13 then '假设你要求用户按enter key继续
if not eof(filehandle) then
readnextline
end
else
msgbox("file is over")
end if然后另外做一个函数,处理它
private sub Readnextline
lineinput #filehandle,distext
end sub