请教一下二级vb的一道题 谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/25 01:24:26
窗体上有Text1,Text2两个文本框和一个命令按钮Command1,编写下列程序
Dim y As Integer
Private Sub Command1_Click()
Dim x As Integer
x=2
Text1.Text=Fun2(Funl(x),y)
Text2.Text=Funl(x)
End Sub
Private Function Funl(x As Integer) As Integer
x=x+y:y=x+y
Funl=x+y
End Function
Private Function Fun2(x As Integer,y As Integer) As Integer
Fun2=2*x+y
End Function
当单击一次和两次命令按钮后,文本框Text1和Text2内的值分别是多少?

请详述一下具体的解答过程 谢谢 还想问一下 Fun, Function 分别代表什么函数,怎样使用? 谢谢
其实sro2405 - 试用期 一级 3-17 04:05的答案应该是对的 但最后算Fun1时错了 因为答案是10 10 58 58 我安妮的算法响了一下 此时 X的值应该是8 就对了 呵呵 不管怎么样都谢谢你了 下次有问题还得要麻烦大家阿

first time click:
x= 2: y=0 (be aware of y is global)

Funl(x) = Funl(2)
x=x+y=2+0 x=2
y=x+y=2+0 y=2 (y is 2 now)
Funl=x+y=2+2=4

Fun2(Funl(x),y) = Fun2(4, 2)
Fun2=2*x+y =2*4+2 = 10

So Text1.Text=10

Text2.Text=Funl(x) =Funl(2)
x=x+y=2+2 x=4
y=x+y=4+2 y=6 (y is 6 now)
Funl=x+y=4+6=10

So Text2.Text=10

Second click:
x=2;y=6

Funl(x) = Funl(2)
x=x+y=2+6 x=8
y=x+y=8+6 y=14 (y is 14 now)
Funl=x+y=8+14=22

Fun2(Funl(x),y) = Fun2(22, 14)
Fun2=2*x+y =2*22+14 = 58

So Text1.Text=58

Text2.Text=Funl(x) =Funl(2)
x=x+y=2+14 x=16
y=x+y=16+14 y=30 (y is 30 now)
Funl=x+y=16+30=46

So Text2.Text=46

Just be alert, each click will reset x to 2, but y will go up.

Have fun. :)

Function 是自定义函数的语句fun和fun2是自定义的函数

Private Sub Command1_Click(29)
Fun6+=[23]
Text2+={11}