以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]如何生成随机长度的WBS编号 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=88224) |
-- 作者:chnfo -- 发布时间:2016/7/29 11:43:00 -- [求助]如何生成随机长度的WBS编号 因做试验数据,要生成大量的随机的分解结构。 例如 1 1.1 1.1.1 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2 1.1.3 1.1.3.1 1.1.3.1.1 1.1.2.1.2 1.2 …… 即:每一个节点的直属下级节点的个数并不完全相同;即使共有一个父节点,子节点有的有下级节点,有的没有。 这个该如何实现呢? [此贴子已经被作者于2016/7/29 11:43:09编辑过]
|
-- 作者:cbt -- 发布时间:2016/7/29 12:12:00 -- For i As Integer = 1 To 3 Dim str As String = "1." &i output.show(str) For i2 As Integer = 1 To 3 Dim str2 As String = str & "." & i2 If Rand.Next(2)>0 Then output.show(str2) Continue For End If For i3 As Integer = 1 To 3 Dim str3 As String = str2 & "." & i3 If Rand.Next(8)> 0 Then output.show(str3) End If Next Next Next |
-- 作者:cbt -- 发布时间:2016/7/29 12:38:00 -- Dim tv As WinForm.TreeView = Forms("窗口1").Controls("TreeView1") tv.Nodes.Clear Dim nd As WinForm.TreeNode = tv.Nodes.Add("1") For i As Integer = 1 To 3 Dim str As String = "1." &i Dim nd2 As WinForm.TreeNode = nd.Nodes.Add(i) For i2 As Integer = 1 To 3 Dim str2 As String = str & "." & i2 Dim nd3 As WinForm.TreeNode If Rand.Next(2)>0 Then nd3 = nd2.nodes.Add(i2) Continue For End If For i3 As Integer = 1 To 3 Dim str3 As String = str2 & "." & i3 If Rand.Next(8)> 0 Then If nd3 IsNot Nothing Then nd3.nodes.Add(i3) End If End If Next Next Next tv.ExpandAll |
-- 作者:chnfo -- 发布时间:2016/7/29 13:42:00 -- 稍调整了一下。 For i As Integer = 1 To 10
Dim str As String = "1." &i output.show(str) For i2 As Integer = 1 To Rand.Next(1,6) Dim str2 As String = str & "." & i2 output.show(str2) If rand.Next(3) > 0 Then Continue For End If For i3 As Integer = 1 To Rand.Next(2,8) Dim str3 As String = str2 & "." & i3 output.show(str3) Next Next Next 不过,这样写限定了最多的层数是4层,如果要扩展到7层,就会很麻烦,是否定义函数,自我调用会好一些。 [此贴子已经被作者于2016/7/29 13:42:38编辑过]
|
-- 作者:大红袍 -- 发布时间:2016/7/31 10:48:00 -- 写成递归
http://www.foxtable.com/webhelp/scr/2416.htm
|