lof(文件号)函数返回的是文件的字节数
而input函数用的是字符数
如果文本文件里包含中文和英文,那么用input(lof(文件号),文件号)就会溢出有什么解决办法没有

解决方案 »

  1.   

    如果非得一次读入,可以用RichTextBox
      

  2.   

    当今最牛的代码Private function TxtRead(byval sFile as string) as string
        on error resume next 
        Open sFile For Input As #1
            Do While Not EOF(1)
                Line Input #1, TextLine
                TxtRead=TxtRead & TextLine
            Loop
        Close #1
    End function-------------------------------------------
    例子
    msgbox txtread("C:\Text.txt")
      

  3.   

    Dim sFile As String
    Open "C:\filename.txt" For Input As #1
    sFile = StrConv(InputB$(LOF(1), #1), vbUnicode)
    Close #1
    以上方法最好只处理640k以下的文件,超出的话可能会出错。终极方式是 binary 读取,任何类型任意长度都没问题。
      

  4.   

    Private Function TxtRead(ByVal sFile As String) As String
        On Error Resume Next
        Dim TextLine As String
        Open sFile For Input As #1
            Do While Not EOF(1)
                Line Input #1, TextLine
                TxtRead = TxtRead & TextLine
            Loop
        Close #1
    End Function-------------------------------------------
    例子
    msgbox txtread("C:\Text.txt")
      

  5.   

    因为我想把原本文件里边的格式也读出来,txt文件格式很简单,就是回车换行什么的
    用lineinput语句会删掉文本里原有的回车换行符,导致格式出问题。