填空题 VB
题号 #143694

在窗体上画1个名称为Command1的命令按钮和2个名称分别为Text1、Text2的文本框,如图所示,然后编写如下程序:
Function Fun(x As Integer,ByVal y As Integer)As Integer
 x=x+y
 If x<0 Then
  Fun=x
 Else
  Fun=y
 End If
End Function
Private Sub Command1_Click()
 Dim a As Integer,b As Integer
 a=-10:b=5
  Text1.Text=Fun(a,b)
  Text2.Text=Fun(a,b)
End Sub
程序运行后,单击命令按钮,Text1和Text2文本框显示的内容分别是______和______。

进入在线模考

参考答案

暂无

答案解析

-5 5 
该题考查传值参数和传址参数的区别。Visual Basic通过关键字ByVal来实现对b进行传值,而对于a则是通过引用来传地址,因此a与Function过程里的x是同一地址。第一次调用Function过程时,过程返回值为-5,同时x=-5,即a=-5,因此第二次调用过程时,过程的返回值为5。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考