注册 登录
编程论坛 VB6论坛

新手求教,大家帮忙来找茬

rambopan 发布于 2016-06-24 20:34, 1289 次点击
我一本教材上抄了一段,运行后提示 输入超出文件尾,我想知道这是为什么,应该怎么解决,谢谢。
Private Sub Command1_Click()
CommonDialog1.Filter = "文档文件 (*.txt)|*.txt|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Text1.Text = StrConv(Input(LOF(1), 1), vbUnicode)
Close #1
End Sub

Private Sub Command2_Click()
CommonDialog1.Filter = "文档文件 (*.txt)|*.txt|所有文件(*.*)|*.*"
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1

Close #1
End Sub

Private Sub Form_Load()
Command1.Caption = "打开文本文件"
Command2.Caption = "保存文本文件"
End Sub
2 回复
#2
ZHRXJR2016-06-24 21:42
LOF(1)不对吧,应该是 EOF(1).
#3
风吹过b2016-06-25 21:00
Public Function 打开文件(cs As String) As String
On Error Resume Next
Dim fj As Long
If Dir(cs) <> "" Then
    fj = FreeFile()
    Open cs For Binary As #fj
    '快速打开文件
        打开文件 = StrConv(InputB$(LOF(fj), #fj), vbUnicode)
    Close #fj
Else
    Msg cs & vbCrLf & "文件不存在!", vbCritical, 消息标题
End If
End Function
----------------------------
参考我自己用的代码你琢磨一下吧。
1