|
楼主 |
发表于 2014-11-14 14:37
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 lee1892 于 2014-11-14 14:56 编辑
下述代码可以按题目格式生成一个随机树的字符串- Function RandomTree$()
- Dim nCnt%, i%, nInd%, nLast%, nChildNumMax%
- nCnt = Int(Rnd * 10000) + 1
- nChildNumMax = 10
- nInd = 1: nLast = 1: RandomTree = CStr(nCnt)
- Do
- For i = 1 To Int(Rnd * nChildNumMax) + 1
- nLast = nLast + 1
- If nLast > nCnt Then Exit Do
- RandomTree = RandomTree & ";" & CStr(nInd) & "," & CStr(nLast)
- Next
- nInd = nInd + 1
- Loop
- End Function
复制代码 |
|