vb程序设计题

上传人:飞*** 文档编号:3777558 上传时间:2017-08-11 格式:DOC 页数:58 大小:1.72MB
返回 下载 相关 举报
vb程序设计题_第1页
第1页 / 共58页
vb程序设计题_第2页
第2页 / 共58页
vb程序设计题_第3页
第3页 / 共58页
vb程序设计题_第4页
第4页 / 共58页
vb程序设计题_第5页
第5页 / 共58页
点击查看更多>>
资源描述

《vb程序设计题》由会员分享,可在线阅读,更多相关《vb程序设计题(58页珍藏版)》请在金锄头文库上搜索。

1、五、设计题 (请按照题目要求进行答题 )1:编程,输入 x,求下列分段函数的值,计算结果输出到 Text 控件中。Private Sub Command1_Click()Dim x As Singlex = InputBox(输入 x, 计算分段函数)If x Then List1.AddItem Text1.TextText1.Text = End SubPrivate Sub Command2_Click() List1.RemoveItem List1.ListIndexEnd SubPrivate Sub Command3_Click() Dim I As IntegerOpen d:

2、student.dat For Output As #1For I = 0 To List1.ListCount - 1: Print #1, List1.List(I): Next IClose #1End SubPrivate Sub Command4_Click() EndEnd Sub4:设计一个简单的画板程序,可以根据选择的颜色,用鼠标的左键模拟画笔,在绘图区画线或画矩形;单击“清除”按钮后清除图片框的内容。 (提示:每次画矩形时可先清除其它图案)参考答案:Dim x1 As Single, y1 As SinglePrivate Sub Command1_Click()Common

3、Dialog1.ShowColorPicture1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Command2_Click()Picture1.ClsEnd SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Picture1.CurrentX = XPicture1.CurrentY = Yx1 = Xy1 = YEnd SubPrivate Sub Picture1_MouseMove(Butt

4、on As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenIf Option1.Value ThenPicture1.Line -(X, Y)ElsePicture1.ClsPicture1.Line (x1, y1)-(X, Y), , BEnd IfEnd IfEnd Sub五、设计题 (请按照题目要求进行答题 )第 1 题:编程,用随机函数产生 2 个 10100 的整数,输出最大值。参考答案:Private Sub Command1_Click()Dim x as integer,y as i

5、nteger,max as integerRandomizex = Int(Rnd * 91 + 10)y = Int(Rnd * 91 + 10)Max = xIf y Max Then y = MaxPrint MaxEnd Sub第 2 题:如下图,编写事件过程 Command1_Click 和 Text3_Keypress(Keyascii As Integer)事件,运行时单击“出题”按钮,自动在 Text1 和 Text2 中显示两个 2 位随机正整数;用户在 Text3 中输入运算结果,按回车后计算机对运算结果进行评判,并将评判结果在 Label2中显示(对了或错了) 。要求文本

6、框 Text3 只接受数字和回车键。(回车键的 Ascii 码为 13,数字键的 Ascii 码为 48 到 57) 参考答案:Dim x As Integer, y As IntegerPrivate Sub Command1_Click()x = Int(Rnd * 90) + 10: y = Int(Rnd * 90) + 10Text1.Text = CStr(x): Text2.Text = CStr(y)Text3.Text = Text3.SetFocusLabel2.Visible = False: Command1.Enabled = FalseEnd SubPrivate

7、Sub Form_Load()Text1.Text = : Text2.Text = : Text3.Text = Label2.Visible = FalseRandomizeEnd SubPrivate Sub Text3_KeyPress(KeyAscii As Integer)If (KeyAscii 57) And KeyAscii = y Then r = x Else r = yPicture1.Circle (x, y), r, , , , y / xEnd Sub五、设计题 1:编程,求算式 1+1/2! +1/3!+1/4!+前 10 项的和。 Private Sub Co

8、mmand1_Click()Dim I as integer, s as single,a as singlea = 1: s = 0For i = 1 To 10a = a / is = s + aNext iPrint 1+1/2!+1/3!+=; sEnd Sub2:设计一个用于输入学生信息的应用程序。界面如图所示(民族有汉族、苗族、壮族等;政治面貌有:群众、团员、党员) 。要求:(1)输入完毕后单击确定按钮,能在另一窗口显示输入的信息(2)单击取消按钮,将取消所输入的信息。Public info As StringDim s As StringPrivate Sub Command1_

9、Click()info = 学号为 + Text1.Text + ,姓名为 + Text2.Text + , 性别为 + s + ,民族为 + Combo1.Text + , 政治面貌为 + Combo2.Text+”.”Form2.ShowEnd SubPrivate Sub Command2_Click() Call Form_LoadEnd SubPrivate Sub Form_Load()Text1.Text = :Text2.Text = Option1.Value = True :Option2.Value = FalseCombo1.Text = 汉族 :Combo2.Text

10、 = 群众End SubPrivate Sub Option1_Click()s = 男End SubPrivate Sub Option2_Click()s = 女End Sub3:编程实现两个文本文件的合并,要求用驱动器、目录、文件列表框选择文件 1,单击按钮 1 后,调用通用对话框选择文件 2;单击按钮 2 后,将文件 2 的内容添加到文件 1原来内容之后,然后删除文件 2。Dim fn As String Private Sub Command1_Click()CommonDialog1.Filter = (*.txt)|*.txtCommonDialog1.ShowOpen End

11、SubPrivate Sub Command2_Click()Dim s As StringOpen fn For Append As #1 Open CommonDialog1.FileName For Input As #2Do While Not EOF(2) Line Input #2, sPrint #1, sLoopCloseKill CommonDialog1.FileName End SubPrivate Sub Dir1_Change()File1.Path = Dir1.Path End SubPrivate Sub Drive1_Change()Dir1.Path = D

12、rive1.Drive End SubPrivate Sub File1_Click()If Right(File1.Path, 1) = Then fn = File1.Path + File1.FileNameElsefn = File1.Path + + File1.FileNameEnd IfEnd SubPrivate Sub Form_Load()File1.Pattern = *.txtEnd Sub第 4 题:设计一程序,界面如图所示。程序运行后,单击“计时开始”命令按钮,开始计时,并在文本框 1 中以如图所示格式显示计时时间,单击“计时结束”命令按钮后,停止计时,并根据时间计

13、算上网费用,计算的方法如下(不足 15 分钟忽略不计,超过 15 分钟则按 1 小时计算) 。参考答案:Dim n As Integer, h As Integer, m As IntegerPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseIf m = 15 Then h = h + 1If h -1 Then List1.RemoveItem List1.ListIndexEnd Sub第 3 题:设计一个图片欣赏程序(界面如图所

14、示) ,要求程序启动后可以通过选择驱动器、文件夹,最后单击文件列表框中的图片文件时,图片载入 Picture2 中。如果图片大小超过容器 Picture1 的大小,则使用水平或垂直滚动条移动 Picture2 在 Picture1 中的位置进行浏览。Private Sub Dir1_Change() File1.Path = Dir1.Path End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1.Drive End SubPrivate Sub File1_Click()If Right(File1.Path, 1) = Thenf$ =

15、 Form1.File1.Path + Form1.File1.FileName Elsef$ = Form1.File1.Path + + Form1.File1.FileNameEnd If Picture2.Picture = LoadPicture(f$) If Picture2.Height Picture1.Height Then VScroll1.Visible = True If Picture2.Width Picture1.Width Then HScroll1.Visible = TrueHScroll1.Max = Picture2.Width - Picture1.W

16、idth VScroll1.Max = Picture2.Height - Picture1.HeightEnd SubPrivate Sub Form_Load()File1.Pattern = *.bmp;*.jpg;*.gif VScroll1.Visible = FalseHScroll1.Visible = FalseEnd SubPrivate Sub HScroll1_Change() Picture2.Left = -HScroll1.Value End SubPrivate Sub HScroll1_Scroll()Picture2.Left = -HScroll1.ValueEnd SubPriva

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 中学学案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号