2012-11-27 120 views
1

需要关于我正在编写的一段代码的帮助。我不熟悉脚本,所以请原谅。如何使用VBS在文本文件中搜索变量

基本上在下面的代码中我每次找到文本“Busy working Thread Id =”时intBusyThreads增加1。

Do While oTextFile.AtEndOfStream <> True 
    strLine = oTextFile.ReadLine 
    If inStr(strLine, "Busy Working Thread Id=") Then 
    intBusyThreads = intBusyThreads + 1 
    End If 
Loop 

但是我只希望它增加线程ID是否不同。

例如:

繁忙的工作线程标识= 0×01
繁忙的工作线程标识= 0×05
繁忙的工作线程标识= 0×01

在这个例子中我的代码只将有线索Id 01和05是唯一的,因此将intBusyThreads加2。我无法找到允许我这样做的代码。由于线程ID会一直改变,我不知道如何指定该变量。 (希望是有道理的)我尝试了一些东西,如strcomp()。建议?

谢谢!

回答

1

创建一个唯一的线程ID的dictionary并增加你的柜台,只有当电流ID不存在于词典:

Set uniqueIDs = CreateObject("Scripting.Dictionary") 

Do While oTextFile.AtEndOfStream <> True 
    strLine = oTextFile.ReadLine 
    If inStr(strLine, "Busy Working Thread Id=") Then 
    id = Split(strLine, "=")(1) 
    If Not uniqueIDs.Exists(id) Then 
     intBusyThreads = intBusyThreads + 1 
     uniqueIDs.Add id, True 
    End If 
    End If 
Loop