|
本帖最后由 caiyu93 于 2023-10-21 11:34 编辑
- Sub Main()
- Call Test
- End Sub
- Static Sub Test()
- Dim sc As Object,Code
- If sc Is Nothing Then
- Set sc = CreateObject("ScriptControl")
- Code = _
- "Dim Stack, Sum:Sum = 0" & vbCrLf & _
- "Set Stack = CreateObject(""System.Collections.Stack"")" & vbCrLf & _
- "Sub Recurse(ByVal Count, res)" & vbCrLf & _
- " If Count > 0 Then" & vbCrLf & _
- " Sum = Sum + 1" & vbCrLf & _
- " Stack.Push Sum" & vbCrLf & _
- " Count = Count - 1" & vbCrLf & _
- " Recurse Count, res" & vbCrLf & _
- " ElseIf Count = 0 Then" & vbCrLf & _
- " res = Join(Stack.ToArray):Sum = 0: Stack.Clear" & vbCrLf & _
- " Exit Sub" & vbCrLf & _
- " End If" & vbCrLf & _
- "End Sub"
- With sc
- .Language = "VBscript"
- .AddCode code
- End With
- End If
- With sc
- Dim Result
- Call .CodeObject.Recurse(5, Result)
- Debug.Print Result
- Call .CodeObject.Recurse(10, Result)
- Debug.Print Result
- End With
- End Sub
复制代码
在不考虑性能的前提下可以这么用
|
评分
-
1
查看全部评分
-
|