




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
VB语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click() Caption = 练习 Command1.Caption = 确定 Label1.FontBold = True Label1.AutoSize = True Label1.Caption = Visual Basic程序设计教程End Subex0102Private Sub Command1_Click() Txt.Text = 我有电脑End SubPrivate Sub Command2_Click() Txt.Text = 我没有电脑End SubPrivate Sub Command3_Click() Txt.Text = 一对双撇号,中间不留空End Subex0104Private Sub Command1_Click() Dim x As Single x = Val(Text1.Text) Text2.Text = 15 * xEnd Subex0202Private Sub Form_Click() Dim r As Single, s As Single r = 4.6 s = 3.14159 * r 2 Text1.Text = 圆的面积为 & sEnd Subex0204Private Sub Command1_Click() 最大化按钮 Form1.WindowState = 2 最大化End SubPrivate Sub Command2_Click() 还原按钮 Form1.WindowState = 0 还原End SubPrivate Sub Command3_Click() 最小化按钮 Form1.WindowState = 1 最小化End Subex0205Private Sub command1_click() Dim x As Single Dim y As Single x = Val(Text1.Text) y = Val(Text2.Text) Text3.Text = x * x + y * yEnd Subex0206Private Sub command1_click() Dim x As String x = Text1.Text Text2.Text = Left(x, 1) + Right(x, 1)End Subex0301Private Sub Form_Load() Dim x As Integer, y As Integer Dim a As Integer, b As Integer, c As Integer x = Val(InputBox(请输入一个三位数) a = Int(x / 100) 求百位数 b = Int(x / 10) - a * 10 求十位数 c = x Mod 10 求个位数 Show y = c * 100 + b * 10 + a 生成倒序数 Print x; 倒序数为:; y 显示倒序数End Subex0302Private Sub Command1_Click() n = Val(Text1.Text) Randomize x = Int(1 + n * Rnd) Label1.Caption = 第一个随机数 + Str(x) x = Int(1 + n * Rnd) Label2.Caption = 第二个随机数 + Str(x) x = Int(1 + n * Rnd) Label3.Caption = 第三个随机数 + Str(x)End Subex0303Private Sub Cmd1_Click() Lab1.Visible = True Lab1.Caption = 您已下达显示命令End SubPrivate Sub Form_Click() Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer) Show Print 输入字符:; Chr(KeyAscii), ASCII码为; KeyAsciiEnd SubPrivate Sub Form_DblClick() ClsEnd Subex0305Private Sub Form_Load() x = MsgBox(在这里显示提示信息, 4 + 0, 请确认) x = MsgBox(在这里显示 + Chr(13) + 提示信息, 3 + 0, 请确认) x = MsgBox(在这里显示 + Chr(13) + 提示信息, 2 + 16 + 0, 请确认)End Subex0401Private Sub Form_Load() Dim x As Long, s As String x = InputBox(输入一个整数(135000) s = 奇数 If x Mod 2 = 0 Then s = 偶数 MsgBox sEnd Subex0402Private Sub Command1_Click() Dim a As Single, b As Single Dim c As Single, d As Single Dim m As Single, n As Single, x As Single Show a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) d = Val(Text4.Text) If a b Then 求a、b中的较大数 m = a Else m = b End If If c d Then 求c、d中的较大数 n = c Else n = d End If If m n Then 求m、n中的较大数 x = m Else x = n End If Text5.Text = xEnd Subex0403Private Sub Command1_Click() Dim t As String, p As String t = Mid(Text1.Text, 5, 1) Select Case t Case 2 p = 博士生 Case 3 p = 硕士生 Case 4 p = 本科生 Case 5 p = 专科生 Case Else p = 无效学号 End Select Text2.Text = Left(Text1.Text, 2) + 级 Text3.Text = pEnd Subex0404Private Sub Command1_Click() r = 0: g = 0: b = 0 If Check1.Value = 1 Then r = 255 End If If Check2.Value = 1 Then g = 255 End If If Check3.Value = 1 Then b = 255 End If Label1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click() EndEnd Subex0405Private Sub Form_Load() LabClk.Caption = 0 LabClk.Alignment = 1 LabClk.BorderStyle = 1 LabClk.FontSize = 22 LabClk.FontName = 黑体 TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer() LabClk.Caption = Val(LabClk.Caption) + 1End Subex0406Private Sub Form_Load() Command1.Enabled = False Command2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Text1.SelLength 0 Then Command1.Enabled = True End IfEnd SubPrivate Sub Command1_Click() Command1.Enabled = True Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click() Text2.Text = Text1.SelText Command1.Enabled = False Command2.Enabled = FalseEnd Subex0501Private Sub Form_Load() Dim k As Integer, s As Integer, t As Integer s = 0 For k = 1 To 100 Step 2 s = s + k Next k Show Print 1100范围内的奇数和:; sEnd Subex0502Private Sub Form_Load() Dim s As Single Show s = 0 For k = 1 To 200 s = s + k / (1 + k * k) Next k Print Int(s * 10 + 0.5) / 10End Subex0503Private Sub Form_Load() Show k = 2 s = 0 Do While k = A And t = Z Then y = y + x End If Next k Text2.Text = yEnd Subex0507Private Sub Command1_click() 显示按钮单击事件 FontSize = 12 Cls For i = 0 To List1.ListCount - 1 逐项判断 If List1.Selected(i) Then 真时为选定 Print List1.List(i) End If Next iEnd Subex0508Private Sub Form_Load() Show For a = 1 To 9 For b = 1 To 9 For c = 1 To 9 For d = 1 To 9 x = a * 1000 + b * 100 + c * 10 + d y = b * 1000 + a * 100 + a * 10 + c z = d * 100 + d * 10 + a If x - y = z Then Print A= & a & ,B= & b & ,C= & c & ,D= & d End If Next d Next c Next b Next aEnd Subex0601Private Sub Command1_Click() Dim a(10) As Integer, min As Integer, pos As Integer Randomize For i = 1 To 10 a(i) = Int(Rnd * 90 + 10) Print a(i); Next i Print min = a(1) pos = 1 For k = 2 To 10 If a(k) max Then 判断有无更大数 max = a(i, j): r = i: c = j End If Next j, i Print 最大值为:; max Print 位于行:; r, 列:; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click() n = n + 1 If n = 3 Then n = 0 Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load() n = 1End Subex0607Private Sub Form_Load() Dim a(20) As Integer Randomize a(1) = Int(10 + 90 * Rnd) k = 1 Do While k y Then max = x Else max = y End IfEnd Functionex0703Private Sub Command1_Click() Dim d(5) As Single, m As Single For k = 0 To 5 d(k) = Val(Text1(k).Text) Next k Call Max(d(0), d(1), d(2), m) Call Max(m, d(3), d(4), m) Call Max(m, m, d(5), m) Text2.Text = mEnd Subex0704Private Sub Form_Load() Dim x As Long Show x = Val(InputBox(输入一个数) Print x; 的位数为:; fnws(x)End SubFunction fnws(x As Long) As Integer Dim n As Integer n = 1 Do While x 10 0 n = n + 1 x = x 10 Loop fnws = nEnd Functionex0705Private Sub C1_Click() Form1.HideEnd Subex0705APrivate Sub C2_Click() Form1.ShowEnd Subex0706Dim n As IntegerPrivate Sub Command1_Click() usern = Trim(Text1.Text) passw = Trim(Text2.Text) If usern = username And passw = password Then Form1.Hide Form2.Show Else n = n + 1 Text1.SetFocus If n = 3 Then Form1.Hide Form3.Show End If End If Text1.Text = Text2.Text = End Subex0706APrivate Sub Command1_Click() Form2.Hide Form1.ShowEnd Subex0906BPrivate Sub Command1_Click() Unload Form1 Unload Form2 Unload Form3 EndEnd Subex0802Private Sub Form_Load() Dim i As Integer, j As Integer Show For i = 1 To 12 Print String(20 - i, 32); 输出当前行左边的空格,分号表示下一输出项紧接输出 For j = 1 To 2 * i - 1 输出2*i-1个字符 If j 9 Then k = k + 7 字母的ASCII码比数字大7 Print Chr(k + 48); 以字符格式输出 Next j Print 换行 Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() “产生原稿文”按钮 Randomize s = For k = 1 To 30 x = Chr(Int(Rnd * 26) + 97) 随机产生小写字母 s = s + x Next k Text1.Text = s 显示在文本框中 Text2.Text = Text2.Locked = False 允许录入 Text2.SetFocus 设置焦点 Text3.Text = Text4.Text = f = 0 第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() “结束”按钮 EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer) Dim c As Integer, k As Integer If f = 0 Then 第1次按键时,开始计时 t = Timer 用t保存第1次按键的时间 f = 1 1表示已按键和进入录入过程 End If If Len(Text2.Text) 30 Then Text3.Text = Round(Timer - t, 1) & 秒 显示用户当前所用时间 Else c = 0 For k = 1 To 30 统计录入正确的字母个数 If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Then c = c + 1 End If Next k Text2.Locked = True 禁止录入 Text4.Text = Round(c / 30 * 100, 2) & % 显示准确率 End IfEnd Subex0901Private Sub Command1_Click() Open 静夜思.txt For Input As #1 Do While Not EOF(1) 文件未结束时,循环 Input #1, x List1.AddItem x Loop Close #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() 产生随机数 For i = 1 To 20 d(i) = Int(1 + 99 * Rnd) List1.AddItem d(i) Next iEnd SubPrivate Sub Command2_Click() 保存 Open MyFile4.txt For Output As #1 For i = 1 To 20 Write #1, d(i) Next i Close #1End SubPrivate Sub Command3_Click() 读出 Open MyFile4.txt For Input As #1 Do While Not EOF(1) Input #1, x List2.AddItem x Loop Close #1End SubPrivate Sub Command4_Click() 结束 EndEnd Subex0903Private Sub Form_Load() Show For k = 1 To 6 fn = .第7章ex070 & k & .vbp If Dir(fn) = Then Print Mid(fn, 4) & 未编写! Else Print Mid(fn, 4) & 已编写! End If Next kEnd Subex0904Private Sub Form_Load() chedir = C:Documents and SettingsLinMy Documentsfsodir If Dir(chedir, 16) = Then MkDir chedir End If chefile = C:Windowsnotepad.exe If Dir(chefile) Then FileCopy chefile, chedir & mynotepad.exe End If MsgBox 操作完毕!End Subex1002Private Sub A1_Click() Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click() Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click() Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Butt
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO 80000-9:2019/AMD1:2025 FR Amendment 1 - Quantities and units - Part 9: Physical chemistry and molecular physics
- 【正版授权】 IEC 62453-1:2025 FR Field device tool (FDT) interface specification - Part 1: Overview and guidance
- 【正版授权】 IEC 60730-2-13:2025 EN-FR Automatic electrical controls - Part 2-13: Particular requirements for humidity sensing controls
- 新解读《GB-T 6009-2014工业无水硫酸钠》
- 新解读《GB 30734-2014消防员照明灯具》
- 图书中的一封鸡汤信直接让我从咸鱼变超人!讲义-2025届高考英语复习之读后续写
- 统编版语文三年级下册期末冲刺特训卷(含答案)
- 人教版(PEP)四年级英语上册Unit 6 单元教学设计
- 重复的奥秘课件
- 老年人窒息课件
- (2025秋新版)部编版八年级上册道德与法治全册教案
- 八年级心理健康体验式教学计划
- 消防监控考试题初级及答案
- 《小学开学第一课》课件
- 《小学英语教学研究》近年考试真题参考题库(含答案)
- 网络与信息安全巡检表
- 《路由与交换技术》课程教学大纲
- 北师大版八年级数学上册教案(全册完整版)教学设计含教学反思
- 国家自然科学基金联合申报协议书
- 新教科版五年级科学上册全册课件(精品PPT)
- 教学课件:大学生心理素质训练
评论
0/150
提交评论