VisualBasic程序设计教程曹青邱李华等编著机械工业出版社答案.doc

上传人:good****022 文档编号:116529968 上传时间:2022-07-05 格式:DOC 页数:15 大小:133KB
返回 下载 相关 举报
VisualBasic程序设计教程曹青邱李华等编著机械工业出版社答案.doc_第1页
第1页 / 共15页
VisualBasic程序设计教程曹青邱李华等编著机械工业出版社答案.doc_第2页
第2页 / 共15页
VisualBasic程序设计教程曹青邱李华等编著机械工业出版社答案.doc_第3页
第3页 / 共15页
点击查看更多>>
资源描述
家电维修社团整理- 15 -P37#2-4Private Sub cmdBegin_Click() Timer1.Enabled = True 激活定时器 cmdBegin.Enabled = False cmdEnd.Enabled = TrueEnd SubPrivate Sub cmdEnd_Click() Timer1.Enabled = False 关闭定时器 Label1.Left = 0 标签归位到窗体左侧 cmdBegin.Enabled = True cmdEnd.Enabled = FalseEnd SubPrivate Sub Form_Load() Label1.Left = 0 初始将标签归位到窗体左侧End SubPrivate Sub Timer1_Timer() Label1.Move Label1.Left + 20 每隔0.1秒标签向右移动20缇End Sub2-5Dim tmpPrivate Sub Command1_Click() “复制”按钮 Text1.SetFocus 焦点定位在文本框Text1 tmp = Text1.SelText 将选中的内容存放在变量tmp中End SubPrivate Sub Command2_Click() “剪切”按钮 tmp = Text1.SelText 将选中的内容存放在变量tmp中 Text1.SelText = 将选中的内容置为空串 Text1.SetFocus 焦点定位在文本框Text1End SubPrivate Sub Command3_Click() “粘贴”按钮 Text1.SelText = tmp 将变量tmp的值赋给文本框选中的内容 Text1.SetFocus 焦点定位在文本框Text1End SubPrivate Sub Command4_Click() “下划线”按钮 Text1.FontUnderline = Not Text1.FontUnderline 设置或取消下划线End SubPrivate Sub Command5_Click() “删除线”按钮 Text1.FontStrikethru = Not Text1.FontStrikethru 设置或取消删除线End SubPrivate Sub Command6_Click() “加粗”按钮 Text1.FontBold = Not Text1.FontBold 设置或取消加粗线End SubPrivate Sub Command7_Click() “倾斜”按钮 Text1.FontItalic = Not Text1.FontItalic 设置或取消倾斜End SubPrivate Sub Command8_Click() “放大”按钮 Text1.FontSize = Text1.FontSize + 5 字体放大5磅End SubPrivate Sub Command9_Click() “缩小”按钮 Text1.FontSize = Text1.FontSize - 5 字体缩小5磅End SubP38#2-8Private Sub Form_Load() 在开始运行时设置各文本框的文字大小和字体 Text2.FontName = 隶书 Text2.FontSize = 16 Text3.FontName = 楷体_GB2312 Text3.FontSize = 18End SubPrivate Sub Text1_Change() 在Text1中改变内容时改变Text2和Text3的内容 Text2.Text = Text1.Text Text3.Text = Text1.TextEnd SubPrivate Sub Command1_Click() 清除按钮 Text1.Text = End SubPrivate Sub Command2_Click() 退出按钮 EndEnd Sub2-9Private Sub Command1_Click()Command1.Visible = FalseCommand2.Visible = TrueLabel1.BorderStyle = 1End SubPrivate Sub Command2_Click()Command1.Visible = TrueCommand2.Visible = FalseLabel1.BorderStyle = 0End SubPrivate Sub Command3_Click()Command3.Visible = FalseCommand4.Visible = TrueLabel1.BackStyle = 1End SubPrivate Sub Command4_Click()Command3.Visible = TrueCommand4.Visible = FalseLabel1.BackStyle = 0End SubP60/613-1Private Sub Command1_Click() Const pi = 3.1415926535898 Dim h As Single Dim r As Single h = Val(Text1.Text) r = Val(Text2.Text) Text3.Text = Format(pi * r 2, 0.000) Text4.Text = Format(2 * pi * r * h, 0.000) Text5.Text = Format(pi * r 2 * h, 0.000)End Sub3-2Private Sub Command1_Click() Randomize Text1.Text = Int(Rnd * 100 + 1) Text2.Text = Int(Rnd * 100 + 1) Text3.Text = End SubPrivate Sub Command2_Click() Text3.Text = Val(Text1.Text) + Val(Text2.Text)End Sub3-4Private Sub Timer1_Timer() y = Year(Date) 求当前日期的年份 mon = Month(Date) 求当前日期的月份 d = Day(Date) 求当前日期是月份中的第几天 Label1.Caption = y & 年 & mon & 月 & d & 日 将年、月、日串接起来 h = Hour(Time) 求当前时间的小时部分 Min = Minute(Time) 求当前时间的分钟部分 s = Second(Time) 求当前时间的秒部分 Label2.Caption = h & 时 & Min & 分 & s & 秒 将时、分、秒串接起来End SubP684-4Option ExplicitPrivate Sub Command1_Click() Dim A As Single, B As Single, C As Single Dim P As Single, S As Single A = Val(Text1.Text) B = Val(Text2.Text) C = Val(Text3.Text) P = (A + B + C) / 2 S = Sqr(P * (P - A) * (P - B) * (P - C) Label2.Caption = Format(Str(S), 0.00) 显示时保留两位小数End SubP76#4-1Private Sub Command1_Click() ZJ.Text = Val(DJ.Text) * Val(SL.Text)End SubPrivate Sub Command2_Click() EndEnd Sub4-3Private Sub Command1_Click() X = Val(Text1.Text) X1 = X * 3.1416 / 180 SX = Abs(Sin(X1) CX = Abs(Cos(X1) Text2.Text = Text2.Text & _ Format(X, 0.000) & & _ Format(SX, 0.000) & & _ Format(CX, 0.000) & Chr(13) & Chr(10) Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text)End Sub4-4Private Sub Form_Click() h = Val(InputBox(请输入小时, 将时间转换成秒, 0) m = Val(InputBox(请输入分, 将时间转换成秒, 0) s = Val(InputBox(请输入秒, 将时间转换成秒, 0) Total = h * 3600 + m * 60 + s Print h; 小时; m; 分; s; 秒=; Total; 秒End SubP895-5Private Sub Text1_Change() Label2.Caption = End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)Static I As Integer 变量I统计输入错误口令的次数If KeyCode = 13 Then 如果按下的键为回车键 If UCase(Text1.Text) = HELLO Then 如果口令为HELLO Label2.Caption = 恭喜!,您已成功进入本系统 ElseIf I = 0 Or I = 1 Then 如果口令错且错误次数少于2 I = I + 1 Label2.Caption = 口令错!,请重新输入 Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Else 如果口令错且错误次数等于2 MsgBox 对不起,您不能使用本系统 End 退出应用程序。 End IfEnd IfEnd SubP92#5-1Private Sub Command1_Click() x = Val(Text1.Text) If x Mod 3 = 0 And x Mod 5 = 0 And x Mod 7 = 0 Then Text2.Text = 能同时被3、5、7整除 Else Text2.Text = 不能整除End Sub5-2Private Sub Form_Load()Dim x As Single, y As Single, z As Single, max As Single, min As Singlex = InputBox(第一个)y = InputBox(第二个)z = InputBox(第三个)If x y Then max = xElse: max = yEnd IfIf max z Then max = zw = MsgBox( 最大值 & max)End IfIf x z Then min = zw = MsgBox( 最小值 & min)End IfText1.Text = maxText2.Text = minEnd Sub5-6Private Sub Command1_Click() x = Val(Text1.Text) Select Case x Case Is 100 Label2.Caption = MsgBox 输入的数据超出范围,请重新输入 Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Case Is = 90 Label2.Caption = 优 Case Is = 80 Label2.Caption = 良 Case Is = 70 Label2.Caption = 中 Case Is = 60 Label2.Caption = 及格 Case Else Label2.Caption = 不及格 End SelectEnd Sub5-7Dim I As IntegerPrivate Sub Command1_Click() kl = UCase(Trim(Text1.Text) If kl = ABCD Then I = 0 Form2.Show Else If I = 2 Then MsgBox 对不起,您不能使用本系统 End Else Form1.Caption = 口令错,请重新输入 I = I + 1 Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End IfEnd SubPrivate Sub Text1_Change() Form1.Caption = 口令检测End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then kl = UCase(Trim(Text1.Text) If kl = ABCD Then I = 0 Form2.Show Else If I = 2 Then MsgBox 对不起,您不能使用本系统 End Else Form1.Caption = 口令错,请重新输入 I = I + 1 Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End If End IfEnd SubP96#6-2Private Sub Form_Click() A = 1 B = 1 Text1.Text = Str(A) & Str(B) & Chr(13) & Chr(10) For I = 1 To 9 A = A + B B = A + B Text1.Text = Text1.Text & Str(A) & Str(B) & Chr(13) & Chr(10) Next IEnd SubP101#6-6A*Private Sub Picture1_Click() For I = 1 To 9 For J = 1 To 9 Picture1.Print Format(I); ; Format(J); =; Format(I * J, !); Next J Picture1.Print Next IEnd SubB*Private Sub Picture1_Click() For I = 1 To 9 For J = 1 To I Picture1.Print Format(I); ; Format(J); =; Format(I * J, !); Next J Picture1.Print Next IEnd SubP106#6-11Dim N As IntegerPrivate Sub Command1_Click() “求最大公约数”按钮的事件过程 M = Val(Text1.Text): N = Val(Text2.Text) 输入M,N A = M: B = N 将M、N暂时保存在变量A、B中,用于求最小公倍数 R = M Mod N 求M除以N的余数R Do While R 0 当余数R不为0时执行循环体 M = N 将除数N做为新的被除数M N = R 将余数R做为新的除数N R = M Mod N 求M除以N的余数R Loop Label3.Caption = N 输出最大公约数N Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click() 求最小公倍数按钮的事件过程 Label4.Caption = Val(Text1.Text) * Val(Text2.Text) / NEnd Sub6-12Private Sub Command1_Click() N = Val(Text1.Text): K = Int(Sqr(N): I = 2 Do While I = K If N Mod I 0 Then I = I + 1 不能整除,ID的值累加1 Else Exit Do 整除,退出循环 End If Loop If I = K Then Label2.Caption = 不是素数 Else Label2.Caption = 是素数 End IfEnd SubPrivate Sub Text1_Change() Label2.Caption = End SubP1136-1Private Sub Command1_Click() s1 = 0 For k = 1 To 100 s1 = s1 + k Next k s2 = 0 For k = 1 To 50 s2 = s2 + k 2 Next k s3 = 0 For k = 1 To 10 s3 = s3 + 1 / k Next k Label1.Caption = Format(s1 + s2 + s3, 0.0000)End Sub6-2Private Sub Command1_Click() s = 0 n = Val(Text1.Text) k = 2 For i = 1 To 2 * n - 1 Step 2 s = s + (-1) k * 1 / i k = k + 1 Next i s = 4 * s Text2.Text = Format(s, 0.0000)End Sub6-3Private Sub Command1_Click() a = Val(InputBox(请输入A) n = Val(InputBox(请输入N) Sum = 0 Item = 0 For j = 1 To n Item = Item * 10 + a Sum = Sum + Item Next j Text1.Text = SumEnd Sub6-4Private Sub Form_Click() a = 2 b = 1 s = 0 For i = 1 To 20 s = s + a / b c = a a = a + b b = c Next i MsgBox 和为: & sEnd Sub6-5Private Sub Command1_Click() n = Val(Text1.Text) f = 1 For i = 1 To n f = f * (2 * i - 1) Next i Label2.Caption = fEnd Sub6-6Private Sub Command1_Click() For i = 3 To 100 Step 2 Text1.Text = Text1.Text & Str(i) & vbCrLf Next iEnd Sub6-9Private Sub Command1_Click()f = 1i = 1Do While f = 400000 f = f * i i = i + 2LoopText1.Text = fEnd Sub6-10Private Sub Command1_Click()m = 0n = 0Do While n 0 num1 = num1 + 1 sum1 = sum1 + A(i) Case Is Max Then Max = a(i) End If Next i Text2.Text = MaxEnd Sub7-5Dim A(1 To 20) As IntegerPrivate Sub Command1_Click() Text1.Text = Randomize For i = 1 To 20 A(i) = Int(Rnd * 50 + 1) Text1.Text = Text1.Text & Str(A(i) & Space(3) Next iEnd SubPrivate Sub Command2_Click() For i = 1 To 19 For j = i + 1 To 20 If A(i) A(j) Then t = A(i) A(i) = A(j) A(j) = t End If Next j Next i Text2.Text = For i = 1 To 20 Text2.Text = Text2.Text & Str(A(i) & Space(3) Next iEnd Sub7-9Dim a(1 To 6, 1 To 6), b(1 To 6, 1 To 6)Private Sub Command1_Click()RandomizePicture1.ClsFor i = 1 To 6 For j = 1 To 6 a(i, j) = Int(Rnd * 10) + 1 Picture1.Print Format(a(i, j), !); Next j Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()RandomizePicture2.ClsFor i = 1 To 6 For j = 1 To 6 b(i, j) = a(j, i) Picture2.Print Format(b(i, j), !); Next j Picture2.PrintNext iEnd Sub7-11Dim a() As Integer, n As IntegerPrivate Sub Form_click() Form1.Cls n = Val(InputBox(请输入行数, , 10) ReDim a(1 To n, 1 To n) a(1, 1) = 1 For i = 2 To n a(i, 1) = 1 a(i, i) = 1 For j = 2 To i - 1 a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j Next i For i = 1 To n For j = 1 To i Print Format(a(i, j), !); Next j Print Next iEnd Sub7-12Dim n As Integer, x As IntegerPrivate Sub Command1_Click() n = n + 1 控件数组的最大下标值加1 Load Text1(n) 添加一个文本框 Text1(n).Visible = True 使新加的文本框可见 Text1(n).Left = Text1(n - 1).Left + Text1(n - 1).Width 使新加的文本框显示在右侧 Load Label1(n) 添加一个标签 Label1(n).Visible = True 使新加的标签可见 Label1(n).Left = Label1(n - 1).Left + Label1(n - 1).Width 使新加的标签显示在右侧 If Form1.Width 0 Then 如果还有控件可以删除 If Form1.Width - Text1(n).Width x Then Form1.Width = x Else Form1.Width = Form1.Width - Text1(n).Width End If Unload Text1(n) 删除文本框控件数组的最后一个元素 Unload Label1(n) 删除标签控件数组的最后一个元素 n = n - 1 控件数组的最大下标值减1 Else MsgBox 不能再删除了 End IfEnd SubPrivate Sub Command3_Click() For i = 0 To n Label1(i).Caption = Text1(n - i).Text Next iEnd SubPrivate Sub Form_Load() x = Form1.WidthEnd SubP1678-2Function area(a, b, c) p = (a + b + c) / 2 area = Sqr(p * (p - a) * (p - b) * (p - c)End FunctionPrivate Sub Command1_Click() a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) d = Val(Text4.Text) e = Val(Text5.Text) f = Val(Text6.Text) g = Val(Text7.Text) 求第一个三角形的面积 area1 = area(a, f, e) 求第二个三角形的面积 area2 = area(f, g, d) 求第三个三角形的面积 area3 = area(b, c, g) 求多边形面积 areasum = area1 + area2 + area3 Label1.Caption = Format(areasum, 0.000)End Sub8-3Function f(k As Integer) As Long Dim sum As Long sum = 0 For i = 1 To k sum = sum + i Next i f = sumEnd FunctionPrivate Sub Command1_Click() Dim m As Integer, n As Integer, p As Integer Dim y As Single m = Val(Text1.Text) n = Val(Text2.Text) p = Val(Text3.Text) y = (f(m) + f(n) / f(p) Text4.Text = Format(y, 0.0000)End Sub8-5Function f(k As Integer) As Long Dim sum As Long sum = 0 For i = 1 To k sum = sum + i Next i f = sumEnd FunctionPrivate Sub Command1_Click() Dim m As Integer, n As Integer, p As Integer Dim y As Single m = Val(Text1.Text) n = Val(Text2.Text) p = Val(Text3.Text) y = (f(m) + f(n) / f(p) Text4.Text = Format(y, 0.0000)End Sub8-7Sub s(k, sum) sum = 0 For i = 1 To k sum = sum + i Next iEnd SubPrivate Sub Form_Click() sum = 0 n = Val(InputBox(请输入N) For i = 1 To n Call s(i, sum1) sum = sum + 1 / sum1 Next i MsgBox Str(sum)End SubP1969-1Private Sub Option1_Click() Shape1.FillColor = vbRedEnd SubPrivate Sub Option2_Click() Shape1.FillColor = vbBlueEnd SubPrivate Sub Option3_Click() Shape1.FillColor = vbGreenEnd SubPrivate Sub Option4_Click() Shape1.FillColor = vbYellowEnd SubPrivate Sub Option5_Click() Shape1.Shape = 3End SubPrivate Sub Option6_Click() Shape1.Shape = 1End SubPrivate Sub Option7_Click() Shape1.Shape = 0End SubPrivate Sub Option8_Click() Shape1.Shape = 2End Sub9-3Private Sub Command1_Click() addit = Trim(InputBox(请输入书名, 注意) If addit Then List1.AddItem addit End IfEnd SubPrivate Sub Command2_Click() If List1.ListCount = 0 Then MsgBox 列表中已经没有书, , 注意 Exit Sub End If If List1.ListIndex = 0 Then List1.RemoveItem List1.ListIndex Else MsgBox 请先选择某本书, , 注意 End IfEnd SubPrivate Sub Command3_Click() Select Case List1.ListIndex Case 0 MsgBox 不能上移, , 注意 Case -1 MsgBox 请先选择, , 注意 Case Else n = List1.ListIndex a = List1.List(n - 1) List1.List(n - 1) = List1.List(n) List1.List(n) = a List1.Selected(n - 1) = True End SelectEnd SubPrivate Sub Command4_Click() Select Case List1.ListIndex Case List1.ListCount - 1 MsgBox 不能下移, , 注意 Case -1 MsgBox 请先选择, , 注意 Case Else n = List1.ListIndex a = List1.List(n + 1) List1.List(n + 1) = List1.List(n) List1.List(n) = a List1.Selected(n + 1) = True End SelectEnd SubPrivate Sub Command5_Click() List1.Selected(0) = TrueEnd SubPrivate Sub Command6_Click() List1.Selected(List1.ListCount - 1) = TrueEnd Sub9-4Private Sub Combo1_Click() Select Case Combo1.Text Case 黑 Text1.ForeColor = vbBlack Case 白 Text1.ForeColor = vbWhite Case 红 Text1.ForeColor = vbRed Case 绿 Text1.ForeColor = vbGreen Case 蓝 Text1.ForeColor = vbBlue Case 黄 Text1.ForeColor = vbYellow End SelectEnd SubPrivate Sub Combo2_Click() Select Case Combo2
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 成人自考


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!