vb课后答案.docx

上传人:牧羊曲112 文档编号:3168381 上传时间:2023-03-11 格式:DOCX 页数:21 大小:40.78KB
返回 下载 相关 举报
vb课后答案.docx_第1页
第1页 / 共21页
vb课后答案.docx_第2页
第2页 / 共21页
vb课后答案.docx_第3页
第3页 / 共21页
vb课后答案.docx_第4页
第4页 / 共21页
vb课后答案.docx_第5页
第5页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《vb课后答案.docx》由会员分享,可在线阅读,更多相关《vb课后答案.docx(21页珍藏版)》请在三一办公上搜索。

1、vb课后答案4.5 Private Sub Command1_Click Dim a As Integer a = Val(Text1) If a Mod 3 = 0 And a Mod 5 = 0 And a Mod 7 = 0 Then Label1.Caption = 能同时被3、5、7整除 Else: a = c c = t End If If b c Then t = b b = c c = t Label1.Caption = 不能被同时整除 End Sub 4.6 Private Sub Command1_Click Dim a As Integer, b As Integer,

2、 c As Integer a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) d = (a + b + c) If a b - c And a 0 And b 0 And c 0 Then Text4.Text = Val(Sqr(d * (d - a) * (d - b) * (d - c) Else MsgBox (数据错误) Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End Sub 4.8 Private Sub

3、 Form_Click a = Val(InputBox(输入第1个数字) b = Val(InputBox(输入第2个数字) c = Val(InputBox(输入第3个数字) If a b Then t = a a = b b = t End If If a c Then t = a End If Label1.Caption = 最小数 & Str(a) & vbCrLf & 最大数 & Str(c) End Sub 4.9 Private Sub Command1_Click Dim a As Integer a = Val(Text1.Text) b = a Mod 3 Select

4、 Case b Case Is = 0 MsgBox (Str(a) & 除以3余 & Str(b) Case Is = 1 MsgBox (Str(a) & 除以3余 & Str(b) Case Is = 2 MsgBox (Str(a) & 除以3余 & Str(b) End Select End Sub 4.13 Private Sub Text1_Change a = Right(Text1.Text, 1) If Asc(a) = 97 Then Label1.Caption = UCase(a) ElseIf Asc(a) = 65 And Asc(a) = 10 -5 i = i

5、 + 1 Sum = Sum * i e = e + 1 / Sum Wend Print ; e End Sub 4.17 Private Sub Form_Click For i = 100 To 200 If i Mod 7 0 Then Print 数字是 & Str(i) End If Next i End Sub 4.18 Private Sub Form_Click n = Val(InputBox(数字) For i = 1 To n a = a + i Sum = Sum + a Next i Print 和是 & Str(Sum) End Sub 4.19 Private

6、Sub Form_Click s = 1 a = 1 While s = i1 Then Text1.Text = Text1 & Str(i1) Space(1) End If Next i1 End Sub 例4.13 例4.15 4t.1 Private Sub Command1_Click Dim a, b As Integer Randomize a = Int(41 * Rnd + 10) b = Int(41 * Rnd + 10) Text1 = a Text2 = b End Sub Private Sub Command2_Click Text3 = Val(Text1)

7、* Val(Text2) Text3.Locked = True End Sub 4t.3 Private Sub Command1_Click Dim a, b As Integer a = Val(InputBox(身高) b = Val(InputBox(体重) Text1.Text = a Text2.Text = b c = Val(b / (a * a) & MsgBox (你的身高体指数为: & End Sub Str(c) End Sub 4t.9 4t.12 Private Sub Form_Click Dim a, b, c As Integer a = Val(Input

8、Box() b = Val(InputBox() c = Val(InputBox() Print Tab(2); 输入的数据是: Print Tab(3); a; b; c If a b Then t = a a = b b = t End If If a c Then t = a a = c c = t End If If b c Then t = b b = c c = t End If Print Tab(2); 降序后: Print Tab(3); a; b; c Print Print Tab(2); 其中最大值为: ; a Print Tab(2); 其中最小值为:; c 4t.

9、15 Private Sub Command1_Click Dim n As Integer, sum As Long sum = 1 n = Val(Text1) For i = 1 To n sum = sum * i Next i Text2 = Str(sum) Private Sub Command2_Click Dim n As Integer, sum As Long sum = 1 n = Val(Text1) For i = 1 To n + 2 sum = sum * i Next i Text3 = Str(sum) End Sub 4t.16 Private Sub F

10、orm_Click s = 1 While s = 100000 i = i + 1 s = s * (2 * i) Wend Print s=; s End Sub 4t.23 Private Sub Form_Click Dim a, b As Integer Cls Randomize a = Val(Int(100 * Rnd + 1) b = Val(Int(100 * Rnd + 1) Print Tab(2); 随机数是: Print Tab(3); a, b c = a Mod b d = a * b While c 0 a = b b = c c = a Mod b Wend

11、 Print Tab(2); 最大公约数: Print Tab(3); b Print Tab(2); 最小倍数: Print Tab(3); d / b End Sub 4t.24 Private Sub Picture1_Click For i = 1 To 9 For j = 1 To 9 Picture1.Print Trim(i); *; Next i End Sub 4t.27 Trim(j); =; Format(i * !); Next j Picture1.Print Next i End Sub 4t.25 Private Sub Command1_Click p = FE

12、DCBA For i = 1 To 6 Picture1.Print Right(p, i) Next i End Sub Private Sub Command2_Click For i = 6 To 1 Step -1 Picture1.Print Tab(7 - i); For j = 1 To i Picture2.Print Chr(64 + j); Next j Picture2.Print Next i End Sub Private Sub Command3_Click For i = 1 To 6 Picture1.Print Tab(7 - i); For j = i To

13、 1 Step -1 Picture3.Print Chr(71 - j); Next j Picture3.Print Next i End Sub Private Sub Command4_Click For i = 6 To 1 Step -1 For j = 1 To i Picture4.Print Chr(64 + (i - j + 1); Next j Picture4.Print j, 5.7 Private Sub Check1_Click Label1.FontItalic = Check1.Value End Sub Private Sub Check2_Click La

14、bel1.FontUnderline = Check2.Value End Sub Private Sub Option1_Click Label1.FontSize = 10 End Sub Private Sub Option2_Click Label1.FontSize = 13 End Sub Private Sub Option3_Click Label1.FontSize = 15 End Sub 5.8 Private Sub Command1_Click Shape1.Shape = 3 End Sub Private Sub Command2_Click Shape1.Sha

15、pe = 5 End Sub Private Sub Command3_Click Shape1.Shape = 0 - rectangle End Sub Private Sub Command4_Click Shape1.Shape = 2 - oval End Sub 5.9 Private Sub Command1_Click For i = 0 To List1.ListCount - 1 If List1.List(i) = Text1 Then Exit For Next i If i = List1.ListCount Then List1.AddItem Text1.Text

16、 End If End Sub Private Sub Command2_Click If List1.SelCount 0 Then List1.RemoveItem List1.ListIndex Else MsgBox 请选择要删除的列表 Case 4 Text1.BackColor = vbBlue Case 5 Text1.BackColor = vbYellow End Select End Sub Private Sub Combo3_Click Select Case Combo3.ListIndex Case 0 项 End If End Sub Private Sub Co

17、mmand3_Click List1.Clear Text1.Text = End Sub 5.10 Private Sub Combo1_Click Select Case Combo1.ListIndex Case 0 Text1.ForeColor = vbWhite Case 1 Text1.ForeColor = vbBlack Case 2 Text1.ForeColor = vbRed Case 3 Text1.ForeColor = vbGreen Case 4 Text1.ForeColor = vbBlue Case 5 Text1.ForeColor = vbYellow

18、 End Select End Sub Private Sub Combo2_Click Select Case Combo2.ListIndex Case 0 Text1.BackColor = vbWhite Case 1 Text1.BackColor = vbBlack Case 2 Text1.BackColor = vbRed Case 3 Text1.BackColor = vbGreen Text1.Alignment = 0 Case 1 Text1.Alignment = 2 Case 2 Text1.Alignment = 1 End Select End Sub 5.1

19、1 Private Sub VScroll1_Change Label3.Caption = VScroll1.Value Label4.Caption=(5*(Val(VScroll1.Value) - 32) / 9 End Sub Private Sub VScroll1_Scroll Label3.Caption = VScroll1.Value Label4.Caption=(5*(Val(VScroll1.Value) - 32) / 9 End Sub 5.14 Private Sub Timer1_Timer Static i As Integer Select Case i

20、Mod 3 Case 0 Text1.BackColor = vbRed Case 1 Text1.BackColor = vbGreen Case 2 Text1.BackColor = vbYellow End Select i = i + 1 End Sub 5.15 Private Sub Command2_Click Timer1.Enabled = False End Sub Private Sub Command1_Click Timer1.Enabled = True End Sub Private Sub Form_Load Timer1.Enabled = False En

21、d Sub Private Sub Timer1_Timer Static a As Integer Select Case a Case 0 Label1.Left = Label1.Left + 1000 If Label1.Left = (Form1.Width - Label1.Width) Then a = 1 Case 1 Label1.Left = Label1.Left - 1000 If Label1.Left 2 Then s = 0 Select Case a Case 0 Text1.Left = Text1.Left + 1000 If Text1.Left = (F

22、orm1.Width - Text1.Width) Then a = 1 Case 1 Text1.Left = Text1.Left - 1000 If Text1.Left = 0 Then a = 0 End Select End Sub 5t.11 Private Sub List1_DblClick For i = 0 To List1.ListCount - 1 s = s + Val(List1.List(i) Next i List1.AddItem s End Sub 6.1 Option Base 1 Dim a As Integer Private Sub Command

23、1_Click ReDim a(10) For i = 1 To 10 Randomize a(i) = Int(90 * Rnd + 10) Sum = Sum + a(i) Picture1.Print a(i); Next i For j = 1 To 10 For k = j To 10 If a(j) = a(j) Then r = a(j) a(j) = a(i) a(i) = r End If Next j Next i For u = 1 To 10 Picture1.Print a(u); Next u End Sub 6.6 Dim a As Integer Private

24、 Sub Command1_Click n = Val(Text1) ReDim a(n, n) For i = 1 To n For j = 1 To i a(1, 1) = 1 a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j Next i For i = 1 To n Print Tab(3 * n - 3 * i); For j = 1 To i Print Format(a(i, j), !); Next j Print Next i End Sub 6t.1 Dim a(10) As Integer Private Sub Command

25、1_Click For i = 1 To 10 Randomize a(i) = Int(90 * Rnd + 10) Text1 = Text1 & Space(1) & a(i) Next i End Sub Private Sub Command2_Click For i = 1 To 10 For j = i To 10 If a(i) a(j) Then t = a(j) a(j) = a(i) a(i) = t End If Next j Text2 = Text2 & Space(1) & a(i) Next i End Sub 6t.2 Dim a(20) As Integer

26、 Private Sub Command1_Click For i = 1 To 20 a(i) = Int(90 * Rnd + 10) List1.AddItem a(i) Next i End Sub Private Sub Command2_Click For i = 1 To 20 For j = i To 20 If a(i) = n Then Label1.Caption = n & yes Else Label1.Caption = n & not End If End Sub Private Sub Command1_Click a = Val(Text1) Call j(a

27、) End Sub 7t.5 Function j(a, b, c) Max = a If Max b Then Max = b If Max b Then Min = b If Min c Then Min = c k = Min End Function Private Sub Command1_Click a = Val(Text1) b = Val(Text2) c = Val(Text3) Text4 = j(a, b, c) Text5 = k(a, b, c) End Sub 7t.8 Function d(n) s = 1 For i = 1 To n s = s * i Ne

28、xt i d = s End Function Function p(n) For i = 1 To n Sum = Sum + d(i) Next i p = Sum End Function Private Sub Form_Click b = Val(InputBox(num) Print p(b) End Sub 8.4 Private Sub AA1_Click Text3.Text=Val(Text1.Text)+Val(Text2.Text) End Sub Private Sub AA2_Click Text3.Text=Val(Text1.Text)-Val(Text2.Te

29、xt) End Sub Private Sub AA4_Click Text3.Text=Val(Text1.Text)*Val(Text2.Text) End Sub Private Sub AA5_Click Text3.Text=Val(Text1.Text)/Val(Text2.Text) End Sub 8.6 Private Sub AA1_Click Text1.FontBold = Not Text1.FontBold AA1.Checked = Not AA1.Checked End Sub Private Sub AA2_Click Text1.FontItalic = N

30、ot Text1.FontItalic AA2.Checked = Not AA2.Checked End Sub Private Sub AA3_Click Text1.FontUnderline=NotText1.FontUnderline AA3.Checked = Not AA3.Checked End Sub Private Sub Dis_Click Text1.Visible = True End Sub Private Sub Hid_Click Text1.Visible = False End Sub Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As End Sub Private Sub copy_Click Text2.Text = Text1.Text End

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号