《vb高教出版龚沛曾主编课后实验题目解析.doc》由会员分享,可在线阅读,更多相关《vb高教出版龚沛曾主编课后实验题目解析.doc(35页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、,A1Private Sub Command1_Click() Label3 = Text1End SubA2Private Sub Form_Load() Timer1.Interval = 0End SubPrivate Sub Command1_Click() 自动 Timer1.Interval = 200End SubPrivate Sub Command2_Click() 手动 Timer1.Interval = 0 Call MyMoveEnd SubPrivate Sub Timer1_Timer() Call MyMoveEnd SubSub MyMove() Label1.
2、Move Label1.Left - 50 If Label1.Left 0 Then Label1.Left = Form1.WidthEnd SubA3Private Sub Form_Click() Text1 = Val(Text1) + 1End SubPrivate Sub Form_Load() Text1 = 0End SubA4Private Sub Form_Click() Caption = 单击窗体,改变图片 Picture = LoadPicture(App.Path + n_015.bmp) Print 欢迎使用VBEnd SubPrivate Sub Form_D
3、blClick() Cls Caption = 双击窗体,卸去图片 Picture = LoadPicture() End SubPrivate Sub Form_Load() Caption = 装入窗体 Picture = LoadPicture(App.Path + n_016.bmp) Print 装入图End SubPrivate Sub Form_Resize() 该事件的作用窗体始终与图一样大 Caption = 窗体大小不变 Form1.Width = 260 * 16 260是Tongji-2.bmp图的宽度,象素单位 Form1.Height = 260 * 16 + 20
4、0 260是图的高度,象素单位,200是窗体的标题栏高度End SubA5Sub Command1_Click() Text1.FontName = 隶书 Text1.FontSize = 25End SubSub Command2_Click() Text2.Text = Text1.SelText Text2.FontName = Text1.FontName Text2.FontSize = Text1.FontSizeEnd SubB1Private Sub Command1_Click()Text2 = Format(5 / 9 * (Val(Text1) - 32), 0.00)E
5、nd SubPrivate Sub Command2_Click() Text1 = Format(9 / 5 * Val(Text2) + 32, 0.00)End Sub或Private Sub Command1_Click() Dim f!, c! 声明两个变量 f = Val(Text1) c = 5 / 9 * (f - 32) Text2 = Format(c, 0.00) 保留两位小数End SubPrivate Sub Command2_Click() Dim ff!, cc! 声明两个变量 cc = Val(Text2) ff = 9 / 5 * cc + 32 Text1
6、= Format(ff, 0.00) 保留两位小数End SubB2Private Sub Command1_Click()Label2 = Format(Val(Text1) * Val(Text1) * 3.14, 0.00)End SubPrivate Sub Command2_Click() Label3 = Format(Val(Text1) * 3.14 * 2, 0.00)End SubPrivate Sub Text1_LostFocus() If Not IsNumeric(Text1.Text) Then MsgBox 输入有非数字字符,请重新输入, , 警告 Text1.
7、Text = Text1.SetFocus End IfEnd Sub或Private Sub Command1_Click()Label2 = Format(Val(Text1) * Val(Text1) * 3.14, 0.00)End SubPrivate Sub Command2_Click() Label3 = Format(Val(Text1) * 3.14 * 2, 0.00)End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If Not IsNumeric(Text1.Tex
8、t) Then Text1.Text = End If End IfEnd SubB3Private Sub Command1_Click() n = Int(Log(2) / Log(1.008) + 1) Label1 = n & 年后人数超过26亿End SubB4Private Sub Command1_Click() Dim x, dx, cd x = Text1.Text dx = UCase(x) cd = Len(x) Print 大写字母为:; dx Print 字符串长度为:; cdEnd SubB5Private Sub Command1_Click() Text1 =
9、Int(Rnd * 900 + 100)End SubPrivate Sub Command2_Click() Dim x%, x1%, x2%, x3% x = Val(Text1) x1 = x Mod 10 分离出的个位数 x2 = (x Mod 100) 10 分离出的十位数 x3 = x 100 分离出的百位数 Label1 = x1 * 100 + x2 * 10 + x3End SubB6Private Sub Form_Click()Label1 = Left(Text1, 11) Label2 = Mid(Text1, 12, 6) Label3 = Right(Text1,
10、 5)End SubB7Private Sub Command1_Click() Print For i = 1 To 5 Print Tab(15 - i * 2); String(2 * i - 1, ); Spc(18 - 4 * (i - 1); String(2 * i - 1, ) Next iEnd SubPrivate Sub Command2_Click() ClsEnd Sub进一步要求:Private Sub Command1_Click() Print For i = 1 To 5 Print Tab(15 - i * 2); String(2 * i - 1, );
11、String(10 - (2 * i - 1), ); String(2 * i - 1, ) Next iEnd SubPrivate Sub Command2_Click() ClsEnd SubB8Private Sub Form_Click()x = Val(InputBox(输入一正实数, 计算, 0)pf = Format(x * x, 0.000)pfg = Format(Sqr(x), 0.000)lf = Format(x * x * x, 0.000)lfg = Format(x (1 / 3), 0.000)Print 平方为:; pf; Space(5); 平方根为:;
12、 pfg; Space(5); 立方为:; lf; Space(5); 立方根为:; lfgEnd SubC1Private Sub Form_Click()Dim x!, y!x = Val(InputBox(输入x的值)If x 1000 Theny = xElseIf x 2000 Theny = 0.9 * xElseIf x 3000 Theny = 0.8 * xElsey = 0.7 * xEnd IfPrint yEnd SubC2Private Sub Form_Click()Dim x!, y!x = Val(InputBox(输入上网时间)If x 10 Theny =
13、30ElseIf x 150 Theny = 150End IfPrint yEnd SubC3Private Sub Command1_Click() Dim x!, y!, z! x = InputBox(input x) y = InputBox(input y) z = InputBox(input z) Print x y z Print 排序前; x; ; y; ; z If x y Then t = x: x = y: y = t If x z Then t = x: x = z: z = t If y z Then t = y: y = z: z = t Print 排序后 &
14、 x & & y & & zEnd SubPrivate Sub Command2_Click() Dim x!, y!, z! x = InputBox(input x) y = InputBox(input y) z = InputBox(input z) Print x y z Print 排序前; x; ; y; ; z If x y Then t = x: x = y: y = t If y z Then t = y: y = z: z = t If x a(i + 1) Thenz = a(i + 1)a(i + 1) = a(i)a(i) = zEnd IfNext iPictu
15、re2.Print a(0)Picture2.Print a(1)Picture2.Print a(2)End SubC5Private Sub Text2_LostFocus() Dim m%, n%, y% m = Val(Text1) n = Val(Text2) If n Mod 2 0 Then MsgBox (脚数必定为偶数) Text2 = Text2.SetFocus Else y = n / 2 - m If y 0 Then Text4 = Format(-b + Sqr(de) / t, 0.00) Text5 = Format(-b - Sqr(de) / t, 0.0
16、0)Else Text4 = Format(-b / t, 0.00) & + & Format(Sqr(Abs(de) / t, 0.00) & i Text5 = Format(-b / t, 0.00) & - & Format(Sqr(Abs(de) / t, 0.00) & iEnd IfEnd SubPrivate Sub Command2_Click()Text1 = Text2 = Text3 = Text4 = Text5 = End SubC7Private Sub Text3_LostFocus() Select Case Trim(Text3) Case + Text4
17、 = Val(Text1) + Val(Text2) Case - Text4 = Val(Text1) - Val(Text2) Case * Text4 = Val(Text1) * Val(Text2) Case / If Val(Text2) = 0 Then MsgBox 分母为零,重新输入 Text2 = Text2.SetFocus Else Text4 = Val(Text1) / Val(Text2) End If End SelectEnd SubC8Private Sub Text1_LostFocus() Select Case Trim(Text1) Case 1 T
18、ext2 = Monday Case 2 Text2 = Tuesday Case 3 Text2 = Wednesday Case 4 Text2 = Thursday Case 5 Text2 = Friday Case 6 Text2 = Saturday Case 7 Text2 = Sunday Case Is 7, Is 7 Or Text1 1 Then MsgBox 数字为17,重新输入 Text1 = Text1.SetFocusElse Text2 = Choose(Text1, Monday, Tuesday, Wednesday, Thursday, Friday, S
19、aturday, Sunday)End IfEnd SubD1Private Sub Form_Click() For i = 1 To 9 Print Tab(10 - i); String(2 * i - 1, Trim(Str(i)Next iEnd SubD2Private Sub Form_Click()For i = 1 To 10 Step 1 Print Tab(i); String(20 - 2 * i), Chr(64 + i)Next iEnd SubD3Private Sub Command1_Click()Dim s!, t!, i&s = 1t = 1For i =
20、 1 To 100000t = t + is = s + 1 / tIf 1 / t 0.00001 Then Exit ForNext iPrint For结构; s, i; 项End SubD4Private Sub Command1_Click()Dim n&, pi#, i&n = InputBox(输入n值)pi = 2For i = 1 To n pi = pi * (2 * i) / (2 * i - 1) * (2 * i) / (2 * i + 1)Next iPrint 当n= & n & 时,pi=; piEnd SubD5Private Sub Form_Click()
21、 Dim s!, t!, i!, a%, n% a = Int(Rnd * 9 + 1) n = Int(Rnd * 6 + 5) t = 0: s = 0 Print a=; a, n=; n For i = 1 To n t = t * 10 + a s = s + t Print t; Next i Print Print s=; sEnd SubD6Private Sub Command1_Click()Dim s As Integers = 0For i = 1 To 9For j = 0 To 9 For k = 0 To 9 s = i * 100 + j * 10 + k If
22、 s = i 3 + j 3 + k 3 Then Print s End If Next kNext jNext iEnd SubPrivate Sub Command3_Click()formd6.Hidemain.ShowEnd SubD7Private Sub Command1_Click()Dim a!, x0!, x1!a = 27x0 = 2i = 0Do i = i + 1 x1 = 2 * x0 / 3 + a / (3 * x0 * x0) If Abs(x1 - x0) Max Then Max = a(i) If a(i) Min Then Min = a(i) Avg
23、 = Avg + a(i) Next i Avg = Avg / 10 Print Print Max=; Max; Min=; Min; Avg=; AvgEnd SubE2Private Sub Form_Click() Dim a a = Array(56, 78, 98, 88, 76, 78) For i = 0 To 5 Print String(a(i) 5, ); a(i) Print Next iEnd SubE3Dim a%(19)Private Sub Command1_Click()Picture1.Cls For i = 0 To 19 a(i) = Int(Rnd
24、* 101) Picture1.Print a(i); ; If (i + 1) Mod 4 = 0 Then Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim s(5 To 9) For i = 0 To 19 k = a(i) 10 Select Case k Case 0 To 5 s(5) = s(5) + 1 Case 9 To 10 90100分的人数 s(9) = s(9) + 1 Case 6 To 8 存放其他三个分数段的下标有规律,根据K获得 s(k) = s(k) + 1 End
25、SelectNext i For i = 5 To 9 If s(i) 0 Then Picture2.Print s(; i; )的人数有 ; Format(s(i), 0); 个 Next iEnd SubE4Private Sub Command1_Click()Picture1.ClsDim d%(1 To 10)For i3 = 1 To 10Randomized(i3) = Int(Rnd * 91 + 10)Next i3For i = 1 To 10For j = 1 To 10 - iIf d(j) = 5 Then MsgBox (超过5门课程,不能再选) Exit Sub
26、 Else List2.AddItem List1.Text List1.RemoveItem List1.ListIndex End IfEnd SubE8Sub Combo1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57, 13 Case Else KeyAscii = 0 End Select If KeyAscii = 13 Then Combo1.AddItem Combo1.Text Combo1.Text = End IfEnd SubPrivate Sub Command1_Click() Di
27、m min%, max% min = Val(Combo1.List(0) max = Val(Combo1.List(0) imin = 0 imax = 0 For i = 1 To Combo1.ListCount - 1 If Val(Combo1.List(i) max Then imax = i max = Combo1.List(i) ElseIf Val(Combo1.List(i) min Then imin = i min = Combo1.List(i) End If Next i t = Combo1.List(0) Combo1.List(0) = Combo1.Li
28、st(imin) Combo1.List(imin) = t t = Combo1.List(Combo1.ListCount - 1) Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = tEnd SubE9Private Sub Form_Click() For i = 0 To Screen.FontCount - 1 If Asc(Left(Screen.Fonts(i), 1) = 5 ThenMsgBox (输入人数超过数组声明的个数)Else With a(n) .number = T
29、ext1 .name = Text2 .salary = Text3 Picture1.Print a(n).number, a(n).name, a(n).salary PrintEnd Withn = n + 1Text1 = Text2 = Text3 = End IfEnd SubPrivate Sub Command2_Click()Dim t As clerk, i%, j%For i = 0 To n - 1 For j = i To n - 1 If a(i).salary a(j + 1).salary Then t = a(i): a(i) = a(j + 1): a(j + 1) = t End If Next jNext iPicture1.ClsPicture1.Print 工号 姓名 工资For i = 0 To n - 1 Picture1.Print a(i).number, a(i).name, a(i).salary PrintNext iEnd SubF1Private Sub Form_Click() Dim a(1 To 10), amin, i% For i = 1 To 10 a(i) = -Int(Rnd *