在窗体上画一个名称为 Command1 的命令按钮,然后编写下列通用过程和命令按钮的事件过程:
Private Function fun(ByVal m As Integer)
If m Mod 2=0 Then
fun=2
Else
fun=1
End If
End Function
Private Sub Command1_Click
Dim i As Integer,s As Integer
s=0
For i = 1 To 5
s=s+fun(i)
Next
Print s
End Sub
程序运行后,单击命令按钮,在窗体上显示的是
Private Function fun(ByVal m As Integer)
If m Mod 2=0 Then
fun=2
Else
fun=1
End If
End Function
Private Sub Command1_Click
Dim i As Integer,s As Integer
s=0
For i = 1 To 5
s=s+fun(i)
Next
Print s
End Sub
程序运行后,单击命令按钮,在窗体上显示的是
举一反三
- 中国大学MOOC: 在窗体上添加一个命令按钮Command1,然后编写如下事件过程:Private Sub Command1_Click() Dim a As Integer, s As Integer a = 8 s = 1 Do s = s + a a = a - 1 Loop While a <= 0 Print s; aEnd Sub程序运行后,单击命令按钮,则窗体上显示的内容是( )。
- 运行下列程序,单击窗体显示的结果为( )。 Private Sub Form_Click() Dim a Dim s As Integer, i As Integer a = Array(1, 2, 3) For i = 2 To 0 Step -1 s = s + a(i) * a(i) Next i Print s End Sub
- 编写如下程序: Private Sub Command1_Click() Dim n As Integer : Static s As Integer For n = 1 To 3 s = s + n Next Print s End Sub 程序运行后,第三次单击命令按钮Command1时,输出结果为
- 设有下面程序: Function F( a As Integer) b = 0 Static c b= b + 1 c= c + 2 F= a + b + c End Function Private Sub Command1_Click() Dim a As Integer a = 2 For i = 1 to 3 Print F(a); Next i End Sub 运行上面的程序,单击命令按钮 Command1 ,输出结果为________
- 阅读程序: Function Fun(a As Integer) Static C b=0:b=b+2:c=c+2 F=a*b*c End Function Private Sub Command1_Click() Dim a As Integer a=2 For i=1 To 2 Print Fun( A: ; B: Next C: End Sub D: 运行上面的程序,单击命令按钮,输出结果为A) 8 16 E: 9 18 F: 10 20 G: 7 14