版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、VB语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = 练习 Command1.Caption = 确定 Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = Visual Basic程序设计教程 End Subex0102Private Sub Command1_Click()Txt.Text = 我有电脑 End SubPrivate Sub Command2_Click()Txt.Text = 我没有电脑 End SubPrivate Sub Comm
2、and3_Click()Txt.Text = 一对双撇号,中间不留空 End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * x End Subex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r A 2Text1.Text = 圆的面积为 & s End Subex0204Private Sub Command1_Click() 最大化 按钮Form1.Wi
3、ndowState = 2最大化End Sub还原 按钮还原Private Sub Command2_Click()Form1.WindowState = 0最小化 按钮 最小化End SubPrivate Sub Command3_Click() Form1.WindowState = 1 End Sub ex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * y End Sub ex0206Pr
4、ivate Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1) End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integer求百位数求十位数求个位数生成倒序数 显示倒序数x = Val(InputBox(请输入一个三位数 )a = Int(x / 100)b = Int(x / 10) - a * 10c = x M
5、od 10Showy = c * 100 + b * 10 + aPrint x; 倒序数为: ; y End Sub ex0302Private Sub Command1_Click() n = Val(Text1.Text) Randomize21x = Int(1 + n * Rnd)Label1.Caption = x = Int(1 + n * Rnd)Label2.Caption = x = Int(1 + n * Rnd)Label3.Caption = 第一个随机数 + Str(x)第二个随机数 + Str(x)第三个随机数 + Str(x)End Sub ex0303Priv
6、ate Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = 您已下达显示命令 End SubPrivate Sub Form_Click()Cmd1.Visible = True End Sub ex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint 输入字符: ; Chr(KeyAscii), ASCII 码为 ; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Sub ex0305Private Sub Form_Load()
7、请确认 )请确认 )x = MsgBox( 在这里显示提示信息 , 4 + 0, 请确认 )x = MsgBox( 在这里显示 + Chr(13) + 提示信息 , 3 + 0, x = MsgBox( 在这里显示 + Chr(13) + 提示信息 , 2 + 16 + 0, End Sub ex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox(输入一个整数(1 35000)s = 奇数If x Mod 2 = 0 Then s = 偶数MsgBox sEnd Sub ex0402Private Sub Comm
8、and1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text) d = Val(Text4.Text) If a b Then求 a、b 中的较大数m = a ElseEnd IfIf c d Thend 中的较大数ElseEnd IfIf m n Then求 m、n 中的较大数Elsex = nEnd If Text5
9、.Text = xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As String t = Mid(Text1.Text, 5, 1) Select Case tCase 2 p = 博士生 Case 3 p = 硕士生 Case 4 p = 本科生 Case 5 p = 专科生 Case Elsep = 无效学号 End SelectText2.Text = Left(Text1.Text, 2) + 级 Text3.Text = pEnd Subex0404Private Sub Command1_Click()r
10、= 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = 0LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.
11、FontSize = 22LabClk.FontName = 黑体 TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1End Subex0406Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
12、 Single) If Text1.SelLength 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = False End Subex0501Private Sub Form_Load()Dim k As I
13、nteger, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2 s = s + kNext k ShowPrint 1100范围内的奇数和:”;sEnd Subex0502 Private Sub Form_Load()Dim s As Single Show s = 0For k = 1 To 200 s = s + k / (1 + k * k)Next kPrint Int(s * 10 + 0.5) / 10End Subex0503Private Sub Form_Load()Show k = 2 s = 0Do Whi
14、le k = A And t = Z Then y = y + xEnd IfNext kText2.Text = yEnd Sub ex0507Private Sub Command1_click()FontSize = 12ClsFor i = 0 To List1.ListCount - 1 If List1.Selected(i) Then Print List1.List(i)End IfNext i显示 按钮单击事件逐项判断 真时为选定End Sub ex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c
15、 = 1 To 9For d = 1 To 9x = 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 ThenPrint A= & a & ,B= & b & ,C= & c & ,D= & d End IfNext dNext cNext bNext aEnd Sub ex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As Int
16、eger RandomizeFor i = 1 To 10 a(i) = Int(Rnd * 90 + 10) Print a(i);Next iPrint min = a(1) pos = 1For k = 2 To 10If a(k) max Then max = a(i, j): r = i: c = jEnd IfNext j, iPrint 最大值为: ; maxPrint 位于行: ; r, 列: ; c End Sub ex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n)
17、.Value = TrueEnd SubPrivate Sub Form_Load()n = 1 End Subex0607Private Sub Form_Load() Dim a(20) As Integer Randomize a(1) = Int(10 + 90 * Rnd) k = 1Do While k y Then max = xElsemax = y End IfEnd Function ex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(
18、k).Text)Next kCall 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 Sub ex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox(输入一个数 )Print x; 的位数为: ; fnws(x)End SubFunction fnws(x As Long) As IntegerDim n As Integern = 1Do While x 10 0n = n + 1x = x
19、 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.HideForm2.ShowElsen = n + 1T
20、ext1.SetFocusIf n = 3 ThenForm1.Hide Form3.ShowEnd IfEnd IfText1.Text = Text2.Text = End Sub ex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowF
21、or i = 1 To 12Print String(20 - i, 32); For j = 1 To 2 * i - 1If j 9 Then k = k + 7 Print Chr(k + 48);Next jPrint Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click()Randomizes = For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) s = s + xNext kText1.Text = sText2.Text = Text2.Locked
22、 = FalseText2.SetFocusText3.Text = Text4.Text = f = 0 输出当前行左边的空格,分号表示下一输出项紧接输出 输出 2*i-1 个字符按左、右两边指定输出字符左边输出的字符右边输出的字符字母的 ASCII 码比数字大 7以字符格式输出换行产生原稿文”按钮随机产生小写字母显示在文本框中允许录入设置焦点第 1 次按键标记, 0 表示未按键End SubPrivate Sub Command2_Click() “结束”按钮EndEnd Sub第 1 次按键时,开始计时 用 t 保存第 1 次按键的时间 表示已按键和进入录入过程Private Sub T
23、ext2_KeyUp(KeyCode As Integer, Shift As Integer) Dim c As Integer, k As IntegerIf f = 0 Thent = Timerf = 1 1End If显示用户当前所用时间If Len(Text2.Text) 30 ThenText3.Text = Round(Timer - t, 1) & 秒 Elsec = 0统计录入正确的字母个数For k = 1 To 30If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Then c = c + 1End If禁止录入 显示准确
24、率Next k Text2.Locked = True Text4.Text = Round(c / 30 * 100, 2) & % End IfEnd Subex0901Private Sub Command1_Click()Open 静夜思 .txt For Input As #1Do While Not EOF(1) 文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() 产生随机数 For i = 1 To 20
25、d(i) = Int(1 + 99 * Rnd) List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() 保存 Open MyFile4.txt For Output As #1For i = 1 To 20 Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() 读出 Open MyFile4.txt For Input As #1Do While Not EOF(1) Input #1, x List2.AddItem xLoopClose #1End S
26、ubPrivate Sub Command4_Click() 结束 EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6第 7 章 ex070 & k & .vbpIf Dir(fn) = ThenPrint Mid(fn, 4) & 未编写! ElsePrint Mid(fn, 4) & 已编写! End IfNext kEnd Subex0904Private Sub Form_Load()chedir = C:Documents and SettingsLinMy Documentsfsodir If Dir(chedir,
27、16) = ThenMkDir chedirEnd Ifchefile = C:Windowsnotepad.exeIf Dir(chefile) ThenFileCopy chefile, chedir & mynotepad.exeEnd IfMsgBox 操作完毕! End Sub ex1002Private 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年居间服务协议法律解释要点
- 2024年城市绿化苗木供应合同
- 2024专业版房产交易协议要览版
- 2024国际劳务合作协议模板版B版
- 2024咨询业务信息安全保障合同版B版
- 2024年度办公设备OEM生产与质量保证协议
- 2024区域调料供应商与分销商协议条款
- 2024年外卖送餐员聘用合同版B版
- 2024别墅室内装饰合同范本
- 2024寄卖寄存协议
- 智能出行的基础架构
- 新时代企业财务管理的未来发展趋势
- 肖春宏老师讲授内容(22年10月至22年11月)
- 订购单模板(订货单模板)
- 骨牵引术知情同意书
- 营养科肠外配置护理质量控制管理考核标准
- 国家开放大学《比较初等教育》终结性考核大作业参考答案
- 中国特色社会主义进入新时代教案高中政治必修一中国特色社会主义
- 传染病报告ICD编码解说版
- 股权变更登记表
- 第5课家族の写真课件-初中日语人教版第一册2
评论
0/150
提交评论