




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
上机程序设计题题解(P116P126)71. 加法器Private Sub Form_Load() Text1.Alignment = 1 Text2.Alignment = 1 Text3.Alignment = 1 Text3.Locked=TrueEnd SubPrivate Sub Command1_Click() Text3.Text = Str(Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command2_Click() Text1.Text = Text2.Text = Text3.Text = Text1.SetFocusEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii 57 Then KeyAscii = 0 End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)If KeyAscii 57 Then KeyAscii = 0 End IfEnd SubPrivate Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii 57 Then KeyAscii = 0 End IfEnd Sub2. 健康称Private Sub Command1_Click() Dim sg As String, tz As String, bz As String sg = Str(Text1.Text) tz = Str(Text2.Text) bz = sg - 105 If tz/ bz = 1.1 Then Label5.Caption = 偏胖,注意节俭! ElseIf tz / bz = 0.9 Then Label5.Caption = 偏瘦,增加营养! Else Label5.Caption = 正常。继续保持! End IfEnd SubPrivate Sub Form_Load() Form1.Caption = 健康称 Text1.Alignment = 1 Text2.Alignment = 1 Text1.MaxLength = 3 Text2.MaxLength = 3End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii 57 Then KeyAscii = 0: Text1.SetFocusEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii 57 Then KeyAscii = 0: Text2.SetFocusEnd Sub3. 最大化Private Sub Form_Load() Command1.Left = (Form1.ScaleWidth - Command1.Width) / 2 Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 Command1.Caption = 最大化(&L)End SubPrivate Sub Command1_Click() If Command1.Caption = 最大化(&L) Then Command1.Caption = 还原(&B) Form1.WindowState = 2 Command1.Left = (Form1.ScaleWidth - Command1.Width) / 2 Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 Else Command1.Caption = 最大化(&L) Form1.WindowState = 0 Command1.Left = (Form1.ScaleWidth - Command1.Width) / 2 Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 End IfEnd Sub4. 判断质数Private Sub Command1_Click()Dim i As Integer, X As IntegerIf Not IsNumeric(Text1.Text) Then MsgBox 输入的不是数字,无法计算, , designElseX = Val(Text1)If X = 2 Or X = 3 Then Label3.Caption = X & 是质数Else For i = 2 To Sqr(X) If X Mod i = 0 Then Exit For Next If i Sqr(X) Then Label3.Caption = X & 是质数 Else Label3.Caption = X & 不是质数 End IfEnd IfEnd IfEnd Sub5. 计算平均成绩Private Sub Form_Load() Text2.Locked = TrueEnd SubPrivate Sub Text1_Change(Index As Integer) Text2 = Text2 = (Val(Text1(0) + Val(Text1(1) + Val(Text1(2) / 3End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii 57 ThenKeyAscii = 0beep End IfEnd Sub6. 收款计算Private Sub Form_Load() Text3.Locked = TrueEnd SubPrivate Sub Command1_Click() 清除 Text1 = Text2 = Text3 = Text1.SetFocusEnd SubPrivate Sub Command2_Click() 计算 Dim a as single, b as integera=val(text1)b=val(text2)if b=0 then text2=1:b=1 Text3 =a *bEnd Sub7. 编辑Private Sub Command1_Click() 复制 Clipboard.SetText (Text1.SelText)End SubPrivate Sub Command2_Click() 剪切 Clipboard.SetText (Text1.SelText) Text1.SelText = End SubPrivate Sub Command3_Click() 粘贴 Text1.SelText = Clipboard.GetTextEnd SubPrivate Sub Command4_Click() Text1.SelText = End Sub8. 密码检验Private Sub Form_Load() 以下属性都可以在属性窗口中设置 Text1.MaxLength = 7 Text1.PasswordChar = * Label2.Alignment = 2 Label2.ForeColor = vbRed Label2.FontName = 宋体 Label2.FontBold = False Label2.FontItalic = False Label2.FontSize = 20 End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) Static times As Integer If KeyAscii = 13 Then If Text1.Text = 1234567 Then Label2.Caption = 欢迎光临! Label2.Visible = True Else If times = 0Then Label2.Caption = 密码不符,请再输一遍! Label2.Visible = True Text1.Text = Else Label2.Caption = 非法用户,请退出程序! Text1.Text = Text1.Enabled = False End IfEnd Iftimes = times + 1 End IfEnd Sub9. 密码修改Private Sub Command1_Click()If Text1 = Text2 And Text1 = admin Then if Text3 = Text4 thenMsgBox 密码修改成功!,”修改密码”End ElseMsgbox “新密码有误,请重试!”, ”修改密码”End if Else MsgBox 用户名或密码无效,请重试!,”修改密码”End IfEnd SubPrivate Sub Command2_Click() EndEnd Sub10. 字符排序Private Sub Command1_Click() Dim a() As String, i As Integer, p As Integer n = Len(Text1) ReDim a(n) For i = 1 To n a(i) = Mid(Text1, i, 1) Next For i = 1 To n - 1 p = i For j = i + 1 To n If a(j) a(p) Then p = j Next t = a(i): a(i) = a(p): a(p) = t Next For i = 1 To n Print a(i); NextEnd SubPrivate Sub Command2_Click() EndEnd Sub11. 替换Private Sub Command1_Click() Dim len1 As Integer, len2 As Integer, len3 As Integer len1 = Len(Text1) len2 = Len(Text2) len3 = Len(Text3) Do While i = len1 If Text2 = Mid(Text1, i + 1, len2) Then Text1.SetFocus Text1.SelStart = i Text1.SelLength = len2 Text1.SelText = Text3 i = i + len3 len1 = len1 - len2 + len3 Else i = i + 1 End If LoopEnd Sub12. 显示星期年月Private Sub Option1_Click() 显示星期几 n = Weekday(Date) - 1Text1.Text = 今天是星期 & nEnd SubPrivate Sub Option2_Click() 显示年份 Text1.Text = 今天是 & Year(Date) & 年End SubPrivate Sub Option3_Click() 显示月份Text1.Text = 今天是 & Month(Date) & 月End SubPrivate Sub Option4_Click() 显示日期 Text1.Text = 今天是 & Day(Date) & 日End SubPrivate Sub Command1_Click() 结束 EndEnd Sub13. 字体修饰Private Sub Check1_Click(Index As Integer)Select Case IndexCase 0 If Check1(0).Value = 1 Then Label1.FontBold = True Else Label1.FontBold = False End IfCase 1 If Check1(1).Value = 1 Then Label1.FontItalic = True Else Label1.FontItalic = False End IfEnd SelectEnd SubPrivate Sub Option1_Click(Index As Integer)Select Case IndexCase 0 Label1.FontName = 宋体Case 1 Label1.FontName = 楷体_GB2312End SelectEnd Sub14. 点餐Private Sub Form_Load()For i = 0 To 2 Text1(i).Enabled = FalseNextEnd SubPrivate Sub Check1_Click(Index As Integer) If Check1(Index).Value=1 Then Text1(Index).Enabled = TrueText1(Index).SetFocus ElseText1(index).Enabled=FalseText1(index).text=” End IfEnd SubPrivate Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer Dim money As Integer a = Val(Text1(0) b = Val(Text1(1) c = Val(Text1(2) money = 13 * a + 18 * b + 25 * c n = MsgBox(一共 & money & 元, 0, 工程1)End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii 57 Then KeyAscii = 0 End IfEnd Sub15. 输出选择的信息Private Sub Form_Load() Combo1.AddItem 联想 Combo1.AddItem Dell Combo1.Text = 联想End Sub Private Sub Check1_Click() If Check1.Value = 1 Then Combo1.Enabled = True Text1.Enabled = True Else Combo1.Enabled = False Text1.Enabled = False End IfEnd SubPrivate Sub Check2_Click()If Check2.Value = 1 Then Option1.Enabled = True Option2.Enabled = True Else Option1.Enabled = False Option2.Enabled = False End IfEnd SubPrivate Sub Command1_Click()If Option1.Value = True Then Label3.Caption = Combo1.Text & Text1 & win2000Else Label3.Caption = Combo1.Text & Text1 & win98End IfEnd Sub16. 改变字号Private Sub Form_Load()HScroll1.Max = 72HScroll1.Min = 12Label1.FontSize = HScroll1.ValueEnd SubPrivate Sub HScroll1_Change()Text1.Text = HScroll1.ValueLabel1.FontSize = HScroll1.ValueEnd SubPrivate Sub HScroll1_Scroll() Call HScroll1_ChangeEnd SubPrivate Sub Text1_Change() Dim i As Integer i = Val(Text1.Text) If i = 12 And i = 72 Then Label1.FontSize = i HScroll1.Value = i End IfEnd Sub17. 标签移动Private Sub Form_Load() HScroll1.Max = Form1.ScaleWidth-Label1.Width HScroll1.Value = Label1.LeftEnd SubPrivate Sub HScroll1_Change() Label1.Left = HScroll1.ValueEnd SubPrivate Sub HScroll1_Scroll() Call HScroll1_ChangeEnd SubPrivate Sub Command1_Click() 结束 EndEnd Sub18. 调色板Private Sub Command1_Click() Label2.ForeColor = RGB(HScroll1(0).Value, HScroll1(1).Value, HScroll1(2).Value)End SubPrivate Sub HScroll1_Change(Index As Integer) Dim red As Integer, green As Integer, blue As Integer red = HScroll1(0).Value green =HScroll1(1).Value blue = HScroll1(2).Value Shape1.FillColor = RGB(red, green, blue)End SubPrivate Sub HScroll1_Scroll(Index As Integer) Call HScroll1_Change(Index)End Sub19. 字体设置Private Sub Form_Load()Combo1.AddItem 宋体Combo1.AddItem 黑体Combo1.AddItem 楷体_Gb2312Combo2. AddItem “10”Combo2. AddItem “12”Combo2. AddItem “16”Combo2. AddItem “20”Combo2. AddItem “24”Combo2. AddItem “36”Combo2. AddItem “48”Combo2. AddItem “72”End SubPrivate Sub Combo1_Click()Text1.FontName = Combo1.TextEnd SubPrivate Sub Combo2_Click()Text1.FontSize = Combo2.TextEnd Sub20. 格式设置Private Sub Combo1_click() Select Case Combo1.Text Case 左对齐 Text1.Alignment = 0 Case 居中 Text1.Alignment = 2 Case 右对齐 Text1.Alignment = 1 End SelectEnd SubPrivate Sub Combo2_click() Select Case Combo2.Text Case 常规 Text1.FontBold = False Text1.FontItalic = False Case 斜体 Text1.FontBold = False Text1.FontItalic = True Case 粗体 Text1.FontBold = True Text1.FontItalic = False Case 粗斜体 Text1.FontBold = True Text1.FontItalic = True End SelectEnd Sub21. 添加与删除 Private Sub Command1_Click() If Len(Text1.Text) = 0 Then MsgBox 没有内容,不予添加! Text1.SetFocus Else List1.AddItem Text1.Text, 0 Text1.Text = Text1.SetFocus End IfEnd SubPrivate Sub Command2_Click() If List1.ListIndex = -1 Then MsgBox 请选择输出的项目 Else List1.RemoveItem List1.ListIndex End IfEnd Sub22. 偶数迁移Private Sub Form_Load() List1.Clear List2.ClearEnd Sub Private Sub Command1_Click()Dim I As IntegerRandomizeList1.ClearList2.ClearFor I = 1 To 10 List1.AddItem (Int(Rnd * 90) + 10)Next IEnd SubPrivate Sub Command2_Click()Dim I As Integer, n As IntegerDo While I If List1.ListIndex -1 Then List2.AddItem List1.Text List1.RemoveItem List1.ListIndex Else MsgBox 先选择,再移动 End IfEnd SubPrivate Sub Command2_Click() Do While List1.ListCount 0 List2.AddItem List1.List(0) List1.RemoveItem 0 LoopEnd SubPrivate Sub Command3_Click() If List2.ListIndex -1 Then List1.AddItem List2.Text List2.RemoveItem List2.ListIndexElse MsgBox 先选择,再移动 End IfEnd SubPrivate Sub Command4_Click() Do While List2.ListCount 0 List1.AddItem List2.List(0) List2.RemoveItem 0 LoopEnd SubPrivate Sub Command5_Click() 结束 EndEnd Sub24. 添加删除信息Dim n As IntegerDim a() As StringDim id As IntegerPrivate Sub Combo1_Click() Dim i As Integer id = Combo1.ListIndex For i = 0 To 3 Text1(i).Text = a(i, id) Next iEnd SubPrivate Sub Command1_Click() Dim i As Integer If Text1(0).Text = Then MsgBox 请输入要添加的内容, , 警告 Else ReDim Preserve a(3, n) For i = 0 To 3 a(i, n) = Text1(i).Text Next i Combo1.AddItem a(0, n) n = n + 1 End If For i = 0 To 3 Text1(i).Text = Next iEnd SubPrivate Sub Command2_Click() Dim i As Integer, j As Integer If Combo1.ListIndex = -1 Then MsgBox 请选择要删除的条目, , 警告 Else For i = id To Combo1.ListCount - 2 For j = 0 To 3 a(j, i) = a(j, i + 1) Next j Next i n = n - 1 ReDim Preserve a(3, n) Combo1.RemoveItem id End If Combo1.Text = For i = 0 To 3 Text1(i).Text = Next iEnd Sub25. 电子钟Private Sub Form_Load() Timer1.Interval = 1000 Timer2.Interval = 500 Form1.Caption = 电子钟 Timer2.Enabled = FalseEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Timer2.Enabled = True End IfEnd SubPrivate Sub Timer1_Timer() Label1.Caption = TimeEnd SubPrivate Sub Timer2_Timer() If Time Text1.Text Then If Label1.BackColor = RGB(255, 255, 255) Then Label1.BackColor = RGB(255, 0, 0) Else Label1.BackColor = RGB(255, 255, 255) End If End IfEnd SubEnd Sub26. 倒计时Dim pretime As Integer, mm As Integer, ss As IntegerPrivate Sub Command1_Click() Command1.Enabled = False Frame1.Enabled = False Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load() Timer1.Enabled = False Timer1.Interval = 1000 pretime = 60End SubPrivate Sub Option1_Click(Index As Integer) Select Case Index Case 0 pretime = 60 Case 1 pretime = 300 Case 2 pretime = 600 End SelectEnd SubPrivate Sub Timer1_Timer() mm = pretime 60 ss = pretime Mod 60 Label1.Caption = Str(mm) & 分 & Str(ss) & 秒 If mm = 0 And ss = 0 Then Timer1.Enabled = False Command1.Enabled = True Frame1.Enabled = True End If pretime = pretime - 1End Sub27. 字幕闪烁Private Sub Form_Load() Label1.Caption = 祝你考试成功! Timer1.Interval = 300 Label1.Alignment = 1Timer1.Enabled = FalseLabel1.ForeColor = VbRedEnd SubPrivate Sub Command1_Click() If Command1.Caption = 开始 Then Timer1.Enabled = True Command1.Caption = 停止 Else Command1.Caption = 开始 Timer1.Enabled = False End IfEnd SubPrivate Sub Timer1_Timer() If Label1.ForeColor = VbRed Then Label1.ForeColor =VbBlue Else Label1.ForeColor =VbRed End IfEnd Sub28. 字体滚动Private Sub Form_Load() Form1.Caption = 字体滚动 Timer1.Interval = 100 Timer1.Enabled = False Label1.ForeColor = vbRedEnd SubPrivate Sub Command1_Click() If Command1.Caption = 开始 ThenTimer1.Enabled = TrueCommand1.Caption = 停止 Else Timer1.Enabled = False Command1.Caption = 开始 End IfEnd SubPrivate Sub Timer1_Timer() If Label1.Left = Form1.Width Then Label1.Left = -Label1.Width Else Label1.Left = Label1.Left + 100 End IfEnd Sub29. 字幕放大Private Sub Form_Load()Form1.Caption = 字幕放大Label1.Caption = 欢迎光临!Timer1.Enabled = FalseTimer1.Interval = 200End SubPrivate Sub Command1_Click() If Command1.Caption = 开始 Then Timer1.Enabled = True: Command1.Caption = 停止 Else Timer1.Enabled = False: Command1.Caption = 开始 End IfEnd SubPrivate Sub Timer1_Timer() Label1.FontSize = Label1.FontSize + 2End Sub30. 拨号盘Dim s As StringPrivate Sub Form_Load() Form1.Caption = 拨号键: Text1.Alignment = 1 Text1.MaxLength = 10 Text1.FontName = 宋体 Text1.FontBold = True字体为三号字在属性窗口中设置 Text1.ForeColor = vbBlue str1 = : Timer1.Interval = 500: Text1.Text = Timer1.Enabled = FalseEnd SubPrivate Sub Command1_Click(Index As Integer)Text1.Text = Text1.Text + Trim(Str(Index)End SubPrivate Sub Command2_Click()Timer1.Enabled = Trues = Text1.TextText1.Text = End SubPrivate Sub Timer1_Timer()Static i As IntegerText1.Text = Text1.Text + Mid(s, i + 1, 1)i = i + 1If i = Len(s) Then Timer1.Enabled = False i = 0End IfEnd Sub31. 简单动画演示Dim n As IntegerPrivate Sub Form_Load() Dim i As Integer For i = 0 To 5 Label2(i).Visible = False Next Timer1.Enabled = False Timer1.Interval = 1000End SubPrivate Sub Command1_Click() Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click() Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer() For i = 0 To 5 If i = n Then Label2(i).Visible = True Else Label2(i).Visible = False Next n = n + 1If n 5 Then n = 0End Sub32. 改变大小Dim a As Single, b As SinglePrivate Sub Form_Load()a = Shape1.Left + Shape1.Width / 2b = Shape1.Top + Shape1.Height / 2Shape1.Width = HScroll1.ValueShape1.Height = HScroll1.ValueEnd SubPrivate Sub HScroll1_Change()Shape1.Width = HScroll1.ValueShape1.Height = HScroll1.ValueShape1.Left = a - HScroll1.Value / 2Shape1.Top = b - HScroll1.Value / 2Label2.Caption = HScroll1.ValueEnd SubPrivate Sub HScroll1_Scroll()Call HScroll1_ChangeEnd Sub33. 作图Private Sub Command1_Click() Picture1.Scale (-10, -10)-(10, 10) Picture1.Line (-10, 0)-(10, 0) Picture1.Line (0, -10)-(0, 10) Picture1.CurrentX = 0: Picture1.CurrentY = 0: Picture1.Print (0,0)End SubPrivate Sub Command2_Click() Const pi = 3.1415926535 Picture1.Scale (-10, -10)-(10, 10) Picture1.FillColor = RGB(0, 255, 0): Picture1.FillStyle = 0 Picture1.Circle (0, 0), 5, vbRed, -pi / 6, -5 * pi / 6 End SubPrivate Sub Command3_Click() EndEnd Sub34. 画板Private Sub Command1_Click() CommonDialog1.showcolor Pictu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 森林防火业务知识培训课件
- 森林火灾防范知识培训课件
- 森林消防水电知识培训课件
- 棋类培训课件
- 桥梁防撞理论知识培训课件
- 2025年陵园工作招聘笔试模拟试题及答案
- 2025年健康管理师(高级)实操技能考核试题及答案
- 2025年电子商务战略规划师中级求职面试全攻略及预测题库
- 2025年财务会计实操模拟题集及参考答案详解
- 2026届广东省深圳高级中学化学高二第一学期期中综合测试模拟试题含解析
- 近视推拿培训课件
- 2025年国企运维岗笔试题目及答案
- 2025年职业卫生培训试题及答案
- 2025年江苏省建筑施工企业主要负责人安全员A证考核题库含答案
- 2025年洛阳理工学院招聘硕士研究生学历专任教师考试笔试试题(含答案)
- 中华人民共和国治安管理处罚法2025修订版测试题及答案
- 广西柳州市2024-2025学年七年级下学期期末历史试题 (含答案)
- 无人机应用技术专业认识
- 备考2025年湖北省宜昌市辅警协警笔试笔试预测试题(含答案)
- 新学期教学工作会议上校长讲话:把功夫下在课堂里把心思放在学生上把质量落到细节中
- 初中语文教师培训
评论
0/150
提交评论