【VB开源代码栏目提醒】:网学会员--在 VB开源代码编辑为广大网友搜集整理了:VB二级考试程序完善题汇总 - 计算机理论绩等信息,祝愿广大网友取得需要的信息,参考学习。
程序填空题 说明 1. 程序填空题共64题按教科书的内容顺序排列。
2. 在每题的程序
说明后有一段程序
代码该程序段不完整。
3. 请将
代码中的“--n--”替换
必要的内容使其
完整。
n 1234。
4. 可将程序段复制到
VB代码窗口中
进行调试。
01. 窗体中有一个标签初始时标签中无
内容。
下列程序段要实现单击窗体时 窗体宽高均为5000并位于屏幕左上角同时在标签中显示“中国杭州”。
Private Sub Form_Click Form1.Left 0 Form1.Top --1-- --2-- 5000 --3-- 5000 --4-- quot中国杭州quot End Sub 02. 窗体中有一个标签初始时标签中无内容。
下列程序段要实现单击窗体时 窗体占屏幕整个上半部同时使“中国杭州”标签位于窗体的正中间。
Private Sub Form_Click Form1.Left 0 Form1.Top 0 Form1.Width --1-- Form1.Height --2-- Label1.Caption quot中国杭州quot Label1.Left --3-- Label1.Top --4-- End Sub 03. 窗体中有两个大小相同的按钮控件标题分别为“左移”和“右移”。
下列程序段要实现按钮间距和按钮与边界距相等。
单击按钮时 窗体向左或右移动200。
Private Sub Form_Load Form1.Left 4000: Form1.Top 2000 Form1.Width 5000: Form1.Height 2000 Command1.Caption quot左移quot: Command2.Caption quot右移quot Command1.Width 1000: Command2.Width Command1.Width Command1.Height 500: Command2.Height Command1.Height Command1.Top 600: Command2.Top Command1.Top Command1.Left --1-- Command2.Left --2-- End Sub Private Sub Command1_Click Form1.Left --3-- End Sub Private Sub Command2_Click Form1.Left --4-- End Sub 04. 窗体中有两个大小相同的按钮分别为“上移”和“下移”。
下列程序段要实现其间距和与边界距相等单击按钮时 窗体向上或下移动100。
Private Sub Form_Load Form1.Move 4000 2000 5000 2000 Command1.Caption quot上移quot: Command2.Caption quot下移quot Command1.Move --1-- Command2.Move --2-- End Sub Private Sub Command1_Click --3-- End Sub Private Sub Command2_Click --4-- End Sub 05. 窗体中有两个大小相同的按钮分别为“移动”和“暂停”。
下列程序段要实现单击按钮时窗体连续向右移动或暂停。
Private Sub Form_Load Command1.Caption quot移动quot: Command2.Caption quot暂停quot Timer1.Interval 100 Timer1.Enabled --1-- End Sub Private Sub Timer1_Timer Form1.Move --2-- End Sub Private Sub Command1_Click --3-- End Sub Private Sub Command2_Click --4-- End Sub 06. 下列程序段要求每一次单击窗体直径
固定为400的圆形控件自动从左下向右上沿45度方向运动。
Private Sub Form_Load Form1.Move 0 0 5800 6000 Shape1.Shape 3 Timer1.Interval 100 Timer1.Enabled False End Sub Private Sub Form_Click Shape1.Move 0 5200 --1-- Timer1.Enabled --2-- End Sub Private Sub Timer1_Timer Shape1.Left --3-- Shape1.Top --4-- End Sub 07. 下列程序段要求每一次单击窗体圆形形状控件的圆心不动直径变大30。
Dim --1-- Private Sub Form_Load Form1.Move 0 0 6000 6000 Shape1.Move 2800 2800 400 400 Shape1.Shape 3 D --2-- End Sub Private Sub Form_Click D --3-- Shape1.Move --4-- End Sub 08. 下列程序段要求窗体左上角不动第
一次单击窗体时窗体宽高各增加100第二次单击窗体时窗体宽高各增加200
第三次单击窗体时窗体宽高各增加300。
...以此类推。
Private Sub Form_Load Form1.Move 100 100 2000 1000 End Sub Private Sub Form_Click --1-- nW As Integer nW --2-- Form1.Width --3-- Form1.Height --4-- End Sub 09. 下列程序段要求每一次单击窗体圆形控件自动从左上向右下沿抛物线方向运动。
提示水平
方向为匀速运动垂直方向为匀加速平方关系运动。
Dim X As Integer Private Sub Form_Load Form1.Move 0 0 6000 6000 Shape1.Shape 3 Shape1.Move 0 0 100 100 Timer1.Interval 100 Timer1.Enabled False End Sub Private Sub Form_Click --1-- Timer1.Enabled --2-- End Sub Private Sub Timer1_Timer X X 1 Shape1.Left --3-- Shape1.Top --4-- End Sub 10. 下列程序段要求圆形控件自动按椭圆轨道长短轴比为2:1运动。
提示椭圆轨道公式为 X R COSQY R SINQ/2。
Dim --1-- Private Sub Form_Load Form1.Move 0 0 6000 6000 Shape1.Shape 3 Shape1.Move 0 0 100 100 Timer1.Interval 100 Timer1.Enabled True R 2000 X0 Form1.Width / 2 Y0 Form1.Height / 2 End Sub Private Sub Timer1_Timer --2-- Q Q 0.1 Shape1.Left --3-- Shape1.Top --4-- End Sub 11. 已知函数fx的值分三个区间当x lt 0时fx 0当0 lt x lt 1时fx 1 - x2 当x gt1时 fx x2 1。
下列程序段通过InputBox函数输入x值再计算出函数值fx并在标签Label1中显示。
Private Sub Form_Click Dim x As Single x InputBoxquotxquot If --1-- Then Label1 0 ElseIf --2-- Then Label1 --3-- --4-- Label1 x x 1 End If End Sub 12. 下列程序段为密码检查单击“登录”按钮要求用户通过InputBox函数输入密码12345。
若密码正确在标签Label1显示“欢迎进入VisualBasic”同时“登录”按钮消失。
若密码不正确则无反应。
Private Sub Form_Load Command1.Caption quot登录quot End Sub Private Sub Command1_Click --1-- Password1 InputBoxquot请输入密码quot If --2--Then Label1 quot欢迎进入VisualBasicquot --3-- --4-- End Sub 13. 下列程序段为密码设臵要求用户通过InputBox函数输入两次密码。
若两次输入一致在标签Label1显示quot密码已经修改quot。
若两次输入不一致则在标签Label1显示quot两次输入不一致请重新设臵quot。
Private Sub Form_Load Command1.Caption quot密码设臵quot End Sub Private Sub Command1_Click --1-- Password1 InputBoxquot请输入密码quot Password2 InputBoxquot请再输入一次密码quot If --2-- Then Label1 quot密码已经
修改。
quot --3-- Label1 quot两次输入不一致请重新设臵。
quot --4-- End Sub 14. 窗体中有一个标签下列程序段要实现quot中国杭州quot标签自动向左移动当标签完全移出窗体左端时自动再从右端移入。
Private Sub Form_Load Form1.Move 2000 2000 6000 3000 Label1.Caption quot
中国杭州quot Label1.FontSize 24 Label1.AutoSize True Label1.Move 4000 1000 Timer1.Interval 100 Timer1.Enabled True End Sub Private Sub Timer1_Timer If --1-- Then Label1.Move --2-- Else Label1.Move --3-- --4-- End Sub 15. 下列程序段要求圆形
控件在窗体中横向往复运动。
当圆形控件碰到窗体左右边界时自动反向X -X。
Dim --1-- Private Sub Form_Load Form1.Move 2000 2000 6000 3000 Shape1.Shape 3 Shape1.Move 4000 1000 400 400 Timer1.Interval 100: Timer1.Enabled True --2-- 100 End Sub Private Sub Timer1_Timer If --3-- Then X -X Shape1.Move --4-- End Sub 16. 下列
程序段要求圆形控件在窗体中自由运动到达边界时自动反向 dX -dXdY -dY。
Dim D dX dY Private Sub Form_Load Form1.Move 2000
2000 8000 5000 Shape1.Shape 3 Timer1.Interval 100 Timer1.Enabled True D 500 dX 200 dY 200 Shape1.Move 0 0 --1-- End Sub Private Sub Timer1_Timer If --2-- Then dX -dX If --3-- Then dY -dY Shape1.Move --4-- End Sub 17. 窗体中有一个
按钮控件初始为quot
移动quot。
下列程序段要实现单击按钮quot移动quot时窗体连续向右移动按钮改为quot暂停quot。
再单击按钮quot暂停quot时窗体暂停移动按钮改为quot移动quot。
周而复始...。
Private Sub Form_Load Form1.Move 100 2000 5000 2000 Command1.Caption quot移动quot Command1.Move 2000 800 1000 500 Timer1.Interval 100 Timer1.Enabled False End Sub Private Sub Timer1_Timer Form1.Move Form1.Left 100 End Sub Private Sub Command1_Click If Command1.Caption quot移动quot Then Command1.Caption --1-- Timer1.Enabled --2-- Else Command1.Caption --3-- Timer1.Enabled --4-- End If End Sub 18. 下列程序段判断从InputBox函数输入的整数所在的区间 并在标签Label1中输出判断结果。
Private Sub Form_Load Form1.Move 0 0 6000 2000 Command1.Caption quot输入整数quot Command1.Move 2000 800 2000 500 Label1.Move 800 200 Label1.AutoSize True: Label1.FontSize 16 End SubPrivate Sub Command1_Click Dim nX As Integer nX InputBoxquot输入要
判断的整数quot Select Case nX Case --1-- Label1 quot值为0 quot Case --2-- Label1 quot值在1和10之间包括1和10quot Case --3-- Label1 quot值大于10quot Case --4-- Label1 quot值小于0quot End Select End Sub 19. 下列程序段先通过InputBox
函数输入一个学生成绩百分制 然后转化为五级记分优良中及格不及格。
并用MsgBox函数
显示例如quot该
生成绩95
等级优quot。
Private Sub Form_Click Dim --1-- sFs InputBoxquot请输入百分制
学生成绩quot quot输入成绩quot Select Case --2-- Case 89.5 To 100 sDj quot优quot Case 79.5 To 89.4 sDj quot良quot Case 69.5 To 79.4 sDj quot中quot Case 59.5 To 69.4 sDj quot及格quot Case 0 To 59.4 sDj quot不及格quot Case --3-- sDj quot无效quot End Select Temp MsgBox --4-- 0 quot五级记分quot End Sub 20. 下列程序段先通过InputBox函数输入一个个人收入然后按以下规定给出纳税值1收入在800元以内免征2收入在800--1200元内超过800元部分纳税203
收入超过1200元部分纳税304收入达到5000元或超过时将税金30改为40 Private Sub Form_Click Dim gM As Single gNs As Single Dim nX As Integer gM ValInputBoxquot请输入个人收入元quot Select Case --1-- Case Is lt 800 gNs 0 nX MsgBoxquot免税quot 0 quot纳税情况quot Case --2-- gNs gM - 800 0.2 nX MsgBoxquot应纳税quot StrgNs quot元quot 0 quot纳税情况quot Case --3-- gNs 400 0.2 gM - 1200 0.3 nX MsgBoxquot应纳税quot StrgNs quot元quot 0 quot纳税情况quot Case Is gt 5000 gNs --4-- nX MsgBoxquot应纳税quot StrgNs quot元quot 0 quot纳税情况quot End Select End Sub 21. 下列程序段中单击按钮在标签中依次显示quot中国quotquot浙江quotquot杭州quotquot西湖quot。
Private Sub Form_Load Form1.Move 0 0 5000 2000 Command1.Move 2000 1000 Label1.Move 2000 300 Label1.AutoSize True: Label1.FontSize 24 End Sub Private Sub Command1_Click --1-- Select Case Flag Case 0 Label1 quot中国quot Flag --2-- Case 1 Label1 quot浙江quot Flag --3-- Case 2 Label1 quot杭州quot Flag --4-- Case Else Label1 quot西湖quot Flag 0 End Select End Sub 22. 下列程序段实现在标签中自动依次显示quot中国quotquot
浙江quotquot杭州quotquot西湖quot。
Private Sub Form_Load Label1.AutoSize True: Label1.FontSize 24 Label1 --1-- Timer1.Interval 1000 Timer1.Enabled True End Sub Private Sub Timer1_Timer Select Case Label1 Case --2-- Label1 quot中国quot Case --3-- Label1 quot浙江quot Case --4-- Label1 quot杭州quot Case Else Label1 quot西湖quot End Select End Sub 23. 下列程序段是计算123...100单击窗体打印出结果。
Private Sub Form_Click Dim T As Integer S As Integer T --1-- S 0 Do While --2-- T T 1 --3-- --4-- Form1.Print quotS quot S End Sub 24. 下列程序段为密码
检查单击quot登录quot按钮要求用户通过InputBox函数输入密码12345。
若密码正确在标签Label1显示quot欢迎进入VisualBasicquot同时quot登录quot按钮消失。
若密码不
正确要求
用户再次输入密码。
若三次输错则退出程序。
Private Sub Form_Load Command1.Caption quot登录quot End Sub Private Sub Command1_Click Dim I As Integer Password As String For I 0 To 2 Pass
word InputBoxquot请输入密码quot If Password quot12345quot Then --1-- Next If --2-- Then --3-- --4-- Label1 quot欢迎
进入Visual
Basicquot Command1.Visible False End Sub 25. 下列程序段为密码检查单击quot登录quot按钮要求用户通过InputBox函数输入密码12345。
若密码正确在标签Label1显示quot欢迎进入VisualBasicquot同时quot登录quot按钮消失。
若密码不正确要求用户再次输入密码。
若三次输错则退出程序。
Private Sub Form_Load Command1.Caption quot登录quot End Sub Private Sub Command1_Click Dim I As Integer Password As String Do Password InputBoxquot请输入密码quot If Password quot12345quot Then --1-- If I gt 2
Then --2-- --3-- --4-- Label1 quot欢迎进入VisualBasicquot Command1.Visible False End Sub 26. 下列程序段有5个大小一样直径D的圆形控件在窗体中各自随机地
自由运动。
到达边界时自动反向dXI-dXIdYI-dYII0-4。
Dim I D dX4 dY4 Private Sub Form_Load Randomize D 500 For I 0 To 4 ShapeI.FillColor QBColor10 I dXI 200 -1 IntRnd 2 dYI 200 -1 IntRnd 2 ShapeI.Move --1-- Next I Timer1.Interval 100 Timer1.Enabled True End Sub Private Sub Timer1_Timer For I 0 To 4 ShapeI.Move --2-- If --3-- Then dXI -dXI If --4-- Then dYI -dYI Next I End Sub 27. 下列程序段有5个
不同大小的同心圆形控件在窗体中缩小DIDI-200I0-4。
当缩小到DIlt200时又DI5000
开始缩小。
Dim D4 As
Integer I As
Integer Private Sub Form_Load Timer1.Interval 100 For I 0 To 4 ShapeI.BorderColor QBColor10 I DI 1000 I 1 ShapeI.Move Form1.Width - DI / 2 Form1.Height - DI / 2 DI DI Next End Sub Private Sub Timer1_Timer For I --1-- If DI lt 200 Then --2-- DI --3-- ShapeI.Move --4-- Next End Sub 28. 下列程序段是计算1234...20并打印出来。
Private Sub Form_Click Dim S As Single F As Single J As Integer S --1-- F --2-- For J 1 To 20 F --3-- S --4-- Next J Form1.Print quotS quot S End Sub 29. 下列程序段是计算133233...340并打印出来。
Private Sub Form_Click Dim S As Single N As Integer S 1 N --1-- Do If --2-- Then Exit Do Else S --3-- N N 1 End If --4-- Form1.Print quotSquot S End Sub 30. 如果
一个正整数从高位到低位上的数字递增即百位上的数字不大于十位上的数字十位上的数字不大于个位上的数字则称为升序数如234572344889等都是升序数。
下列程序段是用来判断输入的数
是否为升序数并
打印出来。
Private Sub Command1_Click Dim n As Long x As String i As Integer n InputBoxquot请输入一个正整数quot x --1-- For i 1 To --2-- If Midx i 1 gt Midx i 1 1 Then --3-- Next i If --4-- Then Print n quot是升序数quot Else Print n quot不是升序数quot End If End Sub 31. 下列程序段用于计算1-1/21/4-1/8 ... 共20项的和并打印出来。
Private Sub Form_Click Dim I As Integer Dim K As --1-- Dim S As --2-- S 0 For I 1 To 20 K 1 / 2 I - 1 If I Mod 2 0 Then --3-- S S K Next I Form1.Print quotSquot --4-- End Sub 32. 下列程序段
用于计算1-1/21/3-...1/99-1/100的值并打印出来。
Private Sub Form_Click Dim I As Integer Dim K As --1-- Dim T As --2-- T 0 For I 1 To --3-- K 1 / I T T K K --4-- T T K Next I Form1.Print quottquot T End Sub 33. 下列程序段是计算S1/791/911...1/NN2并打印出来。
其中N通过InputBox函数输入。
Private Sub Form_Click Dim N As Integer P As Integer Dim S As --1-- P 7 Do N ValInputBoxquotINPUT Nquot If N gt P And N Mod 2 ltgt 0 Then Exit Do Loop --3-- Do While --4-- S S 1 / P P 2 P P 2 Loop Form1.Print quotSquot S End Sub 34. 一个数如果等于其每一个数字立方之和则称此数为阿姆斯特朗数Armstrong number。
如407就是一个阿姆斯特朗数因为407430373。
下列程序段为算出1-2000
之间所有的阿姆斯特朗数。
Private Sub Form_Click Dim I As Integer A As Integer B As Integer Dim C As Integer D As Integer For I 1 To 2000 A IntI / 1000 B --1-- C --2-- D --3-- If --4-- Then Print I quot为阿姆斯特郎数quot End If Next I End Sub 35. 下列程序段先通过InputBox函数输入两个正整数M和N。
然后求出M和N的最大公约数并显示在窗体中。
提示取M和N中较小的一个数
作为判断最大公约数的起点nStart。
Private Sub Form_Click Dim M As Integer N As Integer Dim nStart As Integer I As Integer M ValInputBoxquot请输入m的值quot N ValInputBoxquot请输入n的值quot nStart M If --1-- Then nStart N End If For I --2-- If --3-- Then Exit For End If Next I Print --4-- quot的最大公约数是quot I End Sub 36. 下.