本帖最后由 caspar 于 2012-11-22 17:32 编辑
本来vbs是不能像C那样 include 但是通过ExecuteGlobal 就能实现调用自定义类和函数
但是一些奇怪的问题就来了...
因为要多次调用正则来获取文字, 自身懒, 想写少点代码, 就写了一个RegExp的Function 那以后要再用到的时候 直接include
RegExp的代码: | Public Function GetMatches(ByVal patrn, ByVal strng, ByRef MatchesCount, ByRef SubMatchesCount, ByVal regExIgnoreCase, ByVal regExGlobal) | | Dim regEx, Match, Matches | | Dim arrMatch() | | | | Set regEx = New RegExp | | regEx.Pattern = patrn | | IF regExIgnoreCase="" Then | | regEx.IgnoreCase = True | | ELSE | | regEx.IgnoreCase = regExIgnoreCase | | End IF | | IF regExGlobal="" Then | | regEx.Global = True | | ELSE | | regEx.Global = regExGlobal | | End IF | | | | Set Matches = regEx.Execute(strng) | | | | MatchesCount=Matches.Count | | SubMatchesCount=Matches(0).SubMatches.Count | | | | ReDim arrMatch(MatchesCount) | | ReDim arrMatch(Matches.count,SubMatchesCount) | | | | n=1 | | For Each Match in Matches | | arrMatch(n,0)=Match.Value | | For t=1 to Match.SubMatches.Count | | arrMatch(n,t)=Match.submatches(t-1) | | next | | n=n+1 | | Next | | | | Set regEx = Nothing | | GetMatches = arrMatch | | End FunctionCOPY |
但问题来了...include之后 调用这个函数...
例如 | Dim arrMatches() | | arrMatches=GetMatches(patrn,str,mcount,smcount,true,true)COPY |
就会提示类型不匹配...有高手知道这是为什么么...? |