1
2'递归删除频道,参数:频道ID
3Sub DeleteBoard(bid)
4 '删除该频道所有新闻
5 News.DeleteByCondition "BoardID=" & bid
6 '删除该频道所有子频道
7 Dim bs
8 bs = Board.GetList("FartherID=" & bid, false, -1, -1)
9 If IsArray(bs) Then
10 For i=LBound(bs) To UBound(bs)
11 DeleteBoard bs(i).ID
12 Next
13 End If
14 '删除该频道
15 Board.Delete bid
16End Sub
17
后来检查才发现,罪魁祸首就是那个i,它是一个全局变量。递归的时候,在另一次调用的时候,会修改它的值……因而,就莫明其妙的形成了死循环。修改后代码如下:
2'递归删除频道,参数:频道ID
3Sub DeleteBoard(bid)
4 '删除该频道所有新闻
5 News.DeleteByCondition "BoardID=" & bid
6 '删除该频道所有子频道
7 Dim bs
8 bs = Board.GetList("FartherID=" & bid, false, -1, -1)
9 If IsArray(bs) Then
10 For i=LBound(bs) To UBound(bs)
11 DeleteBoard bs(i).ID
12 Next
13 End If
14 '删除该频道
15 Board.Delete bid
16End Sub
17
1
2'递归删除频道,参数:频道ID
3Sub DeleteBoard(bid)
4 '删除该频道所有新闻
5 News.DeleteByCondition "BoardID=" & bid
6 '删除该频道所有子频道
7 Dim bs, i
8 bs = Board.GetList("FartherID=" & bid, false, -1, -1)
9 If IsArray(bs) Then
10 For i=LBound(bs) To UBound(bs)
11 DeleteBoard bs(i).ID
12 Next
13 End If
14 '删除该频道
15 Board.Delete bid
16End Sub
17
增加了i的内部声明,这样,就会使用内部的i,而不是全局的那个。
我不相信神话,我只相信汗水!我不相信命运,我只相信双手!2'递归删除频道,参数:频道ID
3Sub DeleteBoard(bid)
4 '删除该频道所有新闻
5 News.DeleteByCondition "BoardID=" & bid
6 '删除该频道所有子频道
7 Dim bs, i
8 bs = Board.GetList("FartherID=" & bid, false, -1, -1)
9 If IsArray(bs) Then
10 For i=LBound(bs) To UBound(bs)
11 DeleteBoard bs(i).ID
12 Next
13 End If
14 '删除该频道
15 Board.Delete bid
16End Sub
17