(2)static變量
Private Sub Command1_Click()
Dim n As Integer, i As Integer
n = 2
For i = 9 To 1 Step -1
Call sub2(i, n)
Print i, n
Next i
End Sub
Private Sub sub2(x As Integer, y As Integer)
Static n As Integer
Dim i As Integer
For i = 3 To 1 Step -1
n = n + x
x = x - 1
Next i
y = y + n
End Sub
(3) 遞歸
Private Sub Command1_Click()
Dim a As Integer
a = 2
Call sub1(a)
End Sub
Private Sub sub1(x As Integer)
x = x * 2 + 1
If x < 10 Then
Call sub1(x)
End If
x = x * 2 + 1
Print x
End Sub
(4)遞歸
Private Sub test(x As Integer)
Dim i As Integer
If x <> 0 Then
Call test(x - 1)
For i = 1 To x
Print x;
Next i
End If
End Sub
Private Sub Form_Click()
test 3
End Sub
(5)同名變量
Dim y As Integer
Private Sub Form_Click()
Dim x As Integer,y as integer
x=1 : y=1
Print "x1=";x, "y1=";y
Test
Print "x4=";x, "y4=";y
End Sub
Private Sub Test()
Dim x As Integer
Print "x2=";x, "y2=";y
x=2 : y=3
Print "x3=";x,"y3=";y
End Sub
特例:
1、運(yùn)行程序在窗體顯示的結(jié)果是:
Private Sub Form_Click()
Dim a As Integer, b As Integer
a = 3: b = 4
Call sub1(a, a)
Print a, b
Call sub1(b, b)
Print a, b
End Sub
Private Sub sub1(x As Integer, y As Integer)
x = x + 2
y = x + y
End Sub
相關(guān)推薦:2011年計(jì)算機(jī)等級考試二級VB基礎(chǔ)教程匯總計(jì)算機(jī)等級考試二級VB二十套上機(jī)試題及答案
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |