Private Sub Command1_Click()
CommonDialog1.Filter = "文本文档(*.txt)"
CommonDialog1.ShowOpenDim Lstr As String
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
            Line Input #1, Lstr
            Text1.Text = Text1.Text & Lstr & vbCrLf
Loop
Close #1
End Sub
这样读取倒是好使,但是文件太大了,就不好使了,窗口会没有相应这怎么办啊?
大虾帮帮忙啊~!!还有这个图片里面的是什么控件啊?谁帮我看一下

解决方案 »

  1.   

    textbox最多放32kb数据(多行时),所以不适合放大文件内容,建议使用richtextbox。
    而且编程处理字符串相连很费时的,最好一次性读入(比如使用fso,readfile[api]等),这样速度很快,也不用考虑窗体不能响应的问题。
      

  2.   

    1.这样写会快很多
    Do While Not EOF(1)
        Line Input #1, Lstr
        Lstr= Lstr & vbCrLf
    Loop
    Text1.Text = Lstr2.那个象是mshflexgrid或msflexgrid表格控件
      

  3.   

    richtextbox需要在添加吧  全名是什么啊?还有下面的grid是那个控件啊?我没找到
      

  4.   

    更正 Lstr= Lstr & vbCrLf 为
    tmp = tmp + Lstr + vbCrLf
    Text1.Text = tmp 
      

  5.   

    找到了richtextbox一个设置成一行一个颜色吗?第一行红色
    第二行蓝色这样可以吗?
      

  6.   

    不超过 64K 时还是用 TextBox,下面的方法很快的。
    Option ExplicitPrivate Sub Command1_Click()
        Dim hFile As Integer
        Dim aBytes() As Byte
        
        CommonDialog1.Filter = "文本文档(*.txt)"
        CommonDialog1.ShowOpen    hFile = FreeFile()
        Open CommonDialog1.FileName For Binary Access Read As #hFile
        ReDim aBytes(LOF(hFile) - 1)
        Get #hFile, , aBytes
        Close #hFile
        
        Text1.Text = StrConv(aBytes, vbUnicode)
    End Sub
      

  7.   

    用get语句或者用input函数都比 line input 快;
    下面那个控件好像是 listview
      

  8.   


    谢谢啊我的文件看了大雨64K,我用RichTextBox  可以读取文件但是我想设置成一行一个颜色,可以做的到吗??我这个小程序需要设置颜色才可以
      

  9.   

    http://topic.csdn.net/u/20100317/13/83489c3d-ba55-4b04-917d-975f1d178710.htmlshuishui谁回一下这个帖子我结贴送分,不多就50
     全给1楼
      

  10.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim hFile As Integer
        Dim aBytes() As Byte
        Dim aLines() As String
        Dim i As Long
        
        CommonDialog1.Filter = "文本文档(*.txt)"
        CommonDialog1.ShowOpen    hFile = FreeFile()
        Open CommonDialog1.FileName For Binary Access Read As #hFile
        ReDim aBytes(LOF(hFile) - 1)
        Get #hFile, , aBytes
        Close #hFile
        
        aLines = Split(StrConv(aBytes, vbUnicode), vbCrLf)
        
        RichTextBox1.Text = vbNullString
        For i = 0 To UBound(aLines)
            RichTextBox1.SelColor = IIf(i Mod 2, vbBlue, vbRed)
            RichTextBox1.SelText = aLines(i) & vbCrLf
        Next
    RichTextBox 比普通 TextBox 慢多了。
    真正的大文件如果不需要编辑的话,还是用图片框和滚动条模拟,只需要输出可见的一部分。
      

  11.   


    Private Sub Command1_Click()
    RichTextBox1.Text = ""
    CommonDialog1.Filter = "文本文档(*.txt)"
    CommonDialog1.ShowOpenDim Lstr As String
    Open CommonDialog1.FileName For Input As #1
    Dim start As Integer
    Dim length As Integer
    Dim i As Integer
    i = 0
    Do While Not EOF(1)
                Input #1, Lstr
                RichTextBox1.SetFocus
                RichTextBox1.SelStart = Len(RichTextBox1.Text)
                
                '去掉空格
                If Len(Lstr) = 0 Then
                   'MsgBox ("null")
                Else
                    '添加到文本框中
                    start = Len(RichTextBox1)
                     RichTextBox1.Text = RichTextBox1.Text & Lstr & vbCr
                     length = Len(RichTextBox1)
                End If
                     With RichTextBox1
                        .SelStart = start
                        .SelLength = length
                        Select Case i
                        Case 0
                        .SelColor = vbRed
                        Case 1
                        .SelColor = vbGreen
                        End Select
                        .SelBold = True
                        .SelUnderline = True
                    End With
                    
                    If i = 0 Then
                    i = 1
                    Else
                    i = 0
                    End If
                    
    Loop
    Close #1End Sub
    这个是我的一个按钮的事件,我选择文件之后一行一行读取,在把文字一行用红色一行用绿色怎么不行啊?一点效果都没有
      

  12.   

    对 Text 属性赋值等于重新生成 RTF,原先所有的颜色、字体等都被覆盖了。
      

  13.   


    我刚看vb就一天我看了你写的,比我的加载速度快多了,而且代码更短。我是想问一下你的是 Open CommonDialog1.FileName For Binary Access Read As #hFile
        'LOF     对于尚未打开的文件,使用 FileLen 函数将得到其长度。
        ReDim aBytes(LOF(hFile) - 1)
    '读入到byte中
        Get #hFile, , aBytes
        Close #hFile'在通过split函数把byte以回车分开存入数组当中
        aLines = Split(StrConv(aBytes, vbUnicode), vbCrLf)
        
    '循环遍历
    RichTextBox1.Text = vbNullString
        For i = 0 To UBound(aLines)
             'i  于 2  ==0   就  用蓝色,不等于就用红色
            'RichTextBox1.SelColor = IIf(i Mod 2, vbBlue, vbRed)
            MsgBox (aLines(i))
              '选中文字,并赋值吗?
            RichTextBox1.SelText = aLines(i) & vbCrLf
        Next
    你的代码我这么理解的对不?
      

  14.   

    Text 属性赋值等于重新生成 RTFRTF是啥意思啊?
      

  15.   

    1)Open 以后文件就是打开的,LOF 是直接取文件长度,与 FileLen 无关。
    2)RTF : Rich Text Format
      

  16.   

    RichTextBox1.SelColor = IIf(i Mod 2, vbBlue, vbRed)
    RichTextBox1.SelText = aLines(i) & vbCrLf你的2行修改怎么OK呢?是因为用了SelText吗?
      

  17.   

    UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUP