1
2
'
递归删除频道,参数:频道ID
3
Sub
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
16
End Sub
17
后来检查才发现,罪魁祸首就是那个i,它是一个全局变量。递归的时候,在另一次调用的时候,会修改它的值……因而,就莫明其妙的形成了死循环。修改后代码如下:
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
2
'
递归删除频道,参数:频道ID
3
Sub
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
16
End Sub
17
增加了i的内部声明,这样,就会使用内部的i,而不是全局的那个。
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)