我想用VB语言把非文本文件的内容到文本框中,就象WINDOWS自带的记事本一样。请VB高手回答,谢谢!

解决方案 »

  1.   

    用fso对象。
    OpenAsTextStream 试试。
      

  2.   

    推荐使用richtextbox,
    用它的load方法加载。
      

  3.   

    Option ExplicitConst Str_Rtf = "{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fmodern\fprq6\fcharset134 \'cb\'ce\'cc\'e5;}}" & vbCrLf & _
                    "{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\lang2052\f0\fs20\'d5\'c5\'d5\'c5\'a3\'ac\'a3\'ac\'d6\'d0\'bb\'aa\'c8\'cb\'c3\'f1\'b9\'b2\'ba\'cd\'b9\'fa\par" & vbCrLf & _
                    "}"
                     
    Private Sub Command1_Click()
            Open App.Path & "\temp_RTF.rtf" For Output As #1
            Print #1, Str_Rtf
            Close #1
            MsgBox "存文件完成!"
    End SubPrivate Sub Command2_Click()
            Me.RichTextBox1.LoadFile App.Path & "\temp_RTF.rtf"
    End SubPrivate Sub Command3_Click()
            Me.Text2.Text = Me.RichTextBox1.TextRTF
    End SubPrivate Sub Command4_Click()
            Me.Text3.Text = Me.RichTextBox1.Text
    End SubPrivate Sub Form_Load()
            Me.Text1.Text = Str_Rtf
    End Sub
      

  4.   

    flyingZFX(★我飞★我飞★我飞呀飞★) 
    小弟有很多不明白这处,你能解释一下吗?再就是.rtf是什么样的文件。
      

  5.   

    用我这个函数吧:)
    Public Function GetTextFileToStr(zzg_strFileName As String) As String
        On Error GoTo GetTextFileToStr_Err
        Dim tmpID As Integer
        Dim tmpAllStr As String
        Dim tmpStr() As String
        tmpID = FreeFile
        Open zzg_strFileName For Binary As #tmpID
            tmpAllStr = Space(LOF(tmpID))
            Get #tmpID, , tmpAllStr
        Close #tmpID
        GetTextFileToStr = tmpAllStr
        Exit Function
    GetTextFileToStr_Err:
        GetTextFileToStr = ""
        Exit Function
    End Function
      

  6.   

    跟读文本文件一个样啊,只要不碰上chr(0)就可以正常写入文本框
      

  7.   

    Private Sub Command1_Click()
    Text1.Text = Replace(ReadFile("REPVBTIM.DLL"), Chr(0), "")
    End SubFunction ReadFile(TXTFile As String) As String
        On Error GoTo XXX
        Dim fn As Integer: fn = FreeFile
        Open TXTFile For Binary Access Read As #fn
            ReadFile = Space(FileLen(TXTFile))
            Get #fn, , ReadFile
        Close #fn: Exit Function
    XXX: ReadFile = "读文件时出错"
    End Function
      

  8.   

    最简单的方法
    Open FileName$ For Binary As #1
        Dim B() As Byte: ReDim B(LOF(1) - 1)
        Get #1, 1, B
    Close #1
    text1.Text = StrConv(B, vbUnicode)