《VB程序设计试题试卷2参考答案.doc》由会员分享,可在线阅读,更多相关《VB程序设计试题试卷2参考答案.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB程序设计试题试卷2参考答案VB程序设计试题(1)参考答案一、选择题1-5BCCAD 6-10BBAAD 11-15ADACB16-20CBCBB二、判断题1、F2、T3、F4、T5、T6、T7、T8、F9、T。10、F三、填空1、scalemode2、RGB(0,255,0)3、picture1.line(100,100)-(1000,1000)4、value5、select 姓名,应发工资 from 工资 where 性别=“女”6、表类型、动态类型、快照类型7、open “D:a.txt” for input as #1open “D:a.txt” for append as #2四、
2、程序阅读题1、122、If Button=1 ThenPopupMenu Menu1233、Case 48 To 57, 13KeyAscii = 0 4、CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.Color五、编程题1、编程序计算:1!2!3!.x! (x为大于0的整数), 要求:(1) 程序运行时,单击窗体,弹出输入对话框(用inputbox()函数实现),输入x的值;(2) 计算1!2!3!.x!并将结果输出到窗体上。Private Sub form_Click() Dim x As Integer Dim i As I
3、nteger Dim s As Long, t As Long x =val(inputbox(“请输入数据”,”数据输入框”) t = 1 For i = 1 To x t = t * i s = s + t Next I Print S= & s Else i = MsgBox(注意:你输入的数据不正确, vbOKCancel, 错误提示)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text) End IfEnd Sub 2、使用MouseUp、MouseDown和MouseMove事件,编写一个在窗体上用鼠标绘图
4、的简单程序。当鼠标位于窗体上,按住鼠标按钮,在移动时才绘图,而在释放按钮时停止绘图。程序运行界面如图所示:Dim DrawNow As Boolean 初始化窗体及绘图状态Private Sub Form_Load() Form1.Caption = 简单的鼠标绘图板 Form1.ForeColor = vbRed Form1.DrawWidth = 2 DrawNow = FalseEnd Sub MouseDown事件将通知应用程序开始绘图,并设置窗体的当前坐标CurrentX与CurrentY 属性。Private Sub Form_MouseDown(Button As Integer
5、, Shift As Integer, _ X As Single, Y As Single) DrawNow = True CurrentX = X CurrentY = YEnd Sub MouseUp事件将通知应用程序终止绘图,将DrawNow 的值赋值为FalsePrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, _X As Single, Y As Single) DrawNow = FalseEnd Sub 当DrawNow为True时,MouseMove事件过程才绘制直线,否则不执行任何操作。Private
6、Sub Form_MouseMove(Button As Integer, Shift As Integer, _ X As Single, Y As Single) If DrawNow Then Line -(X, Y)End Sub 3、设计一个霓虹灯程序,设计界面如下图所示。要求:利用时钟控件模拟霓虹灯的效果。各对象的主要属性设置:Private Sub Form_Load() Dim i As Integer For i = 0 To 6 Label1(i).Visible = False 开始时隐藏标签控件数组 Label1(i).ForeColor = vbRed Next i Timer1.Enabled = True Timer1.Interval = 500End Sub Private Sub Timer1_Timer() Static index As Integer 定义静态变量index表示当前显示的标签编号 Dim i As Integer If index 7 Then Label1(index).Visible = True index = index + 1 Else For i = 0 To 6 Label1(i).Visible = False Next i index = 0 End IfEnd Sub