vb的程序题

来源:百度知道 编辑:UC知道 时间:2024/06/29 22:55:13
Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim n As Integer, z As Integer
x = 1
y = 1
For n = 1 To 6
z = func(x, y)
Next n

Print z

End Sub

Public Function func(x As Integer, y As Integer) As Integer
Dim n As Integer
Do While n <= 4
x = x + y
n = n + 1
Loop
func = x

End Function
他的运算详细步骤

步骤是这样的:
1.定义了一个函数,设置循环次数六次
2.函数的功能是实现一个很简单的算法.
结果为 6+5*5=31

就是正常的循环呀
要是不是很清楚,可以利用Debug一步步执行就是.

发现你问了好多类似的问题……

1.声明变量
2.赋值
3.for循环6次『调用function 过程 func(参数X Y)』

1>
x = x + y...x = 1 + 1.....= 2
n = n + 1...n = 1 + 1.....= 2
func = x....func..........= 2

2>
x = x + y...x = 2 + 1.....= 3
n = n + 1...n = 2 + 1.....= 3
func = x....func..........= 3

3>
x = x + y...x = 3 + 1.....= 4
n = n + 1...n = 3 + 1.....= 4
func = x....func..........= 4

4>
x = x + y...x = 4 + 1.....= 5
n = n + 1...n = 4 + 1.....= 5
func = x....func..........= 5

5>
func = x....func..........= 5
z = func....z.............= 5

print z.....................5

好好看书,这很简单的