试一下
Private Sub cmdreadtext_Click()
    dim noteText
    On Error GoTo ferr1
    Open "f:\file\file3.txt" For Input As #1
    Input #1, noteText
    Close #1
    txtfile2.text = noteText
    Exit Sub
ferr1:
MsgBox ("文件错误!")End Sub

解决方案 »

  1.   

    哥们,你能不能把错误信息说说!
    有可能:
    1:路径错误
    2:(#1)文件号错误,最好定一个变量,用FreeFile函数功能
      Dim MyIndex, FileNumber
    For MyIndex = 1 To 5   ' Loop 5 times.
       FileNumber = FreeFile   ' Get unused file
          ' number.
       Open "TEST" & MyIndex For Output As #FileNumber   ' Create file name.
       Write #FileNumber, "This is a sample."   ' Output text.
       Close #FileNumber   ' Close file.
    Next MyIndex
    3:Input$()用错了!
    Dim MyChar
    Open "TESTFILE" For Input As #1   ' Open file.
    Do While Not EOF(1)   ' Loop until end of file.
       MyChar = Input(1, #1)   ' Get one character.
       Debug.Print MyChar   ' Print to the Immediate window.
    Loop
    Close #1   ' Close file.
      

  2.   

    '用Input$读取整个文本文件
    Private Sub cmdreadtext_Click()
        On Error GoTo ferr1
        Open "f:\file\file3.txt" For Binary As #1
        txtfile2.text = Input(LOF(1), 1) '读入指定长度的字符串,即文件的整个文本内容
        Close #1
        Exit Sub
    ferr1:
    MsgBox ("文件错误!")End Sub
      

  3.   

    Private Sub Command2_Click()
        Open "aa.txt" For Binary As #1 '不是 Input 
           Text1.Text = Input(LOF(1), 1)
        Close #1
    End Sub
      

  4.   

    谢谢大家的热情帮助!!
    我的程序里文件路径肯定没有错误,我主要想用一下INPUT$这种读入文件的方式读取整个文件的内容,我根据langzhi(方舟)的思路,把文件内容换成英文,果然通过!!
    不过对方舟写的代码我还没有用过,希望以后可以多多交流。wgku:你说的我还不太明白,到底是因为什么出的错,我的文件里的确有汉字也有英文,按照你的思路,应该怎样避免这种情况呢?
      

  5.   

    Private Sub Command2_Click()
        Open "aa.txt" For Binary As #1 '不是 Input 
          Text1.Text = Input(LOF(1), 1)
        Close #1
    End Sub 这个不可以用吗?qq 26603030
      

  6.   

    xxlroad:
    用二进制方式打开可以,但我只是想验证一下为什么input$会出错。
      

  7.   

    wgku:
    用你的方法可以实现读取unicode文件,谢谢!但分已经给完了,抱歉。