具体delphi的代码如下:现要将如下程序改成vb的,请大虾指点:
procedure TC_Render.CountSymbol(var SourceList, DescList: TStringList);
var
flag:Boolean;
i,j:integer;
tempstr:string;
begin
for i:=0 to SourceList.Count-1 do
begin
flag:=false;
tempstr:=SourceList[i];
for j:=0 to DescList.Count-1 do
begin
if SourceList[i]=DescList[j] then
flag:=true;
end;
if flag=false then
DescList.Add(tempstr);
end;
end;
procedure TC_Render.CountSymbol(var SourceList, DescList: TStringList);
var
flag:Boolean;
i,j:integer;
tempstr:string;
begin
for i:=0 to SourceList.Count-1 do
begin
flag:=false;
tempstr:=SourceList[i];
for j:=0 to DescList.Count-1 do
begin
if SourceList[i]=DescList[j] then
flag:=true;
end;
if flag=false then
DescList.Add(tempstr);
end;
end;
建立集合的方法与建立其它对象的方法一样。例如:Dim X As New Collection一旦建立集合之后,就可以用 Add 方法添加成员,用 Remove 方法删除成员。在用 For Each...Next 语句重复整个集合时,可以用 Item 方法从集合返回特定成员。
Dim MyClasses As New Collection ' 建立一个集合对象(Collection)。
Dim Num ' 计数用变量,用来对对象的个数计数。
Dim Msg As String ' 提示信息用变量。
Dim TheName, MyObject, NameList ' 对象信息用变体。
Do
Dim Inst As New Class1 ' 建立 Class1 的新实例。
Num = Num + 1 ' 把计数变量 Num 加一,然后要求输入新对象个体的名称。
Msg = "Please enter a name for this object." & Chr(13) _ & "Press Cancel to see names in collection."
TheName = InputBox(Msg, "Name the Collection Items")
Inst.InstanceName = TheName ' 将名称送入对象实例。
' 若用户输入了名称,将它加入集合。
If Inst.InstanceName <> "" Then
' 将命名的对象加入集合。
MyClasses.Add item := Inst, key := CStr(Num)
End If
' 清除当前的引用,为对下一个对象做准备。
Set Inst = Nothing
Loop Until TheName = ""
For Each MyObject In MyClasses ' 建立名称列表。NameList = NameList & MyObject.InstanceName & Chr(13)
Next MyObject
' 将名称列表在消息框中显示出来。
MsgBox NameList, , "Instance Names In MyClasses Collection"For Num = 1 To MyClasses.Count ' 从集合中删除名字。
MyClasses.Remove 1 ' 因为每删除一个对象后,集合
' 会自动重排顺序,故每次迭代时只需删除第一个
Next ' 对象即可。
End Sub