一道VB题,高手请进!!!!

Dim y As Integer
Private Sub Command1_Click()
Dim x As Integer
x=2
Text1.Text= p2(p1(x),y)
Text2.Text= p1(x)
End Sub
Privage Function P1(x As Integer) As Integer
x =x+y:y=x+y
P1=x+y
End Function
Private Function P2(x As Integer, y As Integer) As Integer
P2= 2*x+y
End Function
当单击1 次和单击2次命令按钮后,文本框Text1和Text2内的值分别是(C)
A)2 4
2 4
B)2 4
4 8
C)10 10
58 58
D)4 4
8 8
高手请告诉我详细解题过程!!!

Dim y As Integer '全局声明
Private Sub Command1_Click()
Dim x As Integer '声明
x=2 '赋值
Text1.Text= p2(p1(x),y) '先调用函数p1(x),把p1(x)嵌入函数p2中,再把所得的值赋给Text1文本框
Text2.Text= p1(x) '同样调用p1(x),并赋给Text2
End Sub
Private Function P1(x As Integer) As Integer '建立函数过程P1(x)
x =x+y:y=x+y
P1=x+y
End Function
Private Function P2(x As Integer, y As Integer) As Integer '建立函数过程P2(x)
P2= 2*x+y
End Function

计算过程如下:
计算Text1.text的过程
x=2
y=0
x=x+y=2+0=2
y=x+y=2+0=2
p1=x+y=2+2=4
p2=2*x+y=2*4+2=10
所以Text1.text=10

计算Text2.text的过程:
x=2
y=2
x=x+y=2+2=4
y=x+y=4+2=6
p1=x+y=10
所以Text2.text=10

注意X,y的值的变化
不懂再来问吧!!!!
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜