VB程序的设计教程课后答案

合集下载

vb程序设计基础课后答案

vb程序设计基础课后答案

vb程序设计基础课后答案【篇一:《vb程序设计基础与vba应用》1-8章参考答案】s=txt>p28 习题一二,单选题1,b 2,b 3,d 4,a 5,d 6,b 7,b 8,c 9,d三, 程序设计题5, private sub command1_click()form1.fontname = 宋体form1.print 中文字体宋体end subprivate sub command2_click()form1.fontname = 楷体_gb2312form1.print 中文字体楷体end subprivate sub command3_click()form1.fontname = 仿宋_gb2312form1.print 中文字体仿宋end subp57 习题二一,判断题对:1, 3, 7,10,14错:2,4,5,6,8,9,11,12,13二,单选题1, a 2, c 3, c4, b6, a 7, b 8, c9, b11, c12, d13, b 14, a16, b17, b18, c19, b21, b 22, d 23, a24, c26, a 27, d28, b三,简答题1. (1) 2 * cos(alfa) * sin(alfa/ ( 2 * a )(2) sqr( s*(s–a)*(s–b )*(s - c))(3) ( a*a + b*c*(x +y)) / (a+b)(4) ( 2* 3.14159*r +exp(-5))* log(x) 5, b 10, c 15, d 20, b 25, b(5) 1/( x + 1/(y+1) )(6) k / ( 1 + a * exp(-b*x) )(7) cos(alfa) ^ 2 + atn(alfa)(8) sqr( y^3 + 3 * (a*a+b*b) / (x*x+y*y) )2. (1) (a+b) mod c (2) sqr(abs(x))(3) int(x) + 1(4) int(rnd *101)+2003。

VB语言程序的设计课后编程及上机调试参考答案

VB语言程序的设计课后编程及上机调试参考答案

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 Command3_Click()Txt.Text = "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r ^ 2Text1.Text = "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮Form1.WindowState = 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮Form1.WindowState = 0 '还原Private Sub Command3_Click() '"最小化"按钮Form1.WindowState = 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * yEnd Subex0206Private 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 Integerx = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数 Showy = c * 100 + b * 10 + a '生成倒序数 Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = 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)ex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = "您已下达显示命令"End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint "输入字符:"; 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 Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_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 = aElsem = bEnd IfIf c > d Then '求c、d中的较大数n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数x = mElsex = nEnd IfText5.Text = xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As Stringt = 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 = 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 = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.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 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 = FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100围的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + 0.5) / 10End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To List1.ListCount - 1 '逐项判断If List1.Selected(i) Then '真时为选定Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + dy = b * 1000 + a * 100 + a * 10 + cz = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数 a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Thens = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数 a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数 max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click()Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数 n = max(c, d) '求c、d中的较大数 Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(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 Subex0704Private 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 \ 10Loopfnws = 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 + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出 For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符Elsek = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII码比数字大7Print 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 = 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 IntegerIf f = 0 Then '第1次按键时,开始计时t = Timer '用t保存第1次按键的时间 f = 1 '1表示已按键和进入录入过程 End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Thenc = c + 1End IfNext kText2.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 20d(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 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出"Open "MyFile4.txt" For Input As #1Do While Not EOF(1)Input #1, xList2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '"结束"EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox "操作完毕!"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(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = "选择文件"CommonDialog1.Filter = "文本文件|*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integerr = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp") Next kEnd SubPrivate Sub Image1_Click(Index As Integer)Picture1.Font.Size = 20Picture1.ClsSelect Case IndexCase 0Picture1.Print "箭头向上"Case 1Picture1.Print "箭头向左"Case 2Picture1.Print "箭头向右"Case 3Picture1.Print "箭头向下"End SelectEnd Sub。

《Visual Basic程序设计教程》习题参考答案

《Visual Basic程序设计教程》习题参考答案

第1章习题一、选择题1. B2. A3. B4. A二、填空题1. 事件驱动或消息驱动2. 工程资源管理器、窗体三、问答题1. 11个菜单项。

文件菜单包括新建工程、打开工程、添加工程、移除工程、保存工程、工程另存为、保存窗体文件、窗体文件另存为、打印、打印设置、生成可执行文件等命令项;编辑菜单(命令项略,以下同)、视图菜单、工程菜单、格式菜单、调试菜单、运行菜单、查询菜单、图表菜单、工具菜单、外接程序菜单、窗口菜单、帮助菜单。

2. 可以自行定义。

标准工具栏中有添加工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤销、恢复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口等按钮。

四、编程题(略)第2章习题一、选择题1. A二、练习题1. S1. 把x赋值给同类型变量t;S2. 把y赋值给x;S3. 把t赋值给y。

2. S1. 输入a、b、c;S2. 如果a<b,则交换a与b的数据;S3. 如果a<c,则交换a与c的数据;S4. 如果b<c,则交换b与c的数据;S5. 输出a、b、c。

3. S1. 输入整数N;S2. 给整数K赋值2;S3. 如果K大于N-1,则转S6;S4.如果N除以K 的余数为0,则转S7;S5. K加1再赋值给K,转S3.;S6. 如果K大于N-1,则N为素数;否则N不是素数。

4. S1. 输入整数N;S2. 将N赋值给K;S3. 给整数nx赋值0;S4. 计算nx乘以10加K除以10的余数,再赋值给nx;S5. 计算K除以10的整数商,赋值给K;S6. 如果K>0,则转S4;否则,转S7;S7. 如果N=nx,则N为回文数,否则N不是回文数。

5.6.第3章习题一、选择题1. D2. C3. A4. B5. D6. A7. B8. D9. B 10. D 11. A . 12. C 13. C 14. C二、填空题1. 标题、引用2. ②④⑤3. 64. GotFocus、Resize5. AddItem、Clear6. Label,CommandButton,OptionButton,CheckBox,Frame、TextBox,ListBox,ComboBox7. PictureBox,Frame8. OptionButton,CheckBox,HScrollBar,VScrollBar、OptionButton、CheckBox,HScrollBar,VScrollBar三、问答题1. 答:对象的只读属性的属性值(如名称属性)只能在设计界面时在属性窗口进行设置;非运行属性的属性值则既可在设计界面时在属性窗口进行设置,也可通过程序代码进行设置与修改。

vb程序设计教程参考答案

vb程序设计教程参考答案

1、B2、A3、B4、答:属性:红色、充满氢气;事件:松手、针刺;方法:飞走、爆破。

5、答:事件是指对象能够识别并作出反映的外部刺激。

事件驱动又称消息驱动,事件驱动程序设计是指每个事件对应有相应的程序代码,仅在该事件发生时,该段代码才会被执行。

事件发生的顺序决定了代码执行的顺序,因此每次执行应用程序时,程序代码并不是按照程序编写的顺序来执行的。

6、答:VB是一个包括界面设计、程序编码、调试、编译并创建可执行程序的集成开发环境。

VB的集成开发环境的主界面中包含:标题栏、菜单栏、工具栏、控件箱、工程资源管理器、属性窗口、“窗体布局”窗口、窗体设计器、代码编辑器等元素组成。

7、答: VB菜单条通常情况下有:文件、编辑、视图、工程、格式、调试、运行、查询、图表、工具、外接程序、窗口、帮助等13项菜单项组成。

8、答:工具栏可自行定义。

标准工具栏中通常情况下有:添加标准exe工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤消、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视化元件管理器等按钮组成。

9、答:创建VB应用程序的一般步骤为:创建界面;设置窗体和控件属性;编写代码;保存工程;运行并调试程序;检查并排除错误;创建可执行文件。

10、Private Sub Command1_Click()Label1.Caption = "I love vb,I hate vb"End Sub1、2、3、S1 输入待判断自然数: N(N>=2);S2 i=2;S3 判断i是否小于N-1,若不是转S5S4 判断N除以i的余数是否为0,如果不是则i=i+1转S3;S5 判断i是否等于N,若是输出“是素数”,否则输出“不是素数”。

4、S1 输入待判断自然数: N;S2 将N转换成字符S,计算S的长度K;S3 i=1;S4 判断i是否小于K-1,若不是转S6;S5 判断S中的第i位和第K-i+1位是否相等,如果是则i=i+1转S4,如果不是则转S6;S6 判断i是否是中间位数,若是输出“是回文数”,否则输出“不是回文数”。

vb程序设计教程习题答案

vb程序设计教程习题答案

vb程序设计教程习题答案VB程序设计教程习题答案VB程序设计是一门广泛应用于软件开发领域的编程语言,它具有易学易用的特点,被广大程序员所喜爱。

在学习VB程序设计的过程中,习题是一个非常重要的环节,通过解答习题可以帮助我们巩固所学的知识,提高编程能力。

下面我将给出一些VB程序设计教程习题的答案,希望对初学者有所帮助。

1. 编写一个VB程序,实现计算两个数的和并输出结果的功能。

答案:```Public Class Form1Private Sub Button1_Click(sender As Object, e As EventArgs) HandlesButton1.ClickDim num1 As IntegerDim num2 As IntegerDim sum As Integernum1 = Integer.Parse(TextBox1.Text)num2 = Integer.Parse(TextBox2.Text)sum = num1 + num2MessageBox.Show("两个数的和为:" & sum)End SubEnd Class```2. 编写一个VB程序,实现判断一个数是奇数还是偶数的功能。

答案:```Public Class Form1Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim num As Integernum = Integer.Parse(TextBox1.Text)If num Mod 2 = 0 ThenMessageBox.Show("这个数是偶数")ElseMessageBox.Show("这个数是奇数")End IfEnd SubEnd Class```3. 编写一个VB程序,实现计算一个数的阶乘的功能。

VB程序设计教程 习题解答

VB程序设计教程 习题解答

《VB程序设计教程》(第4版)习题解答单元一巩固与提高答案一、选择题1. Visual Basic 6.0分为3种版本,不属于这3种版本的是A)学习版B)专业版C)企业版D)业余版【答】D。

2. 下列方法中不能退出Visual Basic的是A)按Alt+Q组合键B)按下Alt+F组合键,然后按Esc键C)按F10键,然后按F键,再按X键D)打开“文件”菜单→“退出”命令【答】B。

3. Visual Basic集成的主窗口中不包括A)属性窗口B)标题栏C)菜单栏D)工具栏【答】A。

4. 下列操作可以打开立即窗口的是A)Ctrl+D B)Ctrl+F C)Ctrl+G D)Ctrl+E【答】C。

二、填空题1. 与传统的程序设计语言相比,Visual Basic最突出的特点是____。

【答】事件驱动编程机制。

2. 如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。

【答】功能键F10或Alt键。

3. 建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。

【答】“工程”菜单。

三、思考题1. 简述Visual Basic的特点。

【答】与一般的程序设计语言相比,VB具有以下特点:(1) 可视化的设计平台;(2) 面向对象的设计方法;(3) 事件驱动的编程机制;(4) 结构化的设计语言;(5) 充分利用Windows资源;(6) 开放的数据库功能与网络支持。

2. 简述Visual Basic集成开发环境的组成。

【答】VB 6.0集成开发环境除了具有标准Windows环境的标题栏、菜单栏、工具栏外,还有工具箱、属性窗口、工程管理器窗口、窗体设计器、立即窗口、窗体布局窗口等有用的开发工具。

(1) 标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化∕还原、关闭按钮。

菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了VB编程的常用命令。

VB程序设计课后习题答案

VB程序设计课后习题答案

VB课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。

2、当正常安装VB6.0后,误把Windows子目录删除。

当重新安装Windows后,是否需要再次安装VB6.0?答:要重新安装的。

因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。

3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。

4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。

5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。

6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。

7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。

VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。

9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。

VB教程课后习题的答案及解析

VB教程课后习题的答案及解析

=第二章标准控件和属性1.下列可以激活属性窗口的操作是( D )A)用鼠标双击窗体的任何部位 B)执行‘工程’菜单中的‘属性窗口’命令 C)按Ctrl+F4键 D)按F4键2.确定一个控件在窗体上的位置的属性是( D )A)Width或Height B)Width和Height C)Top或Left D)Top和Left3.确定一个窗体或控件的大小的属性是( B )A)Width或Height B)Width和Height C)Top或Left D)Top和Left4.在Visual Basic中,所有标准控件都具有的属性是( B )。

【2013年9月考试真题】A) Caption B) Name C) Text D) Value参考答案:B【解析】VB标准控件中不同控件具有不同属性,有的相同有的不同,但都具有Name属性。

故选B。

5.为了让计时器控件每隔10秒产生了一个Timer事件,应把Interval属性设置为( B )A) 1000 B) 10000 C) 10 D) 1006.下面关于单选按钮和复选框的叙述中正确的是( D )A) 单选按钮被选中则它的Value属性为True;复选框被选中则它的Value属性为2B) 单选按钮被选中则它的Value属性为True;复选框被选中则它的Value属性为TrueC) 单选按钮被选中则它的Value属性为1;复选框被选中则它的Value属性为1D) 单选按钮被选中则它的Value属性为True;复选框被选中则它的Value属性为17.将文本框的ScrollBar设置为2,文本框中却没有垂直滚动条,其原因为( B )A) 文本框的Locked属性值为True B) 文本框的MultiLine属性值为FalseC) 文本框的MultiLine属性值为True D) 文本框中没有内容第三章简单程序设计语句1.在面向对象的程序设计中,可被对象识别的动作称为( B )。

《VB语言程序设计》习题答案

《VB语言程序设计》习题答案

《VB语言程序设计》习题参考答案第1章习题一、单选题1.D 2.B 3.C 4.A 5.C 6. A 7.A 8.B 9.C 10.(1)A (2)B二、多选题1.ACDE 2.BCDE 3.CD 4. CE三、填空题1.事件驱动 2.解释,编译 3.设计,运行,中断4. 属性,方法,事件5. Command2_Click6. 中央,代码7.MyForm.frm 8. (1)Cmd1_Click() (2)Print "VB语言程序设计"编程及上机调试1. 按要求设置窗体属性2.在窗体上建立一个标签Label1。

程序代码如下:Private Sub Form_Click()Label1.Caption = "你单击了窗体"End SubPrivate Sub Form_DblClick()Label1.Caption = "你双击了窗体"End Sub3.在窗体上建立两个文本框Text1(输入数)、Text2(输出数)和一个命令按钮Command1。

两个文本框的Text属性均为空。

Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Sub第2章习题一、单选题1.①D,②D 2.①A,②C 3.A 4.B 5.B 6.B 7.C 8.D 9.B 10.B 11.A 12.A 13.B 14.A 15.B 16.A 17.B二、多选题1.BD 2.CD 3.AC 4. AD三、填空题1.(1) Sin(50*3.14159/180) (2) (2+x*y)/(2–y*y)(3) a*a–3*a*b/(3+a) (4) x^(3/8)+Sqr(y*y+4*a*a/(x+y^3))2.Int(50+6*Rnd)3.(1)138 (2)3 (3)214 (4) "inchina" (5)70 (6) "45"(7)04. "系统管理数据库"编程及上机调试1~3题:按要求完成操作练习。

VB程序设计教材习题及参考解答

VB程序设计教材习题及参考解答

第 1 章概述一、叙述题1.简述VB具有哪些特点。

(1)面向对象的可视化设计工具(2)事件驱动的编程机制(3)易学易用的应用程序集成开发环境(4)结构化的程序设计语言(5)充分利用Windows资源(6)开放的数据库功能与网络支持2.简述事件驱动的程序设计原理。

解答:VB程序的运行没有固定的顺序,它通过事件来激活某个对象,随着该对象的活动,会引发新的事件,这个事件又可能使另一个对象激活,对象之间就是以这种方式联系在一起的。

每个事件都可以通过一段程序(称为“事件过程”)来响应,在事件发生时,系统将自动执行相应的事件过程,用以实现指定的操作并达到运算、处理的目的。

为不同对象响应不同事件编写的事件过程构成了一个完整的应用程序,这就是VB事件驱动的程序设计原理。

3.VB的集成开发环境由哪些元素组成?解答:标题栏、菜单栏、工具栏、工具箱、窗体窗口、代码窗口、工程资源管理器窗口、属性窗口及窗体布局窗口等。

4.VB集成开发环境的工具栏能否自行定义?标准工具栏中包含一些什么按钮?解答:VB集成开发环境的工具栏可以自定义,方法是:用鼠标右击标准工具栏的任意位置,可以打开或关闭其余工具栏。

标准工具栏中包含的按钮有:添加Standard EXE工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤销、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视组件管理器及窗体位置与大小等。

5.当创建只有一个窗体的应用程序后,该工程涉及多少个要保存的文件?若要保存该工程中的所有文件,应先保存什么文件?后保存什么文件?解答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

6.简述用VB开发应用程序的一般步骤。

(1)创建应用程序界面(2)设置界面上各个对象的属性(3)编写对象响应事件的程序代码(4)保存工程(5)运行和调试应用程序(6)创建可执行程序二、单选题1.D VB是一种面向对象的可视化程序设计语言。

visual_Basic程序的设计教程_课后习题答案及练习

visual_Basic程序的设计教程_课后习题答案及练习

visual_Basic程序的设计教程_课后习题答案及练习《VB程序设计》综合复习资料第一章 Visual Basic程序设计概述一、填空题1、Visual Basic是一种面向__________的可视化程序设计语言,采取了__________的编程机制。

2、在VB中工程文件的扩展名是____________,窗体文件的扩展名是____________,标准模块文件的扩展名是____________。

3、执行“工程”菜单下的__________命令,可选择并添加ActiveX控件。

4、Visual Basic 6.0用于开发__________环境下的应用程序。

二、选择题1、下面不是VB工作模式的是()A.设计模式B.运行模式C.汇编模式D.中断模式2、可视化编程的最大优点是()A.具有标准工具箱B.一个工程文件由若干个窗体文件组成C.不需要编写大量代码来描述图形对象D.所见即所得3、下列不能打开属性窗口的操作是()A.执行“视图”菜单中的“属性窗口”命令B.按F4键 C.按Ctrl+TD.单击工具栏上的“属性窗口”按钮4、下列可以打开立即窗口的操作是()A.Ctrl+D B.Ctrl+E C.Ctrl+F D.Ctrl+G5、Visual Basic的编程机制是()A.可视化 B.面向对象 C.面向图形 D.事件驱动三、简答题1、代码窗口主要包括哪几部分?2、在工程资源管理器窗口中,主要列出了哪三类文件?3、窗体布局窗口的主要用途是什么?4、VB的基本特点是什么?5、怎样理解可视化设计?6、怎要理解事件驱动编程?第二章简单的VB程序设计一、填空题1、设置是否可以用Tab键来选取命令按钮,应该用______________属性。

2、一个控件在窗体的位置由_______和________属性决定,其大小由__________和_________属性决定。

3、利用对象的属性setfocus可获得焦点,对于一个对象,只有其visible属性和____________属性为true,才能接受焦点。

(完整版)VB程序设计教程(第3版)课后实验完整答案

(完整版)VB程序设计教程(第3版)课后实验完整答案

A.1Private Sub Command1_Click()Label3 = Text1End SubA.2Private Sub Form_Load()Timer1.Interval = 0End SubPrivate Sub Command1_Click() '自动Timer1.Interval = 200End SubPrivate Sub Command2_Click() '手动Timer1.Interval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer()Call MyMoveEnd SubSub MyMove()Label1.Move Label1.Left - 50If Label1.Left < 0 Then Label1.Left = Form1.Width End SubA.3Private Sub Form_Click()Text1 = Val(Text1) + 1End SubPrivate Sub Form_Load()Text1 = 0End SubA.4Private Sub Form_Click()Caption = "单击窗体,改变图片"Picture = LoadPicture(App.Path + "\n_015.bmp")Print "欢迎使用VB"End SubPrivate Sub Form_DblClick()ClsCaption = "双击窗体,卸去图片"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 + 200 ' 260 是图的高度,象素单位,200 是窗体的标题栏高度End SubA.5Sub Command1_Click()Text1.FontName = "隶书"Text1.FontSize = 25End SubSub Command2_Click()Text2.Text = Text1.SelTextText2.FontName = Text1.FontNameText2.FontSize = Text1.FontSizeEnd SubB.1Private Sub Command1_Click()Text2 = Format(5 / 9 * (Val(Text1) - 32), "0.00")End 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 + 32Text1 = Format(ff, "0.00") ' 保留两位小数End SubB.2Label2 = 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) ThenMsgBox "输入有非数字字符,请重新输入", , "警告"Text1.Text = ""Text1.SetFocusEnd 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 ThenIf Not IsNumeric(Text1.Text) ThenText1.Text = ""End IfEnd IfEnd SubB.3Private Sub Command1_Click()n = Int(Log(2) / Log(1.008) + 1)Label1 = n & "年后人数超过26 亿"End SubB.4Private Sub Command1_Click()Dim x, dx, cdx = Text1.Textdx = UCase(x)cd = Len(x)Print "大写字母为:"; dxPrint "字符串长度为:"; cdEnd SubB.5Text1 = 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 SubB.6Private Sub Form_Click()Label1 = Left(Text1, 11)Label2 = Mid(Text1, 12, 6)Label3 = Right(Text1, 5)End SubB.7Private Sub Command1_Click()PrintFor i = 1 To 5Print 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()PrintFor i = 1 To 5Print Tab(15 - i * 2); String(2 * i - 1, "★"); String(10 - (2 * i - 1), "☆"); String(2 * i - 1, "★") Next iEnd SubPrivate Sub Command2_Click()ClsEnd SubB.8Private 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); "平方根为:"; pfg; Space(5); "立方为:"; lf; Space(5); "立方根为:"; lfgEnd SubC.1Private 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 SubC.2Private Sub Form_Click()Dim x!, y!x = Val(InputBox("输入上网时间"))If x < 10 Theny = 30ElseIf x < 50 Theny = 30 + 2.5 * (x - 10)Elsey = 30 + 2.5 * 40 + 2 * (x - 50)End IfIf y > 150 Theny = 150End IfPrint yEnd SubC.3Private 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 Ifx < y Then t = x: x = y: y = tIf x < z Then t = x: x = z: z = tIf y < z Then t = y: y = z: z = tPrint " 排序后" & x & " " & y & " " & z End 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 Ifx < y Then t = x: x = y: y = tIf y < z Thent = y: y = z: z = tIf x < y Thent = x: x = y: y = tEnd IfEnd IfPrint " 排序后" & x & " " & y & " " & z End SubC.4Dim a(3) As IntegerPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 2a(i) = Int(Rnd * 100 + 200)Picture1.Print a(i)Next iEnd SubPrivate Sub Command2_Click()Picture2.ClsDim z As IntegerFor i = 0 To 1If a(i) > a(i + 1) Thenz = a(i + 1)a(i + 1) = a(i)a(i) = zEnd IfNext iPicture2.Print a(0)Picture2.Print a(1)Picture2.Print a(2)End SubC.5Private Sub Text2_LostFocus()Dim m%, n%, y%m = Val(Text1)n = Val(Text2)If n Mod 2 <> 0 ThenMsgBox ("脚数必定为偶数")Text2 = ""Text2.SetFocusElsey = n / 2 - mIf y < 0 ThenMsgBox ("脚数必须≥2 倍的头数,请重新输入")Text2 = ""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Command1_Click()Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 ThenText4 = Format(-b / t, "0.00")Text5 = Format(-b / t, "0.00")ElseIf de > 0 ThenText4 = Format((-b + Sqr(de)) / t, "0.00")Text5 = Format((-b - Sqr(de)) / t, "0.00")ElseText4 = 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") & "i" End IfEnd SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""Text4 = ""Text5 = ""End SubC.7Private Sub Text3_LostFocus()Select Case Trim(Text3)Case "+"Text4 = Val(Text1) + Val(Text2)Case "-"Text4 = Val(Text1) - Val(Text2)Case "*"Text4 = Val(Text1) * Val(Text2)Case "/"If Val(Text2) = 0 ThenMsgBox "分母为零,重新输入"Text2 = ""Text2.SetFocusElseText4 = Val(Text1) / Val(Text2)End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus()Select Case Trim(Text1)Case 1Text2 = "Monday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wednesday"Case 4Text2 = "Thursday"Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Sunday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus()If Text1 > 7 Or Text1 < 1 ThenMsgBox "数字为1~7,重新输入"Text1 = ""Text1.SetFocusElseText2 = Choose(Text1, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")End IfEnd SubD.1Private Sub Form_Click()For i = 1 To 9Print Tab(10 - i); String(2 * i - 1, Trim(Str(i)))Next iEnd SubD.2Private Sub Form_Click()For i = 1 To 10 Step 1Print Tab(i); String((20 - 2 * i), Chr(64 + i))Next iEnd SubD.3Private Sub Command1_Click()Dim s!, t!, i&s = 1t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrint "For 结构"; s, i; "项"End SubD.4Private Sub Command1_Click()Dim n&, pi#, i&n = InputBox("输入n 值")pi = 2For i = 1 To npi = pi * (2 * i) / (2 * i - 1) * (2 * i) / (2 * i + 1) Next iPrint "当n=" & n & "时,pi="; piEnd SubD.5Private Sub Form_Click()Dim s!, t!, i!, a%, n%a = Int(Rnd * 9 + 1)n = Int(Rnd * 6 + 5)t = 0: s = 0Print "a="; a, "n="; nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrint "s="; sEnd SubD.6Private Sub Command1_Click()Dim s As Integers = 0For i = 1 To 9For j = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i ^ 3 + j ^ 3 + k ^ 3 ThenPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Command3_Click()formd6.Hidemain.ShowEnd SubD.7Private Sub Command1_Click()Dim a!, x0!, x1!a = 27x0 = 2i = 0Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0)If Abs(x1 - x0) < 0.00001 Then Exit Dox0 = x1LoopPrint x1, iEnd SubD.8Private Sub Command1_Click()s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iPrint sEnd SubD.9Private Sub Command4_Click()Picture1.ClsPicture1.Print "x 课安排在"; "y 课安排在"; "z 课安排在"Picture1.Print ""For z = 5 To 6For x = 1 To z - 2For Y = x + 1 To z - 1X1 = Choose(Weekday(x), "周一", "周二", "周三", "周四", "周五", "周六", "周日")Y1 = Choose(Weekday(Y), "周一", "周二", "周三", "周四", "周五", "周六", "周日") z1 = Choose(Weekday(z), "周一", "周二", "周三", "周四", "周五", "周六", "周日") Picture1.Print " "; X1; " "; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click()Dim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(Rnd * 71 + 30)Print a(i); " ";Next iMax = a(1)Min = a(1)Avg = a(1)For i = 2 To 10If a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)Avg = Avg + a(i)Next iAvg = Avg / 10PrintPrint "Max="; Max; " Min="; Min; " Avg="; AvgEnd SubE.2Private Sub Form_Click()Dim aa = Array(56, 78, 98, 88, 76, 78)For i = 0 To 5Print String(a(i) \ 5, "◆"); a(i)PrintNext iEnd SubE.3Dim a%(19)Private Sub Command1_Click()Picture1.ClsFor i = 0 To 19a(i) = Int(Rnd * 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 19k = a(i) \ 10Select Case kCase 0 To 5s(5) = s(5) + 1Case 9 To 10 '90~100 分的人数s(9) = s(9) + 1Case 6 To 8 ' 存放其他三个分数段的下标有规律,根据K 获得s(k) = s(k) + 1End SelectNext iFor i = 5 To 9If s(i) <> 0 Then Picture2.Print "s("; i; ")的人数有"; Format(s(i), "0"); "个" Next iEnd SubE.4Private 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) < d(j + 1) Thent = d(j): d(j) = d(j + 1): d(j + 1) = tEnd IfNext jNext iFor i = 1 To 10: Picture1.Print d(i);If i Mod 5 = 0 Then Picture1.PrintNext iEnd SubE.5Dim a%(3, 3), b%(3, 3)Private Sub Form_Load()For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 36 + 35)b(i, j) = Int(Rnd * 41 + 100)Next jNext iEnd SubPrivate Sub Command1_Click()Picture1.ClsFor i = 0 To 3For j = 0 To iPicture1.Print a(i, j); " ";Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Print Tab(j * 6); b(i, j);Next jPicture2.PrintNext iEnd SubPrivate Sub Command3_Click()Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, i)Next isb = 0For i = 0 To 3sb = sb + b(i, 3 - i)Next iPicture3.Print "A 数组主对角线元素和为:"; sa Picture3.Print "B 数组副对角线元素和为:"; sb End SubE.6Private Sub Form_Click()n = InputBox("输入n 值")ReDim a6%(n + 1, n + 1)a6(0, 0) = 1: a6(1, 1) = 1: a6(1, 0) = 1For i = 2 To n + 1For j = 2 To ia6(i, j) = a6(i - 1, j - 1) + a6(i - 1, j) Picture1.Print a6(i, j); "";Next jPicture1.PrintNextEnd SubE.7Private Sub Form_Load()List1.ClearList1.AddItem "大学计算机基础"List1.AddItem "C/C++程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计"List1.AddItem "多媒体技术与应用"List1.AddItem "数据库技术与应用"List1.AddItem "网络技术与应用"List1.AddItem "硬件技术基础"List1.AddItem "软件技术技术基础"End SubPrivate Sub List1_Click()If List2.ListCount >= 5 ThenMsgBox ("超过5 门课程,不能再选")Exit SubElseList2.AddItem List1.TextList1.RemoveItem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As Integer) Select Case KeyAsciiCase 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 ThenCombo1.AddItem Combo1.TextCombo1.Text = ""End IfEnd SubPrivate Sub Command1_Click()Dim min%, max%min = Val(Combo1.List(0))max = Val(Combo1.List(0))imin = 0imax = 0For i = 1 To Combo1.ListCount - 1If Val(Combo1.List(i)) > max Thenimax = imax = Combo1.List(i)ElseIf Val(Combo1.List(i)) < min Thenimin = imin = Combo1.List(i)End IfNext it = Combo1.List(0)Combo1.List(0) = Combo1.List(imin)Combo1.List(imin) = tt = Combo1.List(Combo1.ListCount - 1)Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax) Combo1.List(imax) = tEnd SubE.9Private Sub Form_Click()For i = 0 To Screen.FontCount - 1If Asc(Left(Screen.Fonts(i), 1)) < 0 ThenPicture1.Print Screen.Fonts(i)Picture2.FontName = Screen.Fonts(i)Picture2.Print "商丘师范学院"End IfNext iEnd SubE.10Private Type clerknumber As String * 3name As String * 5salary As IntegerEnd TypeDim a(0 To 4) As clerk, n%Private Sub Command1_Click()If n >= 5 ThenMsgBox ("输入人数超过数组声明的个数")ElseWith a(n).number = Text1.name = Text2.salary = Text3Picture1.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 - 1For j = i To n - 1If a(i).salary < a(j + 1).salary Thent = a(i): a(i) = a(j + 1): a(j + 1) = tEnd IfNext jNext iPicture1.ClsPicture1.Print "工号姓名工资" For i = 0 To n - 1Picture1.Print a(i).number, a(i).name, a(i).salaryPrintNext iEnd SubF.1Private Sub Form_Click()Dim a(1 To 10), amin, i%For i = 1 To 10a(i) = -Int(Rnd * 101 + 300)Print a(i);Next iCall s(a(), amin)PrintPrint "min="; aminEnd SubSub s(b(), min)Dim i%min = b(LBound(b))For i = LBound(b) + 1 To UBound(b)If b(i) < min Then min = b(i)Next iEnd SubF.2Private Sub Command1_Click()Dim mm%, nn%mm = Val(Text1)nn = Val(Text2)Picture1.Print mm; Tab(6); nn; Tab(12); gcd(mm, nn) End SubFunction gcd%(ByVal m%, ByVal n%)If m < n Then t = m: m = n: n = tr = m Mod nDo While (r <> 0)m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Command1_Click()Print "调用标准函数Sin 的结果"; Sin(x)End SubPrivate Sub Command2_Click()Print "调用自定义函数MySin 的结果"; MySin(x) End SubFunction MySin(x!) As DoubleDim i%, t!, s!t = xs = ti = 1Do While Abs(t) > 0.00001t = -1 * t * x * x / ((i + 1) * (i + 2))s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Command3_Click()x = InputBox("输入要计算正弦函数的角度值x") x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenIf Not IsNumeric(Text1) ThenMsgBox "输入非数字串,重新输入"Text1.Text = ""Text1.SetFocusElseIf IsH(Text1) ThenPicture1.Print Text1; " ★"ElsePicture1.Print Text1End IfText1 = ""End IfEnd IfEnd SubFunction IsH(ss As String) As BooleanDim i%, Ls%IsH = Truess = Trim(ss)Ls = Len(ss)For i = 1 To Ls \ 2If Mid(ss, i, 1) <> Mid(ss, Ls + 1 - i, 1) ThenIsH = FalseExit FunctionEnd IfNext iEnd FunctionF.5Function prime(ByVal m As Integer) As Booleanprime = TrueDim i%For i = 2 To m - 1If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next iEnd FunctionPrivate Sub Command1_Click()n = 0For i = 6 To 100 Step 2For j = 3 To i \ 2If prime(j) ThenIf prime(i - j) ThenList1.AddItem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext jNext iPicture1.Print " 6 和100 之间共有"; n; "对素数和"End SubF.6Dim a%()Private Sub Form_Click()Print "1000 以内的完数为:"For i = 1 To 1000If IsWs(i) ThenPrint i; "=1";For j = 1 To UBound(a)Print "+"; a(j);Next jPrintEnd IfNext iEnd SubFunction IsWs(m) As BooleanDim s%s = 0For i = 1 To m \ 2If m Mod i = 0 ThenReDim Preserve a(j)a(j) = ij = j + 1s = s + iEnd IfNext iIf m = s Then IsWs = TrueEnd FunctionF.7Private Sub DeleStr(s1 As String, ByVal s2 As String)Dim i%ls2 = Len(s2)i = InStr(s1, s2)Do While i > 0s1 = Left(s1, i - 1) + Mid(s1, i + ls2) ' 在s1 中去除s2 子串i = InStr(s1, s2)LoopEnd SubPrivate Sub Command1_Click() ' 调用DeleStr 子过程Dim ss1 As Stringss1 = Text1Call DeleStr(ss1, Text2)Text3 = ss1End SubPrivate Sub Command2_Click()End SubF.8Private Sub Command1_Click()Dim maxw$maxlen Text1 & " ", maxwText2 = maxwEnd SubSub maxlen(s$, maxw$)Dimword$ maxw = ""Do While s <> ""i = InStr(s, " ")word = Left(s, i - 1)If Len(word) > Len(maxw) Then maxw = words = Mid(s, i + 1)LoopEnd SubG.1Private Sub Command1_Click()List1.ClearList1.AddItem Combo1If Option1 Then List1.AddItem "Pentium II"If Option2 Then List1.AddItem "Pentium I"If Option3 Then List1.AddItem "Celeron"List1.AddItem Text1If Check1 Then List1.AddItem "声卡"If Check2 Then List1.AddItem "Modem"If Check3 Then List1.AddItem "网络适配器"End SubPrivate Sub Text1_LostFocus()st = UCase(Trim(Text1))le = Len(st)If Not IsNumeric(Left(st, le - 2)) Or Right(st, 2) <> "MB" Then MsgBox "有不合法字符!"Text1 = ""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click()Picture1.Font.Bold = Not Picture1.Font.BoldEnd SubPrivate Sub Check2_Click()Picture1.Font.Italic = Not Picture1.Font.BoldEnd SubPrivate Sub Command1_Click()Picture1.ClsIf Option1 ThenPicture1.Print Sin(Val(Text1))ElseIf Option2 ThenPicture1.Print Exp(Val(Text1))ElseIf Option3 ThenPicture1.Print Sqr(Val(Text1))End IfEnd SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form2End SubG.3Private Sub HScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub HScroll2_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubPrivate Sub VScroll1_Change()Text1 = VScroll1.ValueText2 = HScroll1.ValueText3 = HScroll2.ValueText4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), "0.00") Text5 = Format(Val(Text4) + Val(Text1), "0.00")End SubG.4Dim t As SinglePrivate Sub Command1_Click()t = InputBox("输入倒计时分钟数")t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = tProgressBar1.Value = tEnd SubPrivate Sub Command2_Click()Timer1.Interval = 1000ProgressBar1.Visible = TrueEnd SubPrivate Sub Timer1_Timer()Dim m%, s%t = t - 1ProgressBar1.Value = tm = t \ 60s = t Mod 60Label1 = m & "分" & s & "秒"If t = 0 ThenMsgBox " 时间到!"Timer1.Interval = 0ProgressBar1.Visible = FalseEnd IfEnd SubG.5Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubG.6rivate Sub bold_Click()Text1.FontBold = Not Text1.FontBoldbold.Checked = Not bold.CheckedEnd SubPrivate Sub del_Click()Text1 = ""End SubPrivate Sub end_Click()EndEnd SubPrivate Sub font12_Click()Text1.FontSize = 12End SubPrivate Sub font16_Click()Text1.FontSize = 16End SubPrivate Sub Form_Load()bold.Checked = Falseitalic.Checked = FalseEnd SubPrivate Sub italic_Click()Text1.FontItalic = Not Text1.FontItalicitalic.Checked = Not italic.CheckedEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu menu2End SubG.7Private Sub Command1_Click()CommonDialog1.ShowColorLabel1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()CommonDialog1.ShowOpeni = Shell("C:\WINDOWS\NOTEPAD.exe " + CommonDialog1.FileName, vbNormalFocus) End SubPrivate Sub return_Click(Index As Integer)Form6.ShowUnload Form5End SubG.8G.9Private Sub 结束_Click()EndEnd SubPrivate Sub 删除最大值_Click()max = List1.List(0)For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 删除最小值_Click()min = List1.List(0)For i = 1 To List1.ListCount - 1If min > List1.List(i) Then min = List1.List(i): j = i Next iList1.RemoveItem jEnd SubPrivate Sub 随机产生_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub 添加数据_Click()List1.AddItem Int(Rnd * 30 + 70)End SubPrivate Sub 统计_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next iForm2.Text1 = List1.List(n)Form2.Text2 = List1.List(m)Form2.Text3 = Format(ave / List1.ListCount, "0.00") Form2.ShowEnd SubG.10Private Sub experimentG2_Click()Form2.ShowEnd SubPrivate Sub experimentG3_Click()Form3.ShowEnd SubPrivate Sub experimentG4_Click()Form4.ShowEnd SubPrivate Sub experimentG5_Click()Form5.ShowEnd SubPrivate Sub font_12_Click()Text1.FontSize = 12End SubPrivate Sub font_16_Click()Text1.FontSize = 16End SubPrivate Sub rnd10_Click()RandomizeFor i = 0 To 9List1.List(i) = Int(Rnd * 30 + 70)Next iEnd SubPrivate Sub stat_Click()Dim max%, min%, ave!, m%, n%max = List1.List(0)min = List1.List(0)ave = List1.List(0)m = 0n = 0For i = 1 To List1.ListCount - 1If max < List1.List(i) Then max = List1.List(i): m = i If min > List1.List(i) Then min = List1.List(i): n = i ave = ave + List1.List(i)Next istat2.Text1 = List1.List(n)stat2.Text2 = List1.List(m)stat2.Text3 = Format(ave / List1.ListCount, "0.00")stat2.ShowEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu caidan2, vbPopupMenuCenterAlignEnd SubPrivate Sub xie_Click()Text1.Font.Italic = Not Text1.Font.BoldEnd SubH.1Private Sub Command1_Click()Open "c:\score" For Output As #1Print #1, "051023", "王海涛", 66Print #1, "052498", "周文英", 88Print #1, "050992", "陈建东", 77Open "c:\score1" For Output As #2Write #2, "051023", "王海涛", 66Write #2, "052498", "周文英", 88Write #2, "050992", "陈建东", 77Closei1 = Shell("NOTEPAD.exe" + " c:\score", vbNormalNoFocus)i2 = Shell("NOTEPAD.exe" + " c:\score1", vbNormalNoFocus)End SubPrivate Sub Command2_Click()Dim no As String, name As String, s As IntegerOpen "c:\score" For Input As #1Do While Not EOF(1)Line Input #1, linedataList1.AddItem linedataLoopOpen "c:\score1" For Input As #2Do While Not EOF(2)Input #2, no, name, sList2.AddItem no & name & sLoopCloseEnd SubH.2Private Sub Command1_Click()Dim fib%(0 To 9), i%Open "c:\fb.dat" For Output As #1For i = 0 To 9If i = 0 Or i = 1 Thenfib(i) = iElsefib(i) = fib(i - 1) + fib(i - 2)End IfPrint #1, """Fib(" & i & ")""," & fib(i)Next iClose #1i = Shell("NOTEPAD.exe" + " c:\fb.dat", vbNormalNoFocus) End SubPrivate Sub Command2_Click()Dim st$, n%, sum%Open "c:\fb.dat" For Input As #1Do While Not EOF(1)Input #1, st, nsum = sum + nList1.AddItem st & "=" & nLoopClose #1List1.AddItem " 合计:" & sumList1.AddItem "平均:" & sum / 10End SubH.3H.4Private Type studtypeno As String * 4name As String * 6mark As SingleEnd TypeDim student As studtype, stud(1 To 5) As studtype, t As studtypePrivate Sub Command1_Click()Open "d:\score.dat" For Random As #1 Len = Len(student) With student.no = "0001".name = "星期一"。

VB程序设计教程 习题解答

VB程序设计教程 习题解答

VB程序设计教程习题解答vb程序设计教程习题解答《VB编程课程》(第三版)问题解决习题1答案一、多项选择题1.1visualbasic6.0分为3种版本,不属于这3种版本的是a)学习版b)专业版c)企业版d)业余版【答】d。

1.2在以下方法中,无法退出Visual Basic的方法是a)按Alt+Qb)按下alt+f组合键,然后按esc键c)按f10键,然后按f键,再按x键d)打开“文件”菜单→“退出”命令【答】b。

1.3 visual basic集成的主窗口不包括a)属性窗口b)标题栏C)菜单栏d)工具栏[answer]a。

1.4下列操作可以打开立即窗口的是a)ctrl+db)ctrl+fc)ctrl+gd)ctrl+e【答】c。

二、填空题1.5与传统编程语言相比,Visual Basic最突出的特点是。

[答:]事件驱动编程机制。

1.6如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。

[答:]功能键F10或alt。

1.7建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。

【答】“工程”菜单。

三、思考问题1.8简述visualbasic的特点。

[答:]与通用编程语言相比,VB具有以下特点:(1)可视化设计平台;(2)面向对象设计方法;(3)事件驱动编程机制;(4)结构化设计语言;(5)充分利用windows资源;(6)开放数据库功能和网络支持。

1.9简述visualbasic集成开发环境的组成。

[答:]VB6 0集成开发环境不仅有标准Windows环境的标题栏、菜单栏和工具栏,还有工具箱、属性窗口、项目管理器窗口、表单设计器、即时窗口和表单布局窗口等有用的开发工具。

(1)标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化m还原、关闭按钮。

菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了vb编程的常用命令。

VB程序设计教程课后答案

VB程序设计教程课后答案

VB程序设计教程课后答案课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。

2、当正常安装VB6.0后,误把Windows子目录删除。

当重新安装Windows后,是否需要再次安装VB6.0?答:要重新安装的。

因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。

3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。

4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。

5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。

6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。

7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。

VB6.0的帮助系统在两张光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。

9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的内容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定内容有关的帮助信息。

VB程序设计教程 习题解答

VB程序设计教程 习题解答

《VB程序设计教程》(第4版)习题解答单元一巩固与提高答案一、选择题1. Visual Basic 6.0分为3种版本,不属于这3种版本的是A)学习版B)专业版C)企业版D)业余版【答】D。

2. 下列方法中不能退出Visual Basic的是A)按Alt+Q组合键B)按下Alt+F组合键,然后按Esc键C)按F10键,然后按F键,再按X键D)打开“文件”菜单→“退出”命令【答】B。

3. Visual Basic集成的主窗口中不包括A)属性窗口B)标题栏C)菜单栏D)工具栏【答】A。

4. 下列操作可以打开立即窗口的是A)Ctrl+D B)Ctrl+F C)Ctrl+G D)Ctrl+E【答】C。

二、填空题1. 与传统的程序设计语言相比,Visual Basic最突出的特点是____。

【答】事件驱动编程机制。

2. 如果不使用鼠标,用键盘打开菜单和执行菜单命令,第一步应按____键。

【答】功能键F10或Alt键。

3. 建立一个新的标准模块,应该选择____菜单下的“添加模块”命令。

【答】“工程”菜单。

三、思考题1. 简述Visual Basic的特点。

【答】与一般的程序设计语言相比,VB具有以下特点:(1) 可视化的设计平台;(2) 面向对象的设计方法;(3) 事件驱动的编程机制;(4) 结构化的设计语言;(5) 充分利用Windows资源;(6) 开放的数据库功能与网络支持。

2. 简述Visual Basic集成开发环境的组成。

【答】VB 6.0集成开发环境除了具有标准Windows环境的标题栏、菜单栏、工具栏外,还有工具箱、属性窗口、工程管理器窗口、窗体设计器、立即窗口、窗体布局窗口等有用的开发工具。

(1) 标题栏和菜单栏:标题栏中显示的有窗体控制菜单图标、当前激活的工程名称、当前工作模式以及最小化、最大化∕还原、关闭按钮。

菜单栏中显示了“文件”、“编辑”、“视图”、“工程”、“格式”等菜单项,其中包含了VB编程的常用命令。

VB程序设计教程课后答案解析

VB程序设计教程课后答案解析

A.1Private Sub Comma nd1_Click( Label3 = TextlEnd SubA.2Private Sub Form_Load(Timer1 .In terval = 0End SubPrivate Sub Comma nd1_Click(自动Timer1.I nterval = 200End SubPrivate Sub Comma nd2_Click(手动Timer1.I nterval = 0Call MyMoveEnd SubPrivate Sub Timer1_Timer(Call MyMoveEnd SubSub MyMove(Labell.Move Labell.Left - 50If Labell 丄eft < 0 Then Labell 丄eft = Forml.Width End Sub A. 3Private Sub Form_Click(Text1 = V al(Text1 + 1End SubPrivate Sub Form_Load(Textl = 0End SubA.4Private Sub Form_Click(Caption ="单击窗体,改变图片"Picture = LoadPicture(App.Path + "\n_015.bmp"Print"欢迎使用VB"End SubPrivate Sub Form_DblClick(ClsCaption ="双击窗体,卸去图片"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 图的宽度,象素单位'Forml.Height = 260 * 16 + 200'260是图的高度,象素单位,200是窗体的标题栏高度End SubA. 5Sub Comma nd1_Click(Textl.Fo ntName ="隶书”Textl.Fo ntSize = 25End SubSub Comma nd2_Click(Text2.Text = Textl.SelTextText2.Fo ntName = Textl.Fo ntNameText2.Fo ntSize = Textl.Fo ntSizeEnd SubB.1Private Sub Comma nd1_Click(Text2 = Format(5 / 9 * (V al(Text1 - 32, "0.00" End SubPrivate Sub Comma nd2_Click(Text1 = Format(9 / 5 * V al(Text2 + 32, "0.00" End Sub或Private Sub Comma nd1_Click(Dim f!, c!'声明两个变量f = V al(Text1c = 5 / 9 * (f - 32Text2 = Format(c, "0.00"'保留两位小数End SubPrivate Sub Comma nd2_Click(Dim ff!, cc!'声明两个变量cc = V al(Text2ff = 9 / 5 * cc + 32Textl = Format(ff, "0.00"'保留两位小数End SubB.2Label2 = Format(V al(Text1 * V al(Text1 * 3.14, "0.00" End Sub Private Sub Comma nd2_Click(Label3 = Format(V al(Text1 * 3.14 * 2, "0.00"End SubPrivate Sub Text1_LostFocus(If Not lsNumeric(Text1.Text The nMsgBox "输入有非数字字符,请重新输入",,"警告"Textl.Text =""Textl.SetFocusEnd IfEnd Sub或Private Sub Comma nd1_Click(Label2 = Format(V al(Text1 * V al(Text1 * 3.14, "0.00" End Sub Private Sub Comma nd2_Click(Label3 = Format(V al(Text1 * 3.14 * 2, "0.00"End SubPrivate Sub Text1_KeyPress(KeyAscii As In teger If KeyAscii = 13 The nIf Not lsNumeric(Text1.Text The nText1.Text =""End IfEnd IfEnd SubB. 3Private Sub Comma nd1_Click(n = In t(Log(2 / Log(1.008 + 1Label1 = n & "年后人数超过26亿"End SubB.4Private Sub Comma nd1_Click(Dim x, dx, cdx = Text1.Textdx = UCase(xcd = Len(xPrint"大写字母为:";dxPrint"字符串长度为:";cdEnd SubB. 5Textl = In t(R nd * 900 + 100End SubPrivate Sub Comma nd2_Click(Dim x%, x1%, x2%, x3%x = V al(Text1x1 = x Mod 10 '分离出的个位数x2 = (x Mod 100 \ 10 '分离出的十位数x3 = x \ 100 '分离出的百位数Label1 = x1 * 100 + x2 * 10 + x3 End SubB.6Private Sub Form_Click(Label1 = Left(Text1, 11Label2 = Mid(Text1, 12, 6Label3 = Right(Text1,5End SubB.7Private Sub Comma nd1_Click(PrintFor i = 1 To 5Print Tab(15 - i * 2; String(2 * i - 1, " ★"; Spc(18 - 4 * (i - 1; String(2 * i - 1, " ★"Next iEnd SubPrivate Sub Comma nd2_Click(CisEnd Sub进一步要求:Private Sub Comma nd1_Click(PrintFor i = 1 To 5Print Tab(15 - i * 2; String(2 * i - 1, " ★"; String(10 - (2 * i - 1, " ☆"; String(2 * i - 1, "★"Next iEndSubprivateSubCommand2IC=ck(c_sEndSubB.8privateSubFo「mlc=ck(X H < a -(-n p u 65o x (二鸯>—日»達==斗«=pfH Formafx* X - =0-000= pfg H Fo 「maf(sq 「(><=0_fgH Folmafx> (1、3=0.000=Prinf=:=pf 八space(5八U H R :=pfg八 space(5八2二f八space©诺R 2二fgEndSub0--privateSubFo「mlc=ck(XH< a-(-n p u 65o x (二鸯> 妄血一fxA-0Elself x < 2000 Then y = 0.9 * x Elself x < 3000 Then y = 0.8 * x Else y = 0.7 * xEnd IfPrint yEnd SubC. 2Private Sub Form_Click(Dim x!, y!x = V al(lnputBox("输入上网时间"If x < 10 The n y = 30Elself x < 50 The n y = 30 + 2.5 * (x - 10Elsey = 30 + 2.5 * 40 + 2 * (x - 50End IfIf y > 150 The ny = 150End IfPrint yEnd SubC. 3Private Sub Comma nd1_Click(Dim x!, y!, z!x = In putBox("i nput x"y = In putBox("i nput y"z = In putBox("i nput z"Print " x y z"Print "排序前";x; " "; y; " ";zIf x < y The n t =x:x = y: y = tIf x < z The n t =x:x = z: z = tIf y < z The n t =y:y = z: z = tPrint "排序后"& x & " " & y & " " & z End SubPrivate Sub Comma nd2_Click(Dim x!, y!, z!x = In putBox("i nput x"y = In putBox("i nput y"z = In putBox("i nput z"Print " x y z"Print "排序前";x; " "; y; " "; zIf x < y The n t = x: x = y: y = tIf y < z The nt = y: y = z: z = tIf x < y The nt = x: x = y: y = tEnd IfEnd IfPrint "排序后"& x & " " & y & " " & z End Sub C.4Dim a(3 As In tegerPrivate Sub Comma nd1_Click(Picturel.CIsFor i = 0 To 2 a(i = Int(Rnd * 100 + 200 Picturel.Pri nt a(iNext iEnd SubPrivate Sub Comma nd2_Click( Picture2.ClsDim z As In tegerFor i = 0 To 1If a(i > a(i + 1 The nz = a(i + 1a(i + 1 = a(ia(i = zNext iPicture2.Pri nt a(0Picture2.Pri nt a(1Picture2.Pri nt a(2End SubC.5Private Sub Text2_LostFocus(Dim m%, n%, y%m = V al(Text1n = V al(Text2If n Mod 2 <> 0 The nMsgBox ("脚数必定为偶数"Text2 =""Text2.SetFocusElsey = n / 2 - mIf y < 0 The nMsgBox ("脚数必须倍的头数,请重新输入Text2 =""Text2.SetFocusElsex = n / 2 - mLabel2 = yLabel3 = m - yEnd IfEnd IfEnd SubC.6Private Sub Comma nd1_Click(Dim a!, b!, c!, x1!, x2!, de!a = Text1b = Text2c = Text3de = b * b - 4 * a * ct = 2 * aIf de = 0 The nText4 = Format(-b / t, "0.00"Text5 = Format(-b / t, "0.00"Elself de > 0 The nText4 = Format((-b + Sqr(de / t, "0.00"Text5 = Format((-b - Sqr(de / t, "0.00"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" & "i" E nd IfEnd SubPrivate Sub Comma nd2_Click( Textl =""Text2 =""Text3 =""Text4 =""Text5 =""End SubC.7Private Sub Text3_LostFocus( Select Case Trim(Text3Case "+"Text4 = V al(Text1 + V al(Text2 Case "-"Text4 = V al(Text1 - V al(Text2 Case "*"Text4 = V al(Text1 * V al(Text2 Case "/"If V al(Text2 = 0 Then MsgBox "分母为零,重新输入"Text2 =""Text2.SetFocusElseText4 = V al(Text1 / V al(Text2 End IfEnd SelectEnd SubC.8Private Sub Text1_LostFocus( Select Case Trim(Text1Case 1Text2 = "Mo nday"Case 2Text2 = "Tuesday"Case 3Text2 = "Wed nesday"Case 4Case 5Text2 = "Friday"Case 6Text2 = "Saturday"Case 7Text2 = "Su nday"Case Is > 7, Is < 1MsgBox "数字为1~7,重新输入" Textl =""Text1.SetFocusEnd SelectEnd Sub或者Private Sub Text1_LostFocus( If Text1 > 7 Or Textl < 1 The n MsgBox "数字为1~7,重新输入" Textl =""Textl.SetFocusElseText2 = Choose(Text1, "Mo nday", "Tuesday", "Wed nesday", "Thursday", "Friday", "Saturday", "Su nday"End IfEnd SubD.1Private Sub Form_Click(For i = 1 To 9Print Tab(10 - i; String(2 * i - 1, Trim(Str(iNext iEnd SubD.2Private Sub Form_Click(For i = 1 To 10 Step 1Print Tab(i; Stri ng((20 - 2 * i, Chr(64 + iNext iEnd SubD.3Private Sub Comma nd1_Click(Dim s!, t!, i&t = 1For i = 1 To 100000t = t + is = s + 1 / tIf 1 / t < 0.00001 Then Exit ForNext iPrin t "For 结构";s, i;"项"End SubD.4Private Sub Comma nd1_Click(Dim n&, pi#, i&n = InputBox("输入n 值"pi = 2For i = 1 To npi = pi * (2 * i / (2 * i - 1 * (2 * i / (2 * i + 1 Next i Print "当n=" & n & ” 时,pi="; piEnd SubD.5Private Sub Form_Click(Dim s!, t!, i!, a%, n%a = In t(R nd * 9 + 1n = In t(R nd * 6 + 5t = 0: s = 0Prin t "a="; a, " n二";nFor i = 1 To nt = t * 10 + as = s + tPrint t;Next iPrintPrin t "s="; sEnd SubD.6Private Sub Comma nd1_Click( Dim s As In tegers = 0For i = 1 To 9Forj = 0 To 9For k = 0 To 9s = i * 100 + j * 10 + kIf s = i A 3 + j A 3 + k A 3 The nPrint sEnd IfNext kNext jNext iEnd SubPrivate Sub Comma nd3_Click( formd6.Hide main .ShowEnd SubD.7Private Sub Comma nd1_Click(Dim a!, xO!, x1!Doi = i + 1x1 = 2 * x0 / 3 + a / (3 * x0 * x0If Abs(x1 - x0 < 0.00001 Then Exit Do x0 = x1 LoopPrint x1, iEnd SubD.8Private Sub Comma nd1_Click(s = 0x0 = 0.01For i = 1 To 30s = s + x0x0 = x0 * 2Next iEnd SubD.9Private Sub Comma nd4_Click(Picturel.CIsPicture1.Print "x 课安排在";"y 课安排在";"z 课安排在"Picturel.Print ""For z = 5 To 6For x = 1 To z - 2For Y = x + 1 To z - 1X1 = Choose(Weekday(x,'周一","周二","周三","周四","周五","周六","周日"Y1 = Choose(Weekday(Y,'周一","周二","周三","周四","周五","周六","周日"z1 = Choose(Weekday(z,周一","周二","周三","周四","周五","周六","周日" Picturel.Pri nt" "; X1; ""; Y1; " "; z1Next YNext xNext zEnd SubE.1Private Sub Form_Click(Dim a(1 To 10 As In tegerFor i = 1 To 10a(i = In t(R nd * 71 + 30Print a(i;"";Next iMax = a(1Min = a(1A vg = a(1For i = 2 To 10If a(i > Max The n Max = a(iIf a(i < Min Then Min = a(iA vg = A vg + a(iNext iA vg = A vg / 10PrintPrint "Max="; Max; " Min="; Min;" A vg="; A vg End SubE.2Private Sub Form_Click(Dim aa = Array(56, 78, 98, 88, 76, 78For i = 0 To 5Print Stri ng(a(i \ 5, " ♦"; a(iPrintNext iEnd SubE.3Dim a%(19Private Sub Comma nd1_Click( Picturel.CIsFor i = 0 To 19a(i = Int(Rnd * 101Picturel.Pri nt a(i;"";If (i + 1 Mod 4 = 0 The n Picturel.Pri nt Next iEnd SubPrivate Sub Comma nd2_Click( Picture2.CIsDim s(5 To 9For i = 0 To 19Select Case kCase 0 To 5s(5 = s(5 + 1Case 9 To 10 '90~10(分的人数s(9 = s(9 + 1Case 6 To 8 '存放其他三个分数段的下标有规律,根据K获得s(k = s(k + 1 End SelectNext iFor i = 5 To 9If s(i <> 0 Then Picture2.Print "s("; i;"的人数有";Format(s(i, "0";"个"Next i End SubE.4Private Sub Comma nd1_Click(Picture1.ClsDim d%(1 To 10For i3 = 1 To 10Ran domized(i3 = Int(Rnd * 91 + 10For i = 1 To 10For j = 1 To 10 - iIf d(j < d(j + 1 The nt = d(j: d(j = d(j + 1: d(j + 1 = t End IfNext jNext iFor i = 1 To 10: Picture1.Pri nt d(i; If i Mod 5 = 0 Then Picture1.Print Next iEnd SubE.5Dim a%(3, 3, b%(3, 3Private Sub Form_Load(For i = 0 To 3Forj = 0 To 3a(i, j = In t(R nd * 36 + 35b(i, j = Int(Rnd * 41 + 100Next iEnd SubPrivate Sub Comma nd1_Click( Picturel.CIsFor i = 0 To 3Forj = 0 To iPicture1.Pri nt a(i, j;"";Next jPicture1.Pri ntNext iEnd SubPrivate Sub Comma nd2_Click( Picture2.ClsFor i = 0 To 3For j = i To 3Picture2.Pri nt Tab(j * 6; b(i, j; Next jPicture2.Pri ntEnd SubPrivate Sub Comma nd3_Click( Picture3.Clssa = 0For i = 0 To 3sa = sa + a(i, iNext isb = 0For i = 0 To 3sb = sb + b(i, 3 - iNext iPicture3.Print "A数组主对角线元素和为:";sa Picture3.Print "B数组副对角线元素和为:";sb End SubE.6Private Sub Form_Click(n = InputBox("输入n 值"ReDim a6%(n + 1, n + 1a6(0, 0 = 1: a6(1, 1 = 1: a6(1, 0 = 1For i = 2 To n + 1Forj = 2 To ia6(i, j = a6(i - 1, j - 1 + a6(i - 1, j Picturel.Print a6(i, j;""Next jPicturel.Pri ntNextEnd SubE.7Private Sub Form_Load(List1.ClearList1.Addltem "大学计算机基础"List1.Addltem "C/C++ 程序设计"List1.AddItem "VB 程序设计"List1.AddItem "Web 程序设计" Listl.Addltem "多媒体技术与应用" Listl.Addltem "数据库技术与应用" Listl.Addltem "网络技术与应用" Listl.Addltem "硬件技术基础"Listl.Addltem "软件技术技术基础" Private Sub List1_Click(If List2丄istCount >= 5 Then MsgBox ("超过5门课程,不能再选"Exit SubElseList2.Addltem List1.TextList1.Removeltem List1.ListIndexEnd IfEnd SubE.8Sub Combo1_KeyPress(KeyAscii As In teger Select Case KeyAscii Case 48 To 57, 13Case ElseKeyAscii = 0End SelectIf KeyAscii = 13 The nCombo1.Addltem Combo1.TextEnd SubPrivate Sub Comma nd1_Click(Dim mi n%, max%min = V al(Combo1.List(0max=V al(Combo1.List(0=imin=0=imax =0Fori : =1 To Combol.ListCount - 1 If V al(Combo1 丄ist(i > max Then imax = i=Combol. List(imax=Elself V al(Combo1 .L ist(i < min Then imin = imin = C ombol. List(iEnd IfNext it = Combo1.List(0Combol. List(0 = Combo1.List(iminCombo1.List(imin = tt = Combol 丄ist(Combo1.ListCount - 1Combol.List(Combo1.ListCount - 1 = Combo1.List(imax Combo1.List(imax = t End SubE.9Private Sub Form_Click(For i = 0 To Scree n.Fo ntCou nt - 1If Asc(Left(Scree n.Fo nts(i, 1 < 0 The nPicture1.Pri nt Scree n.Fon ts(iPicture2.F on tName = Scree n.Fon ts(iPicture2.Print"商丘师范学院"End IfNext iEnd SubE.10Private Type clerknu mber As Stri ng * 3n ame As Stri ng * 5salary As In tegerDim a(0 To 4 As clerk, n%Private Sub Comma nd1_Click(If n >= 5 The nMsgBox ("输入人数超过数组声明的个数"ElseWith a(n.nu mber = Text1.n ame = Text2.salary = Text3Picture1.Print a(n.number, a(, a(n.salary Print End Withn = n + 1Text1 =""Text2 =""Text3 =""End IfEnd SubPrivate Sub Comma nd2_Click(Dim t As clerk, i%, j%For i = 0 To n - 1For j = i To n - 1If a(i.salary < a(j + l.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 - 1Picture1.Pri nt a(i .nu mber, a(i .n ame, a(i.salaryPrintNext iEnd SubF.1Private Sub Form_Click(Dim a(1 To 10, ami n, i%For i = 1 To 10a(i = -In t(R nd * 101 + 300Print a(i;Next iCall s(a(, aminPrintPrint "min="; aminEnd SubSub s(b(, minDim i%min = b(LBo un d(bFor i = LBou nd(b + 1 To UBou nd(bIf b(i < min Then min = b(iNext iEnd SubF.2Private Sub Comma nd1_Click(Dim mm%, nn%mm = V al(Text1nn = V al(Text2Picturel.Pri nt mm; Tab(6; nn; Tab(12; gcd(mm, nn End Sub Fun ction gcd%(ByV al m%, ByV al n%If m < n The n t = m: m = n: n = tr = m Mod nDo While (r <> 0m = n: n = r: r = m Mod nLoopgcd = nEnd FunctionF.3Dim x!Private Sub Comma nd1_Click(Print "调用标准函数Sin的结果";Sin(xEnd SubPrivate Sub Comma nd2_Click(Print "调用自定义函数MySin的结果";MySin(x End Sub Fu nction MySi n(x! As DoubleDim i%, t!, s!t = xs = tDo While Abs(t > 0.00001t = -1 * t * x * x / ((i + 1 * (i + 2s = s + ti = i + 2LoopMySin = sEnd FunctionPrivate Sub Comma nd3_Click(x = In putBox("输入要计算正弦函数的角度值x" x = x * 3.14 / 180End SubF.4Private Sub Text1_KeyPress(KeyAscii As In teger If KeyAscii = 13 Then If Not lsNumeric(Text1 The nMsgBox "输入非数字串,重新输入"Text1.Text =""Text1.SetFocusElsePicture1.Pri nt Text1; " ★"ElsePicturel.Pri nt TextlEnd IfTextl =""End IfEnd IfEnd SubFunction IsH(ss As Stri ng As Boolea n Dim i%, Ls%IsH = Truess = Trim(ssLs = Len(ssFor i = 1 To Ls \ 2If Mid(ss, i, 1 <> Mid(ss, Ls + 1 - i, 1 Then IsH = FalseExit FunctionEnd IfEnd FunctionF.5Function prime(ByV al m As In teger As Boolea nprime = TrueDim i%For i = 2 To m - 1If (m Mod i = 0 Then prime = False: Exit Function '注意冒号和exit 的范围Next i End FunctionPrivate Sub Comma nd1_Click(n = 0For i = 6 To 100 Step 2Forj = 3 To i\2If prime(j The nIf prime(i - j ThenList1.Addltem i & " =" & j & " +" & i - jn = n + 1End IfEnd IfNext iPicturel.Print" 6和100之间共有";n;"对素数和" End SubF.6Dim a%(Private Sub Form_Click(Print "1000以内的完数为:"For i = 1 To 1000If lsWs(i The nPrint i; "=1";For j = 1 To UBou nd(aPrin t "+"; a(j;Next jPrintEnd IfNext iEnd SubFunction lsWs(m As Boolea nDim s%ForiH _k Tom一2-f3Mod iHThenReDimPreserve異Hiu-j+1sHs +iEnd _fNexfiprivate SubDe-esf 「(slAs siring"ByVa-s2Asss.ngDimi%-S2HLen(s2 i H-nsf 「(s严s2Dowh=e iVosi HLeft(s 「i11+Mid(s严 i+-甘卅那『>End SubPrivate Sub Command1_Click('调用DeleStr 子过程Dim ss1 As String ss1 = Text1Call DeleStr(ss1, Text2Text3 = ss1End SubPrivate Sub Comma nd2_Click(End SubF.8Private Sub Comma nd1_Click(Dim maxw$maxle n Text1 & ” ", maxwText2 = maxwEnd SubSub maxle n( s$, maxw$Dim word$maxw =""Do While s <> "" i = In Str(s,""word = Left(s, i - 1If Len( word > Len( maxw Then maxw = word s = Mid(s, i + 1 LoopEnd SubG.1Private Sub Comma nd1_Click(List1.ClearList1.Addltem Combo1If Option1 Then List1.AddItem "Pentium II"If Option2 Then List1.AddItem "Pentium I"If Option3 Then List1.AddItem "Celeron"List1.AddItem Text1If Check1 Then List1.AddItem "声卡"If Check2 Then List1.AddItem "Modem"If Check3 Then List1.AddItem "网络适配器"End SubPrivate Sub Text1_LostFocus(st = UCase(Trim(Text1le = Len(stIf Not lsNumeric(Left(st, le - 2 Or Right(st, 2 <> "MB" Then MsgBox "有不合法字符!"Text1 =""Text1.SetFocusEnd IfEnd SubG.2Private Sub Check1_Click(Picture1.Fo nt.Bold = Not Picture1.Fo nt.BoldEnd SubPrivate Sub Check2_Click(Picture1.Fo nt.ltalic = Not Picture1.F on t.BoldEnd SubPrivate Sub Comma nd1_Click(Picture1.ClsIf Optio n1 The nPicture1.Print Sin(V al(Text1ElseIf Optio n2 ThenPicturel.Print Exp(V al(Text1Elself Optio n3 The nPicturel.Print Sqr(V al(Text1End IfEnd SubPrivate Sub return_Click(l ndex As In tegerForm6.ShowUn load Form2End SubG.3Private Sub HScroll1_Cha nge(Text1 = VScroll1.V alueText2 = HScroll1.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubPrivate Sub HScroll2_Cha nge(Textl = VScrolll.V alueText2 = HScrolll.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubPrivate Sub VScroll1_Cha nge(Textl = VScrolll.V alueText2 = HScrolll.V alueText3 = HScroll2.V alueText4 = Format(V al(Text1 * (Text3 / 100 * (Text2 / 12, "0.00" Text5 = Format(V al(Text4 + V al(Text1, "0.00"End SubG.4Dim t As Sin glePrivate Sub Comma nd1_Click(t = InputBox("输入倒计时分钟数"t = t * 60ProgressBar1.Min = 0ProgressBar1.Max = t。

大学计算机VB程序设计教程课后答案

大学计算机VB程序设计教程课后答案

第1章概述二.选择题:1.C2. B.3.C.4.C.5.A6.C7.D8.B9.B 10.B11.A12.C 13.D 14.C 15.D16.A17.C 18.A19.A20.D 21.B三.填空题:1.面向对象,事件驱动2.编译,解释3.设计,运行,中断4.F55.调试6.切换文件夹四.编程及上机调试:1.略2.Sub Form_Click( )Label1.Caption = “你单击了窗体”End SubSub Form_DblClick( )Label1.Caption = “你双击了窗体”End Sub第2章面向对象编程基础二.选择题:1.C2. C.3.B.4.B.5.D6.D7.B8.B9.C 10.D11.B 12.B 13.B 14.C 15.A16.B 17.B 18.B 19.C 20.B三.填空题:1.窗体,控件2.属性,事件,方法mand2_click4.picture5.中部,代码四.编程及上机调试:1.Private Sub Command1_Click()Form1.WindowState = 2End SubPrivate Sub Command2_Click()Form1.WindowState = 0Private Sub Command3_Click()Form1.WindowState = 1End Sub2.Private Sub Command1_Click()Form1.Picture = LoadPicture("d:\picture\flower.wmf")Command1.V isible = FalseCommand2.V isible = FalseEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_DblClick()Form1.Picture = LoadPicture("")Command1.V isible = TrueCommand2.V isible = TrueEnd Sub第3章常用标准控件二.选择题:1.C2. B3.C.4.D5.B6.B7.A8.C9.B 10.C11.C 12.A13.C 14.B 15.D16.D 17.C 18.A19.D 20.A21.B三.编程及上机调试:1.Private Sub Check1_Click()If Check1.V alue = 1 ThenText1.FontBold = TrueElseText1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.V alue = 1 ThenText1.FontItalic = TrueElseText1.FontItalic = False End IfEnd SubPrivate Sub Check3_Click()If Check1.V alue = 1 ThenText1.FontUnderline = True ElseText1.FontUnderline = False End IfEnd SubPrivate Sub Command1_Click() Text1.Text = " "End Sub2.Private Sub Command1_Click() Text2.Text = List1.ListCount End SubPrivate Sub Command2_Click() List1.AddItem Text1.TextText1.Text = " "End SubPrivate Sub Command3_Click() Dim i As Integeri = List1.ListIndexList1.RemoveItem iCommand3.Enabled = FalseText1.SetFocusText2.Text = List1.ListCount End SubPrivate Sub Form_Load()Command3.Enabled = False End SubPrivate Sub List1_Click()Command3.Enabled = True End Sub第4章VB语言基础二.选择题:1.A2. D3.D.4.A5.A6.A7.C8.D9.C 10.B11.A 12.D 13.C 14.A15.A16.C 17.D 18.A19.B 20.D21.C 22.A23.B 24.C 25.C三.编程及上机调试:1.Private Sub Form_Load()Dim x As Integer, s As String, d As IntegerRandomizex = Int(Rnd * 9000 + 1000)s = Trim(CStr(x))d = V al(Right(s, 1) + Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1))ShowPrint "产生的数;"; x; "倒序数"; dEnd Sub2.Private Sub Form_KeyPress(KeyAscii As Integer)Print "输入字符:"; Chr(KeyAscii), "ASCII码为:"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Sub3.Private Sub Form_Click()MsgBox "在这里显示提示" & vbCrLf & "提示信息", 2 + 16, "请确认"End Sub或Private Sub Form_Click()MsgBox "在这里显示提示" + Chr(13) + "提示信息", vbAbortRetryIgnore _ + vbCritical, "请确认"End Sub第5章程序控制结构二.单选题1.D2. C3.C.4.D.5.B6.C7.A8.A9.D 10.C11.C 12.C 13.B 14.B四.编程及上机调试1. Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")If x > 20 Theny = x ^ 2 + 3 * x + 2ElseIf x >= 10 Theny = Sqr(3 * x) - 2ElseIf x > 0 Theny = 1 / x + Abs(x)End IfPrint "x="; x, "y="; yEnd Sub(2)Select Case实现:Private Sub Form_Click()Dim x As Integer, y As Integerx = InputBox("请输入一个数值")Select Case xCase Is > 20y = x ^ 2 + 3 * x + 2Case Is >=10y = Sqr(3 * x) - 2Case Is > 0y = 1 / x + Abs(x)End SelectPrint "x="; x, "y="; yEnd Sub2.Private Sub Form_Click()Dim a As Integer, b As Integer, c As IntegerFor i = 100 To 999a = i \ 100b = (i - a * 100) \ 10c = i Mod 10If a ^ 3 + b ^ 3 + c ^ 3 = i ThenPrint i;k = k + 1If k Mod 2 = 0 Then PrintEnd IfNext iEnd Sub3.Private Sub Command1_Click()p = 60: r = 0.014Dop = p * (1 + r)n = n + 1Loop Until p >= 70Print n; "年后世界人口达到"; p; "亿"End Sub4.Private Sub Command1_Click()Dim s As Single, x As Integer, t As Single, n As Integer x = V al(InputBox("请输入x的值", , 2))s = 1n = 1m = 1Don = n + 1m = -mt = m * n / x ^ (n - 1)If Abs(t) < 0.00001 Then Exit Dos = s + tLoopPrint sEnd Sub第6章数组二.单选题:1.A2.A.3.A4.C5.D6.D7.A8.D9.B 10.B四.编程及上机调试:1.Option Base 1Private Sub Form_Click()Dim a(10) As IntegerDim i As Integer, t As IntegerPrint "数组的原始数据为:";For i = 1 To 10a(i) = Int(11 * Rnd) + 10Print a(i);Next iPrintPrint "变化后数组数据为:";For i = 1 To 5t = a(i)a(i) = a(10 - i + 1)a(10 - i + 1) = tNext iFor i = 1 To 10Print a(i);Next iEnd Sub2.Option Base 1Private Sub Form_Click()Dim a(3, 4) As Integer, i As Integer, j As Integer, k As Integer, p As Integer RandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(90 * Rnd + 10)Print a(i, j);Next jPrintNext iMax = a(1, 1): k = 1: p = 1For i = 1 To 3For j = 1 To 4If a(i, j) > Max ThenMax = a(i, j)k = ip = jEnd IfNext jNext iPrint "最大的数为第" & k & "行,第" & p & "列的数:" & MaxEnd Sub3.Option Base 1Dim a(4, 5) As Integer '在窗体声明段声明数组Dim i As Integer, j As IntegerPrivate Sub cmdmatrix_Click() '"生成数组"按钮RandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 10) '一位的随机数Picture1.Print a(i, j); '输出元素Next jPicture1.PrintNext iEnd SubPrivate Sub cmdcol_Click() '"求列和"按钮Dim colsum As Integertxtcol.Text = ""For j = 1 To 5 '列变量先循环colsum = 0For i = 1 To 4colsum = colsum + a(i, j)Next itxtcol.Text = txtcol.Text & Str(colsum)Next jEnd SubPrivate Sub cmdrow_Click() '"求行和"按钮Dim rowsum As Integertxtrow.Text = ""For i = 1 To 4 '行变量先循环rowsum = 0For j = 1 To 5rowsum = rowsum + a(i, j)Next jtxtrow.Text = txtrow.Text & CStr(rowsum) & vbCrLf Next iEnd SubPrivate Sub cmdclear_Click() '"清除"按钮Picture1.Clstxtcol.Text = ""txtrow.Text = ""End SubPrivate Sub cmdexit_Click() '"结束"按钮EndEnd Sub4. Option Base 1Private Sub Form_Click()Dim a() As Integer, b() As Integer, i As Integer, j As Integer, x As Integer, y As Integer x = InputBox("第一维上界")Do While Not IsNumeric(x)x = Int(InputBox("第一维上界"))Loopy = InputBox("第二维上界")Do While Not IsNumeric(x)y = Int(InputBox("第二维上界"))LoopReDim a(x, y)Print "原数组元素为:"For i = 1 To xFor j = 1 To ya(i, j) = Int(90 * Rnd) + 10Print a(i, j);Next jPrintNext iPrint "转置后数组元素为:"For i = 1 To yFor j = 1 To xPrint a(j, i);Next jPrintNext iEnd Sub5. Option Base 1Private Sub Form_Click()Dim a(10, 10) As Integer, i As Integer, j As IntegerFor i = 1 To 10For j = 1 To 10If i = j Or i + j = 11 Thena(i, j) = 0Elsea(i, j) = 1End IfPrint a(i, j);Next jPrintNext iEnd Sub6. Option ExplicitOption Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, k As Integer, a(11) As Integerj = 1For i = 3 To 21 Step 2a(j) = iPrint a(j);j = j + 1Next iPrintn = InputBox("请输入一个数")For i = 1 To 10If n = a(i) ThenFor j = i To 10a(j) = a(j + 1)k = k + 1Next jEnd IfNext iFor i = 1 To 9Print a(i);Next iEnd Sub7. Option Base 1Private Sub Form_Click()Dim a As V ariant, k As Integer, i As Integer, j As IntegerDim b As V ariantb = Array(17, 35, 128, 235, 89, 121, 143, 189, 231, 94)a = Array(11.3, 12.3, 12#, 11.8, 12.6, 11.6, 12.8, 11.8, 12.4, 12.1)For i = 1 To 9 '对数组a的元素排序k = iFor j = i + 1 To 10If a(k) > a(j) Then k = jNext jIf k <> i Then '数组b的元素随数组a的元素一起变动t = a(i)a(i) = a(k)a(k) = tt = b(i)b(i) = b(k)b(k) = tEnd IfNext iPrint "按名字的排列顺序为:"For i = 1 To 10If Len(b(i)) = 2 Then b(i) = "0" & b(i) '补上数组b中长度为2的编号前的"0"Print "第" & i & "名的号码为:" & b(i) & ",成绩为:" & a(i)Next iEnd Sub第7章过程二、单选题1.C2. D3.C4.D5. B6.A7. B8.B9.C 10.D11.C 12.D 13.B 14.B 15.C16.A17.B 18.B三、填空题1.52 512.4 118 353.1 3 5四.编程及上机调试:1. Private Sub Command1_Click()Dim n As IntegerFor n = 100 To 1600 Step 500Print "n="; n; "时π的近似值是:"; pi(n)Next nEnd SubPrivate Function pi(x As Integer) As SingleDim s As Single, k As Integer, m As Integers = 0k = 1m = 1Dos = s + m / km = -mk = k + 2Loop While k <= xpi = 4 * sEnd FunctionPrivate Sub Command2_Click()EndEnd Sub2. Private Sub Command1_Click()Dim x As Integer, i As Integerx = V al(Text1)For i = 1 To xIf prime(i) And prime(x - i) ThenLabel2 = Str(x) & "是" & Str(i) & "和" & Str(x - i) & "两个素数之和"Exit SubEnd IfNext iEnd SubPrivate Function prime(x As Integer) As BooleanFor i = 2 To Int(Sqr(x))If x Mod i = 0 Thenprime = FalseExit FunctionEnd IfNext iprime = TrueEnd FunctionPrivate Sub Command2_Click()EndEnd Sub3. Option ExplicitOption Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()RandomizeDim i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Text1 = Text1 + Str(a(i))Next iCall sort(a)For i = 1 To 10Text2 = Text2 + Str(a(i))Next iEnd SubPrivate Sub sort(a() As Integer)Dim k As Integer, i As Integer, j As Integer, t As Integer k = UBound(a)For i = 1 To k - 1For j = i + 1 To kIf a(i) < a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPrivate Sub Command2_Click()EndEnd Sub4. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, s As IntegerFor i = 2 To 1000S=0For j=1 To i - 1If I mod j=0 Then s=s+jNext jIf s=i Then Print I,Next iEnd Sub5. Public a(10) As IntegerPublic Sub sort(a() As Integer)Dim i As Integer, j As Integer, t As IntegerFor i = 1 To UBound(a) - 1For j = i + 1 To UBound(a)If a(i) > a(j) Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jNext iEnd SubPublic Function max(a() As Integer) As Integermax = a(1)For i = 2 To UBound(a)If max < a(i) Thenmax = a(i)End IfNext iEnd Function窗体Form1代码Private Sub Command1_Click()Dim i As IntegerRandomizeFor i = 1 To UBound(a)a(i) = Int(Rnd * 90) + 11Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form1.HideForm2.ShowEnd SubPrivate Sub Command3_Click()Text2 = max(a)End SubPrivate Sub Command4_Click()EndEnd Sub窗体Form2代码Private Sub Command1_Click()Call sort(a)For i = 1 To UBound(a)Text1 = Text1 & Str(a(i))Next iEnd SubPrivate Sub Command2_Click()Form2.HideForm1.ShowEnd Sub第8章程序调试二.上机调试题1. Option ExplicitPrivate Sub Form_Click()Dim a() As Single, i As IntegerDim y As Singlei = 1DoReDim a(i) …改为ReDim Preserve A(I) a(i) = 1 / fib(i)If a(i) <= 0.0001 Then Exit Do …改为a(i) < 0.0001 y = y + a(i)i = i + 1LoopPrint "y="; yFor i = 1 To UBound(a)Print a(i);Next iEnd SubPrivate Function fib(i As Integer) As IntegerIf i = 1 Thenfib = 1ElseIf i = 2 Thenfib = 2ElseFib(i)= fib(i - 1) + fib(i - 2) …改为Fib=Fib(I-1)+Fib(I-2) End IfEnd Function2. Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, k As Integer, st As StringFor i = 10 To 500If wanshu(i) Thenst = CStr(i)Text1.Text = Text1.Text & stCall test(st)Text1.Text = Text1.Text & Chr(13) & Chr(10)End IfNext iEnd SubPrivate Function wanshu(n As Integer) As BooleanDim i As Integer, sum As IntegerFor i = 2 To n – 1 …改为i=1If n Mod i = 0 Thensum = sum + iEnd IfNext iIf sum = n Then wanshu = TrueEnd FunctionPrivate Sub test(s As String)Dim i As Integer, sum As Integersum = 0 …位置错,和for 语句位置调换Do While Len(s) > 1For i = 1 To Len(s)sum = sum + V al(Mid(s, i, 1))Next iText1.Text = Text1.Text & "->" & Str(sum)s = Str(sum) … 改为s = CStr(sum) LoopEnd Sub第9章数据文件一、单选题1.B 2.C 3.A 4.B 5.C6.B 7.C 8.B 9.10.A11. 12.A13. 14. 15.A16.B二、编程及上机调试1.Private Sub Form_Load()Open "d:\my\text2.txt" For Output As #1End SubPrivate Sub Text1_keyPress(KeyAscii As Integer)If KeyAscii = 13 ThenIf Trim(Text1) = "0000" ThenClose #1EndEnd IfWrite #1, Text1Text1.Text = ""End IfEnd Sub2.Option ExplicitPrivate Type Studentname As String * 10age As IntegerEnd TypePrivate Sub Command1_Click()Dim Stu As StudentOpen "d:\my\text2.txt" For Random As #1 Len = Len(Stu) = "WangY ing"Stu.age = 20Put #1, , StuClose #1Open "d:\my\text2.txt" For Random As #1 Len = Len(Stu)Get #1, , StuPrint "姓名:", Print "年龄:", Stu.ageClose #1End Sub第10章其它控件二、选择题1.B 2.B 3.B 4.C 5.6.A,C 7.A 8.9.10.11. 12.B 13.三、填空题1.菜单编辑器2.下拉式菜单弹出式3.顶4.PopupMenu5.多文档窗体6.MDIChild7.Private Sub HScroll1_Change()text1 = HScroll1.V alueEnd SubPrivate Sub HScroll1_Scroll()text1 = HScroll1.V alueEnd Sub8.Private Sub Toolbar1_ButtonClick(ByV al Button As MSComctlLib.Button) Select Case Button.IndexCase 1Form1.BackColor = vbRedCase 2Form1.BackColor = vbGreenCase 3Form1.BackColor = vbBlueEnd SelectEnd Sub四、编程及上机调试1.Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _X As Single, Y As Single)If Button = 1 ThenPicture1.PSet (X, Y)StatusBar1.Panels(1) = "X=" & XStatusBar1.Panels.Item(2) = "Y=" & YEnd IfEnd Sub2.Private Sub Command1_Click()CommonDialog1.FileName = ""CommonDialog1.InitDir = "D:\"CommonDialog1.Filter = "Word Files|*.doc|文本文件|*.Txt" '设置过滤器CommonDialog1.DialogTitle = "打开文件" '设置打开对话框的标题CommonDialog1.Action = 1 '创建"打开"对话框If CommonDialog1.FileName = "" Then '判断文件名是否为空MsgBox "没有选择文件", 37, "检查" '若为空,则显示信息ElseOpen CommonDialog1.FileName For Input As #1 '打开选定的文件Do While Not EOF(1)Line Input #1, a$ '读文件的一行Text1 = Text1 & a$ & vbCrLf '输出所读的内容LoopEnd IfEnd SubPrivate Sub Command2_Click()CommonDialog1.Flags = 3 '列出打印机和屏幕字体CommonDialog1.Action = 4 '打开"字体"对话框Text1.FontName = CommonDialog1.FontName '改变文本框的字体Text1.FontSize = CommonDialog1.FontSizeText1.FontBold = CommonDialog1.FontBoldText1.FontItalic = CommonDialog1.FontItalicText1.FontUnderline = CommonDialog1.FontUnderline End SubPrivate Sub Command3_Click()EndEnd Sub11章略。

VB程序设计教程课后参考答案

VB程序设计教程课后参考答案

VB程序设计教程课后参考答案习题一一、填空题1.对象、事件驱动2.窗体、控件3.属性4.属性窗口、编程设置5.事件过程6.对象名、下划线、事件名7.Form_click8.Print form1.print “我的VB”9.主窗口、属性、工具箱、代码、窗体、工程资源管理10.菜单、快捷键二、选择题1.C 2. A 3. B 4. B 5. D 6. B C 7. A 三、简答题(略)习题二一、选择题1. D2. C3. C4. B5. C6. B7. C8. B 9. A 10. B 11. B 12. C 13. D 14. B15. A 16. A 17. A 18. A 19. B 20. C 21. A22. B 23. B 24. A 25. C 26. A 27. B 28. B29. C 30. B 31. D 32. D 33. C二、填空题1.Controlbox、Maxbutton、Minbutton2.Multiline TRUE3.******4.单文档界面(SDI)多文档界面(MDI)5.窗体显示6.Passwordchar7._change()三、编程题(略)习题三一、基础知识题(略)二、填空题1.整型、长整型、单精度、双精度2.(x mod 10)*10+x\103.Sin(3.14*15/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)4.(a+b)/(1/(c+5)-c*d/2)5.X mod 5=0 or x mod 9=06.False7.-4、3、-3、3、-4、48.CDEF9.GBCDEFA10.TRUE11.变量、属性12.‘_ :13.(略)14.“”#15.Public、通用/模块、Dim、static、private16.+ 、&、+17.Now() 、time()、日期18.Inputbox()、字符串、val()19.Msgbox()三、选择题1.B 2. C 3. A 4. B D此题有误 5. B 6. A7. D 8. B 9. B 10. C 11. D 12. B13. C 14. B 15. A 16. C 17.A 18. D19. A 20. D 21. A 22. C 23. C 24. D25. A 26. D 27. D 28. B 29. C 30. B31. C 32. B 33. C D此题有误34. C 35. A36. D 37. C 38. A 39. B 40. A 41. C42. C 43. D 44. C 45. D 46. A四、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%, delta%Dim x1#, x2#, x#a = Val(InputBox("please input data to a:", "info", 1))b = Val(InputBox("please input data to b:", "info", 1))c = Val(InputBox("please input data to c:", "info", 1))If a = 0 And b <> 0 Thenx = -c / bPrint "所构成的方程是:" & b & "x" & "+" & c & "=0"Print "该一元一次方程的根是:", xEnd IfIf a = 0 And b = 0 ThenPrint "很抱歉,不能构成合法的方程!"End IfIf a <> 0 Thendelta = b * b - 4 * a * cIf delta >= 0 Thenx1 = (-b + Sqr(delta)) / (2 * a)x2 = (-b - Sqr(delta)) / (2 * a)Print "所构成的方程是:" & a & "x2" & "+" & b & "x" & "+" & c & "=0"Print "该方程的根是:"Print "第一个根是:", x1Print "第二个根是:", x2ElsePrint "所构成的方程是:" & a & " x2" & "+" & b & "x" & "+" & c & "=0"Print "该方程有两个虚根:"Print "第一个虚根是:" & -b / (2 * a) & "+" & Sqr(Abs(delta)) / (2 * a) & "i"Print "第二个虚根是:" & -b / (2 * a) & "-" & Sqr(Abs(delta)) / (2 * a) & "i" End IfEnd IfEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i%, s%s = 0For i = 1 To 99 Step 2s = s + iNextPrint sEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim i%Dim s#s = 0For i = 1 To 100s = s + 1 / i * (-1) ^ (i + 1)NextPrint sEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim i%, n%Dim t#, s#n = Val(InputBox("please input data:", "info", 5))s = 0t = 1For i = 1 To nt = t * is = s + tNextPrint sEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim a%, b%, c%Dim p#, s#a = Val(InputBox("please input data to a:", "info", 3))b = Val(InputBox("please input data to b:", "info", 4))c = Val(InputBox("please input data to c:", "info", 5))。

visualbasic程序设计教程第四版答案

visualbasic程序设计教程第四版答案

visualbasic程序设计教程第四版答案【篇一:visual_basic程序设计教程(第4版)_课后答案】一章习题参考答案一、填空题1、对象事件驱动2、编译运行模式解释运行模式二、简答题1、简述vb的特点。

答:①可视化的程序设计方法②面向对象的程序设计思想③事件驱动的编程机制④结构化的程序设计语言⑤高度的可扩充性⑥强大的数据库访问能力⑦支持动态数据交换⑧支持对象链接与嵌入2、简述vb的安装过程。

答:①向光驱中放入vb安装光盘;②计算机将运行自动安装程序,若没有,执行vb目录下的setup.exe;③根据提示逐一回答问题,并点击“下一步”;④点击“完成”;2、如何启动vb。

答:三种方法:①单击“开始”按钮,选择“程序”菜单下的“microsoft visual basic6.0 中文版”菜单项并单击;②双击桌面上的vb6.0快捷图标;③在“开始”菜单的运行对话框中输入命令来启动vb;第二章习题参考答案一、选择题:1-10、 dcacdbcbbc11-20、badcabbaab21-29、aacbbcddc二、填空题1.窗体、控件2.属性值3.属性窗口设置、代码窗口设置4.事件过程5.对象名、下划线、事件名6. form_click第三章习题参考答案一、选择题1、b2、c3、a4、b5、a6、c7、c二、填空题1、 11字符型、字节型、整型、长整型、单精度型、双精度型、货币型、逻辑型、日期型、对象型、变体型。

string、byte、integer、long、single、double、currency、boolean 、date、object、variant2、双引号(英文)、#3、 ascii、1、24、 public、通用、dim、static、private、static5、、+、+6、 now()、time、日期型三、解答题1、(3)2、(1 )3、(1)常量(关键字)(2)字符型常量(3)逻辑型常量(4)变量(5)字符串常量(6)变量(7)字符串常量(8)变量(9)日期型常量(题目应是#11/16/1999#)(10)数值型常量(单精度)4、315、(1)(1+y/x)/(1-y/x) (2)x^3+3*x*y/(2-y)(3)sqr(abs(a*b-c^3))(4)sqr(s*(s-a)*(s-b)*(s-c))6、7、(1)13 (2)17(3)#1999-11-12#(4)zxy123abc8、(1)19(2)8.16666666666667(3)5.25(4)29、(1)-4 (2)2 . 82842712474619(3)-3(4)49(5)”hello”(6)he7)16 (8)“-459.65” (9)510、(4)11、(2)12、(4)第四章习题参考答案一、选择题:1—7: daabbcd二、填空题1. 500.00%2.将字号扩大为原来的二倍3. b三、编程题(略)1.文本框、标签和命令按钮的名称分别为text1、label1、command1 private sub command1_click()label1.caption=text1.textcommand1.caption=text1.textend sub2.单价、数量、折扣和应付款对应的文本框的名称分别为:text1、text2、text3和text4,计算和清除命令按钮的名称分别为:command1和command2。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

课后习题解答第一、二章:1、简述VB6.0的主要特点答:方便、直观的可视化设计工具;面向对象程序设计方法;事件驱动的编程机制;易学易用的应用程序集成开发环境;结构化程序设计语言;完备的联机帮助功能;强大的多媒体、数据库和网络功能。

2、当正常安装VB6.0后,误把Windows子目录删除。

当重新安装Windows后,是否需要再次安装VB6.0?答:要重新安装的。

因为安装VB6.0时,有些VB程序被系统自动安装在Windows目录下,所以一旦删除Windows子目录,就必须重新安装VB6.0。

3、Visual Basic 6.0分为学习版、专业版和企业版,如何知道所安装的是哪个版本?答:在VB6.0的启动界面上,能显示对应的版本。

4、叙述建立一个完整应用程序的过程答:首先建立用户界面的控件对象(简称控件);然后对控件属性进行设置;再对控件事件过程及编程;保存应用程序;程序调试和运行。

5、Visual Basic 6.0有多种类型窗口,若要在设计时看到代码窗口,应怎样操作?答:选择“视图”—>“代码窗口”命令或单击“工程资源管理器”窗口中的“查看代码”按钮。

6、当建立好一个简单的应用程序后,假定该工程仅有一个窗体模块。

试问该工程涉及多少个要保存的文件?若要保存该工程的所有文件,应先保存什么文件?再保存什么文件?若不这样做,系统会出现什么信息?答:涉及两个文件要保存。

先保存窗体文件(.frm),再保存工程文件(.vbp)。

若先保存工程文件,系统也会先弹出“文件另存为”对话框,要求先保存窗体文件。

7、保存文件时,若不改变目录名,则系统默认的目录是什么?答:系统默认的目录是VB988、安装Visual Basic 6.0后,帮助系统是否也已安装?答:没有。

VB6.0的帮助系统在两光盘上,即MSDN Library,其中还包含了VC、VFP等其他语言的帮助系统。

9、如何使用Visual Basic 6.0的帮助系统?答:最方便的方法是选定要帮助的容,然后按F1功能键,这时系统打开MSDN Library查阅器,直接显示与选定容有关的帮助信息。

10、什么是类?什么是对象?什么是事件过程?答:类是同类对象集合的抽象,它规定了这些对象的公共属性和方法;对象是类的一个实例,对象包含三个要素:属性、方法和事件。

当在对象上发生了事件后,应用程序就要处理这个事件,而处理的步骤就是事件过程。

11、属性和方法的区别是什么?答:属性是对象的特征,方法是对象的行为。

前者有值,可以被赋值或引用;后者没有值,表示能够执行的操作。

12、当标签边框的大小由Caption属性的值进行扩展或缩小时,应对该控件的什么属性进行何种设置?答:将该控件的Autosize属性值设置为true。

13、在VB6.0中,命令按钮的显示形式可以有标准的和图形的两种选择,它们通过什么属性来设置?若选择图形的,则通过什么属性来装入图形?若已在规定的属性里装入了某个图形文件,但该命令按钮还是不能显示该图形,而显示的是Caption属性设置的文字,应怎样修改?答:命令按钮的显示形式通过将Style属性值设置为Graphical来实现。

通过Picture属性来装入图形。

不能显示图形是因为Style属性值被设置为Standard,只要将其改为Graphical,并且将Caption 的值设置为空即可。

14、如果文本框要显示多行文字,应对什么属性设置为何值?答:将MultiLine属性的值设置为True。

15、标签和文本框的区别是什么?答:在程序运行时,标签只能显示文字,不能输入文字,显示文字通过对Caption属性赋值来实现;而文本框既能显示文字,也能输入文字,这通过text属性来实现。

16、要让文本框获得焦点的方法是什么?答:SetFocus方法。

17、简述文本框的Change和KeyPress事件的区别答:相同点是当在文本框输入容时,同时激发上述两个事件;不同点是Keypress事件可通过参数KeyAscii 返回所按键的编码值,可依此判断数据输入的正确性或数据输入结束与否,因而该事件使用较多;change 事件还可以发生在程序改变文本框的text属性时。

18、当某文本框输入数据后(按了回车键),经判断后认为是数据输入错,应怎样删除原来文本框中的数据?答:假定文本框的名称为Text1,则事件过程如下:Private Sub Text1_KeyPress(KeyAscii As Integer )if KeyAscii = 13 thenif 出错条件判断成立 thenText1=””end if……end ifend sub注意:删除刚输入的字符,通过KeyAscii=0语句实现;焦点定位文本框对象采用SetFocus方法。

19、在程序运行前,对某些控件设置属性值,除了在窗体中直接设置外,还可以通过代码设置,这些代码一般存放在什么事件中?如果要将命令按钮定位在窗体的中央,试写出事件过程代码。

答:这些代码一般放在Forem_Load()事件过程中。

将窗体定位在屏幕的中央,只能在属性窗口中将Form1窗口的StartUpPosition属性值设置为2(表示屏幕中心),该属性不能在运行时设置。

要将按钮定位在窗体的中央,事件过程如下:Private sub Form_Load()Command1.left= Form1.scaleWidth\2-command1.Width\2Command1.Top = Form1.ScaleHeight \ 2 – command1.Height \2End Sub其中,ScaleWidth、ScaleHeight表示窗体的相对宽度和高度。

20、VB6.0提供的大量图形文件存放在哪个目录?若你的计算机上没有安装,应怎样安装这些图形文件?答:存放在Graphics目录下。

在VB6.0的安装盘上可以找到Graphics子目录,将其复制到硬盘上的VB 目录下。

第3章:略(在书本上)1、合法的有:(1)单精度(3)单精度(4)双精度(6)整形(7)字符型(9)日期型(10)双精度(12)八进制表示(14)十六进制表示(15)逻辑型(18)单精度数2、合法变量有:(1),(2),(6),(9),(10),(11)3、算术表达式写成VB表达式(1)| x+y | + z5àabs(x+y) +z^5 (2)(a+xy)6à(1 + x * y )^ 6(3)à(10*x + sqr(3*y) ) / (x * y ) (4)à( -b+sqr(b^2-4*a*c) )/2/a(5)à 1 / (1/r1+1/r2+1/r3)(6)àsin(45*3.14/180)+ ( exp(10)+ log(10) )/ sqr( x+y+1)4、根据条件写出相应的VB表达式(1) chr( int ( Rnd * 10 +67 ) (2) int ( Rnd * 101 +100 )(3) x * y >0 (4) x%5=0 or x % 7 =0(5) (x mod 10) 10 + x /10 (6)Round(123.2389*100)/100(7) Ucase (c ) >=”A” and Ucase(c )<=”Z” or Lcase (c ) >=”a” and Lcase(c )<=”z”(8) Mid ( s, 5, 6 ) (9) x >=10 and x <20(10) ( x < z and y >z ) or ( x >z and y < z)(11) x>z and y > z5、下出下列表达式的值:(1) 123+23 mod 10 \ 7 +Asc(“A”) à188, (2)100+”100” & 100 à200100(3) Int ( 68.555*100+0.5)/100 à68.56(4)已知A$=“87654321”,求表达式Val(Left$(A$,4)+ Mid(A,4,2))的值à876554(5)DateAdd(“m”,1,#1/30/2000#) à2000-2-29(6) Len(”VB程序设计”)à6 6、略第4章:VB控制语句1、结构化程序设计的三种基本结构是什么?答:顺序结构、选择结构和循环结构。

2、指出下列赋值语句中的错误(包括运行时错误):(1)10x=sin(x)+y ‘10x是非法变量名(2)c=3+sqr(-3) ‘待求平方根的数为负数(3)c+x+y=c*y ‘赋值符左边是表达式了(4)x=sin(x)/(20 mod 2) ‘分母为零了3、Msgbox函数与InputBox函数之间有什么区别?各自获得什么值?答:两个函数共同之处都显示对话框。

区别:Inputbox函数等待用户在文本框中输入数据,获得的是输入的字符串数据;Msgbox函数等待用户按一按钮,获得的是表示按钮的整数值,以决定程序的流向。

4、要使单精度变量x,y,z分别保留1位、2位、3位小数,并在窗体显示,应使用什么函数?如何编写对应的print方法?答:使用format函数,具体如下:print Format(x,”0.0” )print Format ( y , “ 0.00 “ ) print Format ( z , “ 0.000 “ )5、 语句 if < 表达式> then …… 中的表达式可以是算术、字符、关系、逻辑表达式中的哪些?答:算术、关系、逻辑表达式 6、 指出下列语句中的错误:(1) if x ≥y then print x ‘表达式书写错误,应写成:x>=y (2) if 10<x<20 then x=x+20 ‘表达式书写错,应是:10<x and x<207、按照下列条件,写出相应的条件语句(1)字符型变量中第三个字符是“C ”时,利用Msgbox 显示“yes ”,否则显示“No ” if Mid ( c , 3, 1 ) = “C” then Msgbox “yes” else Msgbox “No” (2)利用if 语句、select case 语句两种方法计算分段函数:答:private sub command1.click() x=val( text1) if x > 20 theny = x * x + 3 * x +2 elseif x>=10 theny = sqr ( 3 * x ) – 2 elseif x>0 theny= 1 / x + Abs ( x ) end if print y end sub(3)利用if 语句和iif 函数两种方法求三个数x,y,z 中的最大值并存入变量max 中。

相关文档
最新文档