《vb程序设计教程实验指导与习题解答上机标准答案》由会员分享,可在线阅读,更多相关《vb程序设计教程实验指导与习题解答上机标准答案(74页珍藏版)》请在金锄头文库上搜索。
1、自测1程序代码Private Sub Command1_Click()Label1.FontSize = Label1.FontSize + 3End SubPrivate Sub Command2_Click()Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click()Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click()Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = FalseEnd
2、 Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Private Sub Command1_Click()Label1 = visual basicText1 = 程序设计题End SubPrivate Sub Command2_Click()Text1 = visual basicLabel1 = 程序设计题End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5)End SubPriva
3、te Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4程序代码Private Sub Command1_Click()Form1.Caption = VB学习Print 简单的VB程序设计End SubPrivate Sub Command2_Click()ClsEnd SubPrivate Sub Command3_Click()EndEnd SubPriva
4、te Sub Command3_Click()EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:自测题5程序代码Private Sub Command1_Click()Text1.Text = Text2.Text = End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Pri
5、vate Sub Command1_Click()Dim a$a = Text1.TextLabel1.Caption = Left(a, 2)End SubPrivate Sub Command2_Click()a = Text1.TextLabel2.Caption = Right(a, 2)End SubPrivate Sub Command3_Click()Text1.Text = Label1.Caption & Label2.CaptionEnd Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习2Private Sub Form_Click()Dim a%
6、, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l%a = 7349e = a Mod 10 个位d = (a 10) Mod 10 十位c = (a 100) Mod 10 百位b = a 1000 千位i = (e + 7) Mod 10 个位h = (d + 7) Mod 10 十位g = (c + 7) Mod 10 百位f = (b + 7) Mod 10 千位j = ii = f 交换后的个位f = j 交换后的千位k = hh = g 交换后的十位g = k 交换后的百位l = f * 1000 + g * 100 + h * 10 + iTe
7、xt1.Visible = FalsePrint 加密前的4位整数是7439; (Chr(10); 加密后的结果是; lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox(输入第一个数, 输入一个数, 8)b = Val(InputBox(输入第一个数, 输入一个数, 7)c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + 0.5) / 100MsgBox x+y= & c & Chr(10) & x-y=
8、 & d & Chr(10) & x*y= & e & Chr(10) & x/y= & f, , 输出的结果End Sub自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox(输入第一个数的值)b = Val(InputBox(输入第二个数的值)c = Val(InputBox(输入第三个数的值)d = Val(InputBox(输入第四个数的值)e = a + b + c + df = e / 4Print 和=; ePrint 平均值=; fEnd Sub自测练习3Private Sub Form_
9、Click()Dim h%, f%, x%, y%h = Val(InputBox(输入总头数)f = Val(InputBox(输入总脚数)x = (4 * h - f) / 2y = (f - 2 * h) / 2Print 笼中鸡的头数为; x; 只Print 笼中兔的头数为; y; 只End Sub自测练习1:Private Sub Form_Click()Dim a%, b%, c%a = Val(InputBox(请输入第一条边, 边长)b = Val(InputBox(请输入第二条边, 边长)c = Val(InputBox(请输入第三条边, 边长)If a + b c And
10、a + c b And b + c a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint 直角ElseIf a = b And b = c ThenPrint 等边三角形ElseIf a = b Or a = c Or b = c ThenPrint 等腰三角形ElsePrint 一般三角形End IfElsePrint 不是三角形End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下:等腰三角形:一般
11、三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox(请输入)If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Thenb = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Command1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a 0Case a = 20 And a = 50 And a 100MsgBox 行李费为0.4元/kg,
12、 , 行李费Case Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox 行李费为 & b & 元, , 行李费End SelectEnd Sub初始窗口:输入10:输入25:输入55:输入120:自测练习1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integera(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 1
13、1 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2)Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load()Form1.Width = 10000Form1.Height = 5000End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As IntegerFor i = 1 To 4For j = 1 To 4a(i,