单选题
VB
题号 #453440
窗体上有Text1、Text2两个文本框及一个命令按钮Command1,编写下列程序:
Dim YAs Integer
Private Sub Command1—Click()
Dim x As Integer
X=2
Text1.Text=p2(p1(x),Y):Text2.Text=p1(x)
End Sub
Private Function pl(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
答案解析
分析程序可知Y是一个窗体变量,它的作用范围是本窗体内所有的过程函数,所以在多次调Hj两个Function时,Y的值被保留着;而X是一个局部变量,其作用范围仅在Sub Commandl( )。_Click0执行过程为:第1次单击按钮时x=2。y=0,Text1.Text=p2(pl(x),y)→Textl.Text=p2(4,2)→10;Text2.Text=p1(x)→pl(2)→10;第2次单击按钮时.x=2,y=6,计算结果为Text1.Text=58:Text2.Text=58。
你可能感兴趣的试题
A.Command1.Move-200
B.Command1.Move-200
C.Command1.Left=Command1.Left+200
D.Command1.Left=Command1.Left-200
A.选中状态
B.未选中状态
C.0
D.灰色