《2022年VB上机练习题.docx》由会员分享,可在线阅读,更多相关《2022年VB上机练习题.docx(42页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -VB 上机练习题 二 18、新建一个工程,完成应用程序的设计,详细要求如下:1.依据图 11 所示在窗体上放置按钮和控件;list1中,并且在list2中删除该2.在两个列表框控件的list中输入一些内容;3.单击“” 按钮时,把list2中选中的一项放到项;4.单击“” 按钮时,把list1中选中的一项放到list2中,并且在list1中删除该项;6.单击“” 按钮时,把list1中全部的项放到list2中,并且清空list1;7.单击“ 终止” 按钮时,退出应用程序;图 15 Private Sub Co
2、mmand1_Click If List1.ListIndex = -1 Then MsgBox 请挑选一项再按键! Else List2.AddItem List1.Text List1.RemoveItem List1.ListIndex End If End Sub Private Sub Command2_Click Do Until List1.ListCount = 0 List2.AddItem List1.List0 List1.RemoveItem 0 Loop End Sub Private Sub Command3_Click Do Until List2.ListCou
3、nt = 0 1 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 1 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - - List1.AddItem List2.List0 List2.RemoveItem 0 Loop End Sub Private Sub Command4_Click If List2.ListIndex = -1 Then MsgBox 请挑选一项再按键! Else List1.AddItem List2.Text List2.Remov
4、eItem List2.ListIndex End If End Sub Private Sub Command5_Click End End Sub 2 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 2 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -19、新建一个工程,完成“ 收款运算” 程序的设计,详细要求如下:1.依据图 16 所示在窗体上放置控件;单击“ 运算”,2.窗体上有三个文本框,上面两个分别用于输入商品单价和商品数量,将应对款显示在最下面一
5、个文本框中;3. 最下面一个文本框(应对款)不能直接输入;4. 单击“ 清除” 按钮,三个文本框内容被清空,同时第一个文本框获得焦点;图 16 Private Sub Command1_Click Text1.Text = Text2.Text = Text3.Text = Text1.SetFocus End Sub Private Sub Command2_Click Dim x, y, sum. x = ValText1.Text y = ValText2.Text sum = x * y Text3.Text = CStrsum End Sub Private Sub Form_Loa
6、d Text3.Enabled = False End Sub 3 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 3 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -20、新建一个工程,完成应用程序的设计,详细要求如下:1. 如图 17 所示,在窗体上放置一个水平滚动条、一个标签框和一个命令按钮;2. 滚动条状态发生转变时,标签上的文字可以左右移动,文字移动范畴等于滚动条的范畴;图 17 Private Sub Command1_Click End End
7、Sub Private Sub Form_Load HScroll1.Max = 6000 HScroll1.Min = 0 HScroll1.LargeChange = 40 HScroll1.SmallChange = 10 End Sub Private Sub HScroll1_Change Label1.Left = HScroll1.Value End Sub 4 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 4 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - -
8、 - - - -21、新建一个工程,完成应用程序的设计,详细要求如下:1. 依据图 18 所示在窗体上放置控件;2. 4 个单项按钮分别用于显示星期、年份、月份和日期;3. 选中某个单项按钮时,在文本框中显示当天对应的日期信息;4. 单击“ 终止” 命令该按钮时,退出应用程序;图 18 Private Sub Option1_Click If Option1.Value = True Then Text1.Text = WeekdayNameWeekdayNow End If End Sub Private Sub Option2_Click If Option2.Value = True T
9、hen Text1.Text = YearNow End If End Sub Private Sub Option3_Click If Option3.Value = True Then Text1.Text = MonthNow End If End Sub Private Sub Option4_Click If Option4.Value = True Then Text1.Text = DayNow End If End Sub 5 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 5 页,共 21 页 - - - - - - - - - 名
10、师归纳总结 精品学习资料 - - - - - - - - - - - - - - -22、新建一个工程,完成“ 运算平均成果” 应用程序的设计,详细要求如下:1.依据图 19 所示在窗体上放置控件;即在 高数 、 英语 和 运算机 文本框2.在输入或修改单科成果的同时运算平均分,内容发生转变时,就要立刻重新运算平均分,并将运算结果在“ 平均成果” 文本框 中显示;3.“ 平均成果” 文本框不答应编辑,即不能手工修改;4. 各单科成果文本框中只能输入数字,不能输入字母或汉字,否就给出错误提示;图 19 Dim a, b, c, sum. Private Sub Form_Load Text4.E
11、nabled = False End Sub Private Sub Text1_Change a = ValText1.Text b = ValText2.Text c = ValText3.Text sum = a + b + c Text4.Text = CStrsum End Sub Private Sub Text2_Change a = ValText1.Text b = ValText2.Text c = ValText3.Text sum = a + b + c Text4.Text = CStrsum End Sub Private Sub Text3_Change a =
12、ValText1.Text b = ValText2.Text c = ValText3.Text sum = a + b + c Text4.Text = CStrsum End Sub 6 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 6 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -Private Sub Text1_KeyPressKeyAscii As Integer If KeyAscii 57 Then MsgBox 请输入数字! End S
13、ub Private Sub Text2_KeyPressKeyAscii As Integer If KeyAscii 57 Then MsgBox 请输入数字! End Sub Private Sub Text3_KeyPressKeyAscii As Integer If KeyAscii 57 Then MsgBox 请输入数字! End Sub 23、 设计一个 秒表模拟程序,按下“ 开头” 按钮,屏幕显示当前时间;按下“ 终止” 按钮,屏幕显示终止时间和连续时间;按下“ 退出” 按钮,终止程序;图 20 Dim a As Date, b As Date Private Sub Co
14、mmand1_Click a = Now Text1.Text = FormatNow, HH:MM:SS End Sub Private Sub Command2_Click b = Now Text2.Text = FormatNow, HH:MM:SS Text3.Text = Formata - b, HH:MM:SS End Sub Private Sub Command3_Click End End Sub 7 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 7 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习
15、资料 - - - - - - - - - - - - - - -24、设计一个用来掌握文本框中信息格式的程序,界面如图 21 所示:图 21 Private Sub Check1_ClickIndex As Integer If Check10.Value = 1 Then Text1.FontBold = True Else Text1.FontBold = False End If If Check11.Value = 1 Then Text1.FontItalic = True Else Text1.FontItalic = False End If If Check12.Value =
16、 1 Then Text1.FontUnderline = True Else Text1.FontUnderline = False End If End Sub Private Sub Option1_ClickIndex As Integer Select Case Index Case 0 Text1.FontSize = 14 Case 1 Text1.FontSize = 12 Case Else Text1.FontSize = 8 End Select End Sub Private Sub Option2_ClickIndex As Integer Select Case I
17、ndex 8 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 8 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - - Case 0 Text1.ForeColor = vbRed Case 1 Text1.ForeColor = vbGreen Case Else Text1.ForeColor = vbBlue End Select End Sub 9 细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 9 页,共 21
18、 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -25、新建一个工程,完成“ 字幕闪耀” 程序的设计,程序界面如图 1. 窗体的标题为“ 字幕闪耀” ,固定边框;22 所示,详细要求如下:2. 在属性窗口中将标签(Label1 )的标题设为 “ 祝您考试胜利”,字体设置为 “ 宋体”、“ 粗体” 、“ 二号” ,文字颜色为“ 红色” ,格式设置为水平居中对齐;3. 单击“ 开头” 按钮(Command1),标签文字在定时器掌握下自动交替以红蓝两种颜色显示,同时“ 开头” 按钮变为“ 停止” 按钮;4. 单击“ 停止”
19、 按钮,标签文字停止闪耀,同时“ 停止” 按钮变为“ 开头” 按钮;5.定时器( Timer1 )的时间间隔为0.3 秒;图 22 Private Sub Command1_Click If Command1.Caption = 开头 Then Command1.Caption = 停止 Else Command1.Caption = 开头 End If If Command1.Caption = If Command1.Caption = End Sub 开头 Then Timer1.Enabled = False 停止 Then Timer1.Enabled = True Private
20、Sub Form_Load Label1.ForeColor = vbRed Label1.Left = Form1.Width - Label1.Width / 2 Command1.Caption = 开头 Timer1.Enabled = False Timer1.Interval = 300 End Sub Private Sub Timer1_Timer If Label1.ForeColor = vbRed Then Label1.ForeColor = vbBlue Else: Label1.ForeColor = vbRed End If End Sub 10 细心整理归纳 精
21、选学习资料 - - - - - - - - - - - - - - - 第 10 页,共 21 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -26、新建一个工程,完成“ 字幕滚动” 程序的设计,程序界面如图1.窗体的标题为“ 字幕滚动”,固定边框;23 所示,详细要求如下:2. 在属性窗口中将标签(Label1 )的标题设为 “ 祝您考试胜利”,字体设置为 “ 宋体” 、“ 粗体” 、“ 二号” ,文字颜色为“ 红色”;3. 单击“ 开头” 按钮,标签文字在定时器掌握下自动地从左向右移动,移动速度为每个时间间隔右移
22、 100 缇;当标签移动到窗体外时,再从窗体的左边进入,同时“ 开始” 按钮变为“ 停止” 按钮;4. 单击“ 停止” 按钮,标签“ 祝您考试胜利” 文字停止滚动,同时“ 停止” 按钮变为“ 开头” 按钮;5.定时器( Timer1 )的时间间隔为0.1 秒;图 23 Private Sub Command1_Click If Command1.Caption = 开头 Then Command1.Caption = 停止 Else: Command1.Caption = 开头 End If If Command1.Caption = If Command1.Caption = End Sub
23、 开头 Then Timer1.Enabled = False 停止 Then Timer1.Enabled = True Private Sub Form_Load Label1.ForeColor = vbRed Command1.Caption = 开头 Label1.Left = Form1.Width - Label1.Width / 2 Timer1.Enabled = False Timer1.Interval = 100 End Sub Private Sub Timer1_Timer If Label1.Left 1000 x = x * 1.35 Option10.Value = True Case 800 To 1000 x = x * 1.25 Option11.Value = True Case Else x = x * 1.15 Option12.Value = True End Select Text2.Text
限制150内