【VB开源代码栏目提醒】:以下是网学会员为您推荐的VB开源代码-《Visual_Basic程序设计基础》课后习题参考答案 - 技术总结,希望本篇文章对您学习有所帮助。
第1章 Visual Basic 6.0程序设计概述 一、判断题 1√ 2√ 3× 说明同类控件如两个标签相互重叠设计时可以设置“置前”、“置后”属性。
4√ 5× 6√ 7× 8√ 9√ 10× 11√ 12√ 13× 14√ 15× 16√ 17√ 18√ 19√ 20√ 二、选择题 1. C 2. B 3D 4C 5B 6A 7D 8A 9B 10A 11C 12D 三、填空题 1对象、事件 2属性、方法、事件 3控件、屏幕Screen 4对象 5Left、Top 6属性、lt对象名gt.lt属性名gtlt表达式gt 7网格 8F orm1 9Load或Initialize或Resize或Activate自动执行的先后顺序也按此排列 10Activate、Deactivate 四、程序设计题 程序1界面设计参看图10-1、10-2以及表10-1。
表10-1 实例2各控件的主要属性设置 控件 属性属性值 属性属性值 标签控件1 NameLabel1 Captionquot我的第一个
VB程序quot 标签控件2 NameLabel2 Captionquot请输入你的姓名quot FontUnderLineTrue FontItalicTrue 命令按钮1 NameCommand1 Captionquot确定ampOquot 命令按钮2 NameCommand2 Captionquot结束ampXquot 过程设计如下 Private sub Form_Click Command2.Enabled False Een Sub Private Sub Command1_Click Label2.Visible False Label1.Caption Text1.Text quot: 欢迎使用quot Label1.Caption Text1.Visible False Command1.Enabled False: Command2.Enabled True End Sub Private Sub Command2_Click End End Sub 程序2界面设计略过程设计如下 Private Sub Command1_Click 字体变大 Form1.FontSize Form1.FontSize 3 Form1.Cls: Print quot欢迎使用
VBquot End Sub Private Sub Command2_Click 字体变小 Form1.FontSize Form1.FontSize - 3 Form1.Cls: Print quot欢迎使用VBquot End Sub Private Sub Command3_Click 字体加粗 Form1.FontBold True Form1.Cls: Print quot欢迎使用VBquot End Sub Private Sub Command4_Click 字体不加粗 Form1.FontBold False Form1.Cls: Print quot欢迎使用VBquot End Sub 运行时不得连续、过多次单击“字体变小”按钮因为当FontSize属性值小于0会产生适时错误。
程序3界面设计略过程设计如下窗体Height值的计量包括标题、边框而ScaleHeight值仅与窗体有效绘图区域的高度有关 Private Sub Form_Load Text1.Text quotVisual Basic 程序设计quot End Sub Private Sub Form_Resize Text1.Top 0: Text1.Left 0 Text1.Width Form1.ScaleWidth/2 用 Form1.ScaleWidth效果优于用Form1. Width Text1.Height Form1.ScaleHeight/2 用 Form1.ScaleHeight优于用Form1. Height Command1.Top Form1.ScaleHeight - Command1.Height Command1.Left Form1.ScaleWidth - Command1.Width End Sub 第2章 程序设计基础 一、判断题 1√ 2× 3× 4× 5√ 6× 7√ 8√ 9√ 10× 二、选择题 1B 2D 3A 4C 5C 6B 7A 8D 9. C 10A 三、填空题 1String 24 3quotaaaquot 4145 56 63 718 8False 9x Mod 10 10 x 10 1010 Int Rnd 90 11a b Mod c 12LogxSin3.141593/6 13Const PI3.1415926 14日期 15Intx1 四、程序设计题 程序1界面设计略过程设计如下 方法一、用文本框控件输入圆的半径 Private Sub Command1_Click Dim x As Single x Text1.Text Label1.Caption x x 3.141593 End Sub 方法二、用InputBox函数输入圆的半径 Private Sub Command1_Click Dim x As Single 若要求计算结果具有15位有效位数声明x为Double类型 x InputBoxquotrquotquot输入圆的半径quot Label1.Caption x x 3.141593 End Sub 程序2略。
第3章 结构化程序设计与数组 一、判断题 1√ 2× 3√ 4× 5√ 6× 7× 8√ 9× 10√ 二、选择题 1A 2D 3C 4C 5D 6B 三、填空题 1If xgty Then ty: yx: xt 2IS 3For i 0 to 9: Bi InputBoxquotBquot amp i amp quotquot: Next i 4Dim 5String 68 四、程序阅读题写出下列程序的运行结果 程序1. 0 5 程序2. 20 程序3. 2 4 7 11 16 程序4. 1 4 9 16 25 程序5. 程序6. 五、程序填空题 11q i 2s p i / q 3Next i 21r 0 2m Mod n 31i j - 1 27 - i 3Print 4110 IntRnd 90 2i 1 To 30 3aiaj 4ai Mod 2 1 六、程序设计题 程序1界面设计略过程设计如下 Private Sub Form_Click Dim x As Integer y As Integer z As Integer Dim max As Integer midd As Integer min As Integer x InputBoxquot请输入x的值quot y InputBoxquot请输入y的值quot z InputBoxquot请输入z的值quot If x gt y Then max x Else max y If z gt max Then max z If x lt y Then min x Else min y If z lt min Then min z midd x y z - max - min Print max midd min End Sub 程序2界面设计略过程设计如下 Private Sub Form_Click Dim x As Single y As Single x InputBoxquot请输入x的值quot If x gt 3 Then y x 3 ElseIf x gt 1 Then y x x ElseIf x gt 0 Then y Sqrx Else y 0 End If Print y End Sub 程序3界面设计略过程设计如下 Private Sub Form_Click Dim i As Integer j As Integer For i 1 To 9 For j 1 To 9 Print Tabj - 1 4 i j Next j Print Next i End Sub 程序4界面设计略过程设计如下 Private Sub Form_Click Dim x As Single s As Single t As Single Dim i As Integer n As Integer x InputBoxquot请输入x的值quot n InputBoxquot请输入n的值quot t x / 2: s t For i 3 To n t t x / i s s t Next i Print s End Sub 程序5界面设计略过程设计如下 Private Sub Form_Click Dim e As Single t As Single i As Integer e 2: t 1: i 1 While t gt 0.0001 i i 1: t t / i: e e t Wend Print e End Sub 程序6界面设计略过程
设计如下 Option Base 1 Private Sub Form_Click Dim n As Integer a9 9 As Integer i As Integer j As Integer On Error GoTo k 下列
代码中若出现错误转到标号为K的语句执行。
n InputBoxquot请输入n0ltnlt10quot For i 1 To n: ai 1 1: ai i 1: Next i For i 3 To n For j 2 To i - 1 ai j ai - 1 j - 1 ai - 1 j Next j i For i 1 To n Print Tab30 - 2 i For j 1 To i Print Space4 - LenTrimStrai j TrimStrai j Next j Print Next i Exit Sub k: MsgBox quot输入n值小于1或大于10数组下标超界。
quot End Sub 第4章 函数与过程 一、判断题 1× 2√ 3× 4× 5√ 6× 7× 8√ 二、填空题 1按地址传送 2b As Long 36 4按值传递 5按地址传递 6Public x As Single 7Static x As Integer 8Form2.y 三、
程序阅读题写出下列程序的运行结果 程序1. s 2 程序2. 1 程序3. 1 1 2 1 1 2 1 2 2 2 2 3 s 5 1 1 s 9 1 2 1 1 3 3 1 1 4 6 4 1 四、程序填空题 11ByeVal 2k Mod i 3k k i 4Call ppi 21a Aa Double 2n-1 3aj lt ak 31a As Double n As Integer 2t t x 3f s 五、程序设计题 程序1界面设计略过程设计如下 Private Function fsumx As Double n As Integer As Double Dim i As Integer For i 1 To n fsum fsum xi Next i fsum fsum / n End Function 程序2界面设计略过程设计如下 Private Sub ffa As Single n As Integer Dim i As Integer x As Single For i 1 To n 2 x an - i 1: an - i 1 ai: ai x Next i End Sub 程序3界面设计略过程设计如下 Private Sub findx As Single m As byte n As Byte _ xmax As Singleki As Bytekj As Byte xmax x11: ki 1: kj 1 For i 1 To m For j 1 To n If Absxi j gt Absxmax Then xmax xi j: ki i: kj j Next j i End Sub 第5章
常用控件 一、判断题 1× 2× 3× 4√ 5× 6√ 7× 8√ 9√ 10√ 11× 12× 13√ 14√ 15× 16× 17× 18√ 19√ 20× 21√ 22× 23√ 24× 25√ 二、选择题 1C 2D 3B 4B 5B 6C 7B 8B 9B 10A 11D 12C 13B 14B 15A 16D 17B 18B 19B 20A 三、填空题 1上、下、左、左 2缇、无关 3amp、ltAltgtltYgt 4Enabled 5MaxLength 6Text1.SetFocus 7MultiLine 8Visible 9Alignment 10AutoSize 11ForeColor 120或1 13True 141 15AddItem 161 17List1.Clear 18文本框、列表框 19下拉式组合框、简单组合框、下拉式
列表框 20Scroll 21Value 22Change 23定时器不起作用 24Timer 2565535 四、程序阅读题 程序1. 116 程序2. 8 程序3. 23451 程序4. 小你好 程序5. 您好 34512 小李你好 欢迎使用Visual Basic 程序6. 李子 程序7. y 6 程序8. n 1 苹果 y 14 n 3 橘子 n 5 葡萄 柚子 香蕉 五、程序填空题 11ai Midstr1 i 1 或 ai MidText1.Text i 1 2p j 3ai ap 4Command2.Enabled True 211 To 2i–1 2Command2.Enabled True 3Command2.Enabled False 31Text2.Enabled False 2p 2 3Print i 4ValText1.Text lt 2 或 ValText1.Text lt 1 5KeyAscii 13 41List1.ListCount 2List1.RemoveItem I 3i i 1 51Timer1.Enabled True 2x 3600 3x Mod 3600 60 或 x - 3600 h 60 4x x 1 61Label1.Left 2Label1.Left -Label1.Width 六、程序设计题 程序1. 界面设计略过程设计如下 Private Sub Command1_Click If Command1.Caption quot显示quot Then Print quot欢迎使用Visual Basicquot: Command1.Caption quot清除quot Else Form1.Cls: Command1.Caption quot显示quot End If End Sub Private Sub Command2_Click End End Sub Private Sub Form_Load Form1.Cls: Command1.Caption quot显示quot: Command2.Caption quot退出quot End Sub 程序2界面设计略过程设计如下 Private Sub Form_Load Text1.MaxLength 1: Text1.Text quotquot End Sub Private Sub Text1_KeyPressKeyAscii As Integer Label1.Caption CStrKeyAscii End Sub 程序3界面设计略过程设计如下 Const pwd As String quot123456quot 预设密码为123456 Private Sub Command1_Click Cls: Print quot欢迎进入quot End Sub Private Sub Form_Load Command1.Caption quot进入quot: Command1.Enabled Falsew Text1.Text quotquot: Text1.Pass
wordChar quotquot End Sub Private Sub Text1_KeyPressKeyAscii As Integer If KeyAscii 13 Then If Text1.Text pwd Then m MsgBoxquot口令正确欢迎进入quot: Command1.Enabled True Else m MsgBoxquot口令错误请重新输入quot: Text1.Text quotquot End If End If End Sub 程序4界面设计略过程设计如下 Dim num As Integer m As Integer rec As Integer Private Sub Form_Load Command1.Caption quot出题quot: Command1.Enabled True Text1.Text quotquot: Text1.Enabled False: rec 0 End Sub Private Sub Command1_Click Randomize: num IntRnd 100 1: Text1.Enabled True Label1.Caption quotquot: Command1.Enabled False End Sub Private Sub Command2_Click End End Sub Private Sub Text1_KeyPressKeyAscii As Integer If KeyAscii 13 Then m ValText1.Text: rec rec 1: Text1.SelStart 0 Text1.SelLength LenText1.Text: Text1.SetFocus If rec gt 10 Then Label1.Caption quot差重新开始quot: Call Form_Load Else If m gt num Then Label1.Caption Strm amp quot大了quot ElseIf m lt num Then Label1.Caption Strm amp quot小了quot Else If rec lt 5 Then Label1.Caption quot好猜对了。
quot Else Label1.Caption quot还行猜对了。
quot End If Call Form_Load End If End If End If End Sub 程序5界面设计如图10-3所示过程设计如下 Private Sub Form_Load Command10.Enabled False: Command11.Enabled False Command12.Enabled False: Label1.Caption quotquot End Sub Private Sub Command1_ClickIndex As Integer Select Case Index Case 0 Clipboard.Clear: Clipboard.SetText Text1.SelText Text1.SelText quotquot: Label1.Caption quot请选择要粘贴的位置quot Command10.Enabled False: Command11.Enabled False Command12.Enabled True Case 1 Clipboard.Clear: Clipboard.SetText Text1.SelText Label1.Caption quot请选择要粘贴的位置quot: Command10.Enabled False Command11.Enabled False: Command12.Enabled True Case Else Text1.SelText Clipboard.GetText: Form_Load Label1.Caption quot粘贴完成quot End Select End Sub Private Sub Text1_MouseUpButton As Integer Shift As Integer _ X As Single Y As Single Dim n As Integer n Text1.SelLength If n gt 0 Then Label1.Caption quot选择了quot amp n amp quot个字请选择下一步操作quot Command10.Enabled True: Command11.Enabled True Else Label1.Caption quotquot End If End Sub 程序6界面设计如图10-4所示过程设计如下 Private Sub Form_Load Label1.Caption quot 当前日期quot: Text1.Text Date Option10.Caption quot显示日期quot: Option11.Caption quot显示时间quot Option10.Value True: Command1.Caption quot退出quot End Sub Private Sub Option1_ClickIndex As Integer Select Case Index Case 0 Label1.Caption quot当前日期quot: Text1.Text Date Case 1 Label1.Caption quot当前时间quot: Text1.Text Time End Select End Sub Private Sub Command1_Click End End Sub 程序7过程设计如下 Private Sub Form_Load Label1.Caption quot 当前日期quot: Text1.Text Date Option10.Caption quot显示日期quot: Option11.Caption quot显示时间quot Option10.Value True: Command1.Caption quot退出quot Combo1.AddItem quot年-月-日quot: Combo1.AddItem quot月-日-年quot Combo1.AddItem quot日-月-年quot: Combo1.Text quot年-月-日quot End Sub Private Sub Combo1_Click Dim n As String Select Case Combo1.ListIndex Case 0: n quotyyyy-mm-ddquot Case 1: n quotmm-dd-yyyyquot Case 2: n quotdd-mm-yyyyquot End Select Text1.Text FormatDate n End Sub Private Sub Option1_ClickIndex As Integer Select Case Index Case 0: Label1.Caption quot当前日期quot: Text1.Text Date Case 1: Label1.Caption quot当前时间quot: Text1.Text Time End Select End Sub Private Sub Command1_Click End End Sub 程序8. 界面设计如图10-5所示过程设计如下 Private Sub Form_Load List1.AddItem quothappyquot: List1.AddItem quotapplequot List1.AddItem quotstudentquot: List1.AddItem quotcomputerquot End Sub Private Sub Command1_Click List1.AddItem Text1.Text: Text1.SetFocus Text1.SelStart 0: Text1.SelLength LenText1.Text End Sub Private Sub Command3_Click List1.Clear End Sub Private Sub Command4_Click End End Sub Private Sub Command2_Click If List1.ListIndex ltgt -1 Then List1.RemoveItem List1.ListIndex End Sub 9界面设计如图10-6所示过程设计如下 Private Sub Form_Load Option10.Caption quot八进制quot: Option11.Caption quot十六进制quot Option12.Caption quot二进制quot End Sub Private Function trank As Long n As Integer As String Dim x As Integer y As String 1 k1 As Long tran quotquot: k1 Absk Do While k1 gt 0 x k1 Mod n If x gt 10 Then y ChrAscquotAquot x - 10 Else y CStrx tran y tran k1 k1 n Loop If k lt 0 Then tran quot-quot tran End Function Private Sub Option1_ClickIndex As Integer Dim k As Long n As Integer k ValText1.Text Select Case Index Case 0 Label2.Caption quot八进制quot: n 8 Case 1 Label2.Caption quot十六进制quot: n 16 Case 2 Label2.Caption quot二进制quot: n 2 End Select Text2.Text trank n End Sub 10界面设计如图10-7所示过程设计如下 Private Sub Form_Load Label1.Left Width / 2 - Label1.Width / 2 Label1.AutoSize True HScroll1.Min 1: HScroll1.Max 1000 HScroll1.SmallChange 10: HScroll1.LargeChange 100 HScroll1.Value 500: Timer1.Interval 500 End Sub Private Sub HScroll1_Change Timer1.Interval HScroll1.Value End Sub Private Sub HScroll1_Scroll Call HScroll1_Change End Sub Private Sub Timer1_Timer Label1.FontSize Label1.FontSize 2 Label1.Left Width / 2 - Label1.Width / 2 If Label1.FontSize gt 72 Then Timer1.Enabled False End Sub 第6章 图形控件和图形方法 一、判断题 1√ 2× 3√ 4× 5√ 6× 7× 8× 9√ 10√ 二、选择题 1C 2B 3C 4A 5A 6C 7A 8C 9C 10B 11A 12B 13B 14C 15C 三、填空题 1 Circle ScaleLeft ScaleWidth / 2 ScaleTop ScaleHeight / 2 800 2LoadPicture 3AutoSize、Stretch、False、False 4选中、属性 5形状、矩形 6Picture1.PictureLodePicturequotC:WindowsCloud.bmpquot 7图片框、其他控件 8缇、Sc.