2011-08-16 7 views
1

あなたはカンマ区切りの文字列に文字列を集約ループ考えてみましょう:VB6でDistinct文字列を見つける最良の方法は何ですか?

Dim Result As String 
For Each Something In Things 
    If Result <> vbNullString Then 
     Result = Result & "," 
    End If 
    Result = Result & SomeStringFunction(Something) 
Next Something 

動作しますが、どのような場合、私は唯一の明確な文字列をしたいですか?私は、このメソッドを使用してきたが、それは非常に "重い重量" ようだ:

Dim Dict As Dictionary 
Set Dict = New Dictionary 
For Each Something In Things 
    Dict(SomeStringFunction(Something)) = vbNullString 
Next Something 

Dim Result As String 
Dim vKey As Variant 
For Each vKey In Dict.Keys 
    If Result <> vbNullString Then 
     Result = Result & "," 
    End If 
    Result = Result & CStr(vKey) 
Next vKey 
Set Dict = Nothing 

答えて

1

OK、汚いハック時間:

Dim Result As String 
Dim noDupes as New Collection 
For Each Something in Things 
    On Error Resume Next 
    noDupes.Add Something, Something 
    If Err.Number = 0 Then 
     If Result <> vbNullString Then 
      Result = Result & "," 
     End If 
     Result = Result & SomeStringFunction(Something) 
    End If 
    Err.Clear 
Next Something 
関連する問題