Private Sub Command1_Click() b=-15.1 a=sub1(2.54,b+10) print "b=";b;"a=";a End SubPrivate Sub Command1_Click()b=-15.1a=sub1(2.54,b+10)print "b=";b;"a=";aEnd SubPublic function sub 1(a As string,b as integer)as integerb=b+10a=-bsub1=aend functi
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/23 13:11:09
Private Sub Command1_Click() b=-15.1 a=sub1(2.54,b+10) print "b=";b;"a=";a End SubPrivate Sub Command1_Click()b=-15.1a=sub1(2.54,b+10)print "b=";b;"a=";aEnd SubPublic function sub 1(a As string,b as integer)as integerb=b+10a=-bsub1=aend functi
Private Sub Command1_Click() b=-15.1 a=sub1(2.54,b+10) print "b=";b;"a=";a End Sub
Private Sub Command1_Click()
b=-15.1
a=sub1(2.54,b+10)
print "b=";b;"a=";a
End Sub
Public function sub 1(a As string,b as integer)as integer
b=b+10
a=-b
sub1=a
end function
运行程序后输出内容为(B)
B b=-15.1 a=-5
求详解
Private Sub Command1_Click() b=-15.1 a=sub1(2.54,b+10) print "b=";b;"a=";a End SubPrivate Sub Command1_Click()b=-15.1a=sub1(2.54,b+10)print "b=";b;"a=";aEnd SubPublic function sub 1(a As string,b as integer)as integerb=b+10a=-bsub1=aend functi
各值变化如下
Private Sub Command1_Click()
b=-15.1
a=sub1(2.54,b+10) 这句调用sub1函数,其中第二个参数的值为b+10=-5.1
print "b=";b;"a=";a 这句是输出,分号的意思是紧凑连接输出
End Sub
Public function sub 1(a As string,b as integer)as integer 参数a=2.54,b=-5.1,但b定义为整型,所以被取整b=-5
b=b+10 ' b=b+10=-5+10=5
a=-b 'a=-b=-5
sub1=a 'sub1=a=-5
end function
可以得出sub1的返回值是-5,所以aa=sub1(2.54,b+10)=-5,在command1_click里b的值一直是-15.1没有改变过,所以输出的结果是b=-15.1 a=-5