|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
清风_ll 发表于 2013-10-3 20:36
分离此类变量可以通过判断括号是否成对出现来定位一个变量。以下针对该字符串实现的代码。
Sub GetRed ... - Sub GetRedimVar_2() '保留数组声明的原始定义
- Dim sStr As String
- sStr = "Redim crr(1,2,3),arr(UBound(Array(1, 2)), UBound(Array(Array(Array(2, 3), 3), 3))), brr(UBound(Array(1, 2)), UBound(Array(2, 4)))"
- For Each s In Split(GetRedimV_2(sStr), "|")
- Debug.Print s
- Next
- End Sub
- Function GetRedimV_2(s As String) As String
- s = Trim(Mid(Trim(s), 7))
- For i = 1 To Len(s)
- c = Mid(s, i, 1)
- If VarNameStart = 0 Then
- If c <> "," And c <> " " Then
- VarNameStart = i
- i = InStr(i, s, "(")
- ParenthesesNumber = 1
- End If
- Else
- ParenthesesNumber = ParenthesesNumber + IIf(c = "(", 1, IIf(c = ")", -1, 0))
- If ParenthesesNumber = 0 Then
- GetRedimV_2 = GetRedimV_2 & "|" & Mid(s, VarNameStart, i - VarNameStart + 1)
- VarNameStart = 0
- End If
- End If
- Next
- If Len(GetRedimV_2) > 0 Then GetRedimV_2 = Right(GetRedimV_2, Len(GetRedimV_2) - 1)
- End Function
复制代码 |
|