一道VB问题!

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:28:31
在窗体上添加一个名称为Command1的命令按钮,并编写如下程序:
Private Sub Command1_Click ()
Dim x As Integer
Static y As Integer
x=10
y=5
Call f1(x,y)
Print x,y
End Sub’
Private Sub f1(Byref x1 As Integer,y1 As Integer)
x1=x1+2
y1=y1+2
End Sub
程序运行后,单击命令按钮,在窗体上显示的内容是_____.
(A) 10 5 (B) 12 5 (C) 10 7 (D) 12 7
为什么选D Static y As Integer是什么意思 Private Sub f1(Byref x1 As Integer,y1 As Integer)这句看不懂

我学的是C 所以说的不一定正确
Private Sub f1(Byref x1 As Integer,y1 As Integer)
这个是函数 F1
CALL F1(X,Y) 调用了 函数 F1 也就是
Private Sub f1(Byref x1 As Integer,y1 As Integer)
的部分。 经过计算得到 x1 为 10+2 即 12
y1 为 5+2 即 7
打印 得到 D 的答案。
Static y As Integer 是用STATIC 的形式定义变量。
Static 的用法在 http://baike.baidu.com/view/536145.html?wtp=tt

static y
就是在运行完这个sub之后
y仍然保留
比如说
sub adds()
static s
s=s+1
end sub
第一次运行,s=1
第二次运行,s=2
……

Private Sub f1(Byref x1 As Integer,y1 As Integer)
这是一个 子过程
就是执行这里面的步骤