已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为。 Public Function Fn(n) If n = 0 Then Fn = 1 Else Fn = Fn(n - 1) * n End Function Private Sub Command1_Click() Print Fn(6) End Sub
举一反三
- 窗体上有一个名为Command1的命令按钮,编写如下事件过程: Private Sub Command1_Click() i = 0 Do While i < 8 For j = 1 To i n = n + 1 Next i = i + 1 Loop Print n End Sub 运行程序,单击命令按钮,则输出结果是______。
- 设有以下函数过程: Function fact(n As Long) If n = 1 Then fact = 1 Else fact = n * fact(n - 1) End If End Function 在窗体上画一个命令按钮和两个文本框,然后编写如下事件过程: Private Sub Command1_Click() Dim n As Long, result As Long n = Val(Text1.Text) result = fact(n) Text2.Text = Str(result) End Sub 程序运行时,如果在文本框 Text1 中输入数据 5 后,单击命令按钮 Command1 ,则在文本框 Text2 上输出的结果为________
- 在窗体上有一命令按钮Command1,其Click事件代码如下: Private Sub Command1_Click() Dim a%, b%, i%, n% For i = 1 To 10 n = InputBox("请输入一个整数", "输入数据框", 2) If n Mod 2 = 0 Then a = a + 1 Else b = b + 1 End If Next i MsgBox ("运行结果a=" & str(a) & ", b=" & str(b)) 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时,输出结果为
- 编写如下程序: Private Sub Command1_Click; Dim m As Integer, n As Integer m = 2 : n = 1 Select Case m Case 1 Select Case n Case 1 Print "AAA" Case 2 Print "BBB" End Select Case 2 Print "CCC" End Select End Sub 程序运行后,单击命令按钮Command1,输出结果为 A: BBB B: CCC C: AAA D: 1