[二级VB试题天天练]VB考试试题16
分类: 计算机
时间: 2022-08-29 04:53:13
作者: 全国等级考试资料网
20.过程函数练习(1)
上机试试看下列程序的运行结果,
然后把语句“Dim sum As Integer”换成“Static Sum As Integer”再试试看——
Private Sub Command1_Click()
Dim A As Long
A = P(1) + P(2) + P(3) + P(4)
Print A
End Sub
Private Function P(N As Integer)
Dim i As Integer
Dim sum As Integer
For i = 1 To N
sum = sum + i
Next
P = sum
End Function
上机试试看下列程序的运行结果,
然后把语句“Dim sum As Integer”换成“Static Sum As Integer”再试试看——
Private Sub Command1_Click()
Dim A As Long
A = P(1) + P(2) + P(3) + P(4)
Print A
End Sub
Private Function P(N As Integer)
Dim i As Integer
Dim sum As Integer
For i = 1 To N
sum = sum + i
Next
P = sum
End Function