比如我桌面有个1.TXT 里面、内容如下
123456 第1行
5456456  第2行
123456  第3行
5456456 第4行
456s4d5f6456 第5行
  我想把他读取到TEXT里面显示可以通过
Dim STR As String '定义变量
Open "桌面\1.txt" For Input As #1
'Do While Not EOF(1)
'Line Input #1, Nextline
'Text1.Text = Nextline
'Loop
'Close #1
Text1.Text = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
读取后在TEXT1显示为
123456 第1行
5456456  第2行
123456  第3行
5456456 第4行
456s4d5f6456 第5行
但是这不是我想要的··我想要的是·我想读取到TEXT1里面显示为
123456 第1行
5456456  第2行
456s4d5f6456 第5行也就是 说 有同行的字符一模一样的话就只显示一个··
请问是否可以做到啊???
请给出代码谢谢···

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim s As String, i As Long, j As Long, t As String
        Dim ss() As String, tt() As String, n As Long
        Open "d:\aa.txt" For Input As #1
        Do While Not EOF(1)
           Line Input #1, s
           t = t + s + ","
        Loop
        Close #1
        ss = Split(t, ",")
        tt = Split(t, ",")
        t = "": s = ""
        n = UBound(ss) - 1
        For i = 0 To n
           For j = i + 1 To n
              If ss(i) = tt(j) Then
                 tt(j) = ""
              End If
           Next j
        Next i    For i = 0 To n
           If tt(i) <> "" Then t = t + tt(i) + vbCrLf
        Next i
        Open "d:\bb.txt" For Output As #1
        Print #1, t
        Close #1
        MsgBox "ok"
    End Sub
      

  2.   

    建個String變量,將開頭設為Chr(13)+Chr(10)。每讀一行,搜索一下某個字符串變量里是否已經有這樣一行內容且前後都是Chr(13)+Chr(10)就行了,沒有就加到這個變量里,最後將變量從第三個字符開始的內容賦值給Textbox。
      

  3.   

    Private Sub Command1_Click()
       '设置Text1.MultiLine属性为true
        Open App.Path & "\g.txt" For Input As #1
        Dim tmpStr() As String, i As Integer, j As Integer    Do While Not EOF(1)
           ReDim Preserve tmpStr(i)
           Line Input #1, tmpStr(i)
           For j = 0 To UBound(tmpStr) - 1
               If tmpStr(j) = tmpStr(UBound(tmpStr)) Then
                  ReDim Preserve tmpStr(i - 1)
                  i = i - 1
                  Exit For
               End If
           Next j
           i = i + 1
        Loop
        Text1.Text = Join(tmpStr, vbNewLine)
    End Sub
      

  4.   

    可以考虑建个字典:
    Private Sub Command1_Click()
    Dim s() As String, i As Long, dic
    Set dic = CreateObject("scripting.dictionary")
    Open "c:\1.txt" For Input As #1
    s = Split(StrConv(InputB(LOF(1), 1), vbUnicode, &H804), vbCrLf)
    Close #1
    For i = 0 To UBound(s)
    If Not dic.Exists(Split(s(i))(0)) Then dic(Split(s(i))(0)) = s(i)
    Next
    Text1.Text = Join(dic.items, vbCrLf)
    End Sub