江西樟树中央大街楼盘:一道VB的问题,望高人详说思路

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 16:27:12
option Explicit
Dim t as integer
Private sub command1_Click()
dim x as integer,y as integer
x=1:y=1
for t=1 to 5
if t Mod 2=0 Then
y=fun(t,x)+x
else
x=fun(t,y)+y
end if
next t
print t;x;y
end sub
Private Function fun(n As Integer,m As Integer) As Integer
m=n-1+t
n=m+n-t
fun=m*n
end function
望高人详解每一步

option Explicit '强制声明,即每个变量都要声明
Dim t as integer '定义t为整型
Private sub command1_Click() 'command1的单击事件
dim x as integer,y as integer '定义x、y为整型
x=1:y=1 'x=1,y=1
for t=1 to 5 '循环,从1 到5
if t Mod 2=0 Then '如果t整除2
y=fun(t,x)+x 'y=调用fun并加上x
else '否则
x=fun(t,y)+y 'x调用fun并加上y
end if '结束if语句
next t 'for循环的匹配语句
print t;x;y ' 在同一行打印t,x,y 的值
end sub '过程结束
Private Function fun(n As Integer,m As Integer) As Integer '自定义过程
m=n-1+t 'm(fun过程调用的第二个数,n为第一个数)
n=m+n-t
fun=m*n '这些不用再说明了吧??
end function