Vb上机实验答案

合集下载

国家二级VB机试(上机操作)模拟试卷400(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷400(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷400(题后含答案及解析) 全部题型 2. 基本操作题 3. 简单应用题 4. 综合应用题基本操作题1.请根据以下各小题的要求设计Visua,Basic应用程序(包括界面和代码)。

(1)在名称为Form1标题为“选课”的窗体上画一个复选框数组,名称为CH1,共有四个复选框,按顺序其标题分别是“数学”、“语文”、“外语”、“计算机”,其中“语文”、“计算机”复选框处于选中状态,运行时的窗体如图3—147所示。

请画控件并设置相应属性。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjt1.vbp,窗体文件名为sjt1.frm。

(2)在名称为Form1的窗体上画一个名称为HS1的水平滚动条,其刻度值范围为1~100;画一个命令按钮,名称为C1,标题为“移动滚动框”。

请编写适当的事件过程,使得在运行时,每单击命令按钮一次(假定单击次数少于10次),滚动框向右移动10个刻度。

运行时的窗体如图3—148所示。

要求程序中不得使用变量,事件过程中只能写一条语句。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjt2.vbp,窗体文件名为sjt2.frm。

正确答案:(1)【操作步骤】步骤1:新建一个“标准EXE”工程。

步骤2:在窗体Form1中加入一个复选框,并用“复制”和“粘贴”的方法,生成包含四个元素的复选框数组。

步骤3:分别设置窗体和复选框数组中各元素的相关属性。

步骤4:按要求将文件保存至考生文件夹中。

(2)【操作步骤】步骤1:新建一个“标准EXE”工程,按要求画出控件并设置相应属性。

步骤2:在代码编辑窗口,编写命令按钮的Click事件过程。

参考代码:Private Sub C1_Click( )HS1.Value=HS1.Value+10End Sub 步骤3:按要求将文件保存至考生文件夹中。

简单应用题2.(1)在名称为Form1的窗体上画一个名称为Text1的文本框,再建立一个名称为Format的弹出式菜单,含三个菜单项,标题分别为“加粗”、“斜体”、“下划线”,名称分别为M1、M2、M3。

Vb上机实验答案

Vb上机实验答案

第一题1.制作如图所示窗体界面。

(用真实的姓名、班级及学号)2.使时间每隔1秒刷新一次3.单击“最大值”命令按钮时,算出通过键盘输入的5个数的最大值4.在列表框中输入20、22、24、26、28Private Sub Command1_Click()Dim a(1 To 5) As IntegerFor i = 1 To 5a(i) = InputBox("please input a number")Next immax = a(1)For i = 1 To 5If a(i) > mmax Thenmmax = a(i)End IfNext iMsgBox mmaxEnd SubPrivate Sub Timer1_Timer()Label2.Caption = TimeEnd Sub第二题1.两个文本框里输入两个数字从而确定一个范围。

2.单击“计算”按钮求出这个范围中能被3或5整除的数的平方和,结果显示在label3中。

bel3的背景色每隔1.5秒蓝红交替。

Private Sub Command1_Click()Dim a As IntegerDim b As Integera = Text1.Textb = Text2.Texts = 0For i = a To bIf a Mod 3 = 0 Or b Mod 5 = 0 ThenLabel3.Caption = Label3.Caption & i & ","s = s + i * iEnd IfNext iLabel3.Caption = sEnd SubPrivate Sub Timer1_Timer()If Label3.BackColor = vbRed ThenLabel3.BackColor = vbBlueElseLabel3.BackColor = vbRedEnd IfEnd Sub第三题1、单击按钮,在文本框中显示1到终值的所有整数的平方和2、单击生成列表按钮,在列表框中显示1到终值之间的所有整数Private Sub Command1_Click()Dim a As Integera = Text1.Texts = oFor i = 1 To as = s + i * iNext iText2.Text = sEnd SubPrivate Sub Command2_Click()Dim a As Integera = Text1.TextFor i = 1 To aList1.AddItem iNext iEnd Sub第四题1、“大家好”的背景颜色红蓝黄交替,单击“停止”按钮时停止颜色变化2、在文本框中写入任意数字,单击“生成列表”按钮,将1到文本框中输入数字之间所有能被3整除得数在列表框中显示Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Command3_Click()Dim a As Integera = Text1.TextFor i = 1 To aIf i Mod 3 = 0 ThenList1.AddItem iEnd IfNext iEnd SubPrivate Sub Timer1_Timer()If Label1.ForeColor = vbRed ThenLabel1.ForeColor = vbBlueElseIf Label1.ForeColor = vbBlue ThenLabel1.ForeColor = vbY ellowElse: Label1.ForeColor = vbRedEnd IfEnd Sub第五题1、“大家好”电子滚动平当单击按钮“开始”时从左向右滚动,当滚动到屏幕最右端的时候,从新回到最左端开始滚动;单击“停止”按钮时停止滚动2、在文本框中写入任意内容,单击“添加”按钮可以将文本框中的内容加入到列表框中Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Command3_Click()List1.AddItem Text1.TextEnd SubPrivate Sub Timer1_Timer()Label1.Left = Label1.Left + 100If Label1.Left > Form1.Width - Label1.Width ThenLabel1.Left = 0End IfEnd Sub第六题1、标签中写入“大家好”,每秒钟“大家好”和“哈哈”交替出现(即,第一秒出现“大家好”。

VB程序设计教程实验指导与习题解答上机答案

VB程序设计教程实验指导与习题解答上机答案

自测1程序代码Private Sub Command1_Click()Label1.FontSize = Label1.FontSize + 3 End SubPrivate Sub Command2_Click()Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click()Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click()Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Label1 = "visual basic"Text1 = "程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 = "程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5) End SubPrivate Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub—初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:—自测题4程序代码Private Sub Command1_Click()Form1.Caption = "VB学习"Print "简单的VB程序设计"End SubPrivate Sub Command2_Click()Cls—End SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击显示之后的窗口:—单击清除之后的窗口:单击退出之后的窗口:自测题5程序代码Private Sub Command1_Click()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text) End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习 1Private Sub Command1_Click() Dim a$a = Text1.TextLabel1.Caption = Left(a, 2) End SubPrivate Sub Command2_Click() a = Text1.TextLabel2.Caption = Right(a, 2) End SubPrivate Sub Command3_Click()—Text1.Text = Label1.Caption & Label2.CaptionEnd Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习 2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l% a = 7349e = a Mod 10 '个位d = (a \ 10) Mod 10 '十位c = (a \ 100) Mod 10 '百位b = a \ 1000 '千位i = (e + 7) Mod 10 '个位h = (d + 7) Mod 10 '十位g = (c + 7) Mod 10 '百位f = (b + 7) Mod 10 '千位j = ii = f '交换后的个位f = j '交换后的千位k = hh = g '交换后的十位g = k '交换后的百位l = f * 1000 + g * 100 + h * 10 + iText1.Visible = False—Print "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; lEnd Sub初始界面单击窗体运行后的界面自测练习 1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 8))b = Val(InputBox("输入第一个数", "输入一个数", 7))c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + 0.5) / 100MsgBox "x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10) & "x/y=" & f, , "输出的结果"End Sub自测练习 2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数的值"))b = Val(InputBox("输入第二个数的值"))c = Val(InputBox("输入第三个数的值"))d = Val(InputBox("输入第四个数的值"))e = a + b + c + df = e / 4—Print "和="; ePrint "平均值="; fEnd Sub自测练习 3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox("输入总头数")) f = Val(InputBox("输入总脚数")) x = (4 * h - f) / 2y = (f - 2 * h) / 2Print "笼中鸡的头数为"; x; "只" Print "笼中兔的头数为"; y; "只"End Sub自测练习1:Private Sub Form_Click() Dim a%, b%, c%a = Val(InputBox("请输入第一条边", "边长"))b = Val(InputBox("请输入第二条边", "边长"))c = Val(InputBox("请输入第三条边", "边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint "直角"ElseIf a = b And b = c ThenPrint "等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint "等腰三角形"ElsePrint "一般三角形"End IfElsePrint "不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:—等边三角形运行结果如下:等腰三角形:一般三角形自测练习2:—Private Sub Form_Click()Dim a%, b!a = Val(InputBox("请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Thenb = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:—运行结果:自测练习 3Private Sub Command1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a > 0Case a < 20MsgBox "行李费为0.2元/kg", , "行李费"Case a >= 20 And a < 50MsgBox "行李费为0.3元/kg", , "行李费"Case a >= 50 And a < 100MsgBox "行李费为0.4元/kg", , "行李费"Case Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox "行李费为" & b & "元", , "行李费"—End SelectEnd Sub初始窗口:输入10:输入25:输入55:—输入120:自测练习 1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integer—a(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 11 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2)Print a(i);Next i初始界面:运行结果界面:自测练习 2Option Base 1Private Sub Form_Load() Form1.Width = 10000 Form1.Height = 5000 End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 10) + 1Picture1.Print a(i, j);Next jPicture1.PrintNext iPicture3.Print "对角线的元素如下" For i = 1 To 4Picture3.Print a(i, i);Next iPicture3.PrintFor i = 1 To 4Picture3.Print a(i, 5 - i);Next iFor i = 1 To 4t = a(1, i)a(1, i) = a(4, i)—a(4, i) = tNext iFor i = 1 To 4t = a(i, 2)a(i, 2) = a(i, 3)a(i, 3) = tNext iFor i = 1 To 4For j = 1 To 4Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub运行初始界面:运—运行结果界面:自测练习 1Sub itostr(a As Integer)Dim b%, c$—a = Val(Text1.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = cEnd SubPrivate Sub Command1_Click()Dim a As Integera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function area(n) As Double Dim c#, d#, e#, s#n = Val(Text2.Text)c = (1 - 0) / nWhile e <= 1d = I * c:e = (I + 1) * cs = s + (Sin(d) + Sin(e)) * c / 2I = I + 1Wendarea = sEnd Function—Private Sub Command1_Click()Dim s As DoubleCall area(n)Text1.Text = area(n)End Sub运行初始界面:运行结果:自测练习 3Private Sub Form_click()—n = Val(InputBox("请输入n的值"))x = Val(InputBox("请输入x的值"))Print "e的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integera = 1:b = 1:c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Function运行初始界面:输入数据:—运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = t— End IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox("输入y的值", "输入数据"))Insertfun a%(), YPrint—For i = 1 To 6Print a(i); " ";Next iEnd Sub运行初始界面:插入数据:运行结果:41011060蓝志鹏资源1102 实验8自测练习1:Private Sub Command1_Click()If Ch1.Value = 1 ThenText1.Text = "报名参加羽毛球比赛"End IfIf Ch2.Value = 1 ThenText1.Text = "报名参加乒乓球比赛"End IfIf Ch1.Value = 1 And Ch2.Value = 1 ThenText1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load() Label1.Alignment = 2Label1.FontSize = 24Label1.FontName = "黑体" Label1.ForeColor = &HFF&—End SubPrivate Sub Option1_Click()Label1.Caption = "我是学生"End SubPrivate Sub Option2_Click()Label1.Caption = "我是教师"End SubPrivate Sub Option3_Click()Label1.Caption = "我是工人"End SubPrivate Sub Option4_Click()Label1.Caption = "我是农民"End Sub运行初始界面:—运行结果:。

青岛科技大学VB上机实验答案

青岛科技大学VB上机实验答案

实验一 VB环境和简单应用程序设计(4个学时)一、实验目的1.熟悉Visual Basic集成开发环境的使用。

2.掌握建立、编辑和运行简单的Visual Basic应用程序的全过程。

3.掌握窗体对象的属性、事件和方法。

二、实验内容1. 在VB的集成开发环境中实现如下的操作:1)、将“标准”工具栏去掉后再添加上,将“编辑”工具栏添上再去掉。

2)、分别利用“菜单”和“工具栏”中的命令打开“属性窗口”、“工程资源管理器窗口”3)、将“窗体布局窗口“的”启动位置“设置成“手工”。

4)、在工具箱中任意添加一个Active X 控件。

5)、在工程1中增加两个窗体:Form1、Form26)、在工程1中增加两个标准模块:Module1 、Module27)、在工程1中增加一个类模块:Class18)、在工程资源管理器中将Form2、Module2 删除。

9)、在在工程资源管理器中利用“切换文件夹”按钮隐藏或显示对象的文件夹10)、将代码窗口中的字体大小改为18号字。

2.设计一个窗体,窗体内有1个文本框和3个命令按钮控件。

要求:当按“显示”按扭时,在文本框内显示“欢迎来到青岛科技大学!”一串红色、四号、隶书字符串。

当按“清除”按钮时,清除文本框内全部信息;当按“退出”按钮时,结束程序运行。

1) 创建界面(将设计好的界面截下来粘贴在下面)3)代码设计Private Sub Command1_Click()T ext1.T ext = "欢迎来到青岛科技大学!"End SubPrivate Sub Command2_Click()T ext1.T ext = ""End SubPrivate Sub Command3_Click()EndEnd Sub4)调试过程记录(错误情况及改正方法,不得少于三条)1、text1与text颠倒了位置通过查课本改正3. 设计一个窗体,在窗体上添加一个文本框和三个命令按钮。

VB上机指导习题答案

VB上机指导习题答案

1、随机产生三个100-300之间的整数,判断这三个整数是否能构成三角形,如果可以,求三角形的面积。

Dim x As Integer, y As Integer, z As IntegerDim c As Single, s As Singlex = Int(Rnd * 201 + 100)y = Int(Rnd * 201 + 100)z = Int(Rnd * 201 + 100)If x + y > z And x + z > y And y + z > x Thenc = (x + y + z) / 2s = Sqr(c * (c - x) * (c - y) * (c - z))Print "三角形面积是:" & sElsePrint "构不成三角形"End If2、随机产生0-100之间的60名学生的数学分数,分别统计分数在[)10,0、[)20,10、[)30,20、[)40,30、[)50,40、[)60,50、[)70,60、[)80,70、[)90,80、[]90、之间的学生人数。

,100Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%Dim x As SingleFor m = 1 To 60 '产生60名学生的分数x = Rnd * 101 '产生0-100的分数Print x;If x >= 90 Thena = a + 1ElseIf x >= 80 Thenb = b + 1ElseIf x >= 70 Thenc = c + 1ElseIf x >= 60 Thend = d + 1ElseIf x >= 50 Thene = e + 1ElseIf x >= 40 Thenf = f + 1ElseIf x >= 30 Theng = g + 1ElseIf x >= 20 Thenh = h + 1ElseIf x >= 10 Theni = i + 1Elsej = j + 1End IfNext mPrint a, b, c, d, e, f, g, h, i, j3、我国有13亿人口,按照人口年增长0.8%计算,多少年以后我国人口超过26亿。

VB程序设计教程实验指导与习题解答上机答案

VB程序设计教程实验指导与习题解答上机答案

程序代码Private Sub Command1_Click()End SubPrivate Sub Command2_Click() = TrueEnd SubPrivate Sub Command3_Click() = TrueEnd SubPrivate Sub Command4_Click() = 10 = False = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:自测2单击还原之后窗口:Private Sub Command1_Click()Label1 = "visual basic"Text1 = " 程序设计题"End SubPrivate Sub Command2_Click()Text1 = "visual basic"Label1 = " 程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()End SubPrivate Sub Command2_Click() = + 30End Sub= + 20= 1初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4程序代码Private Sub Command1_Click() = "VB 学习"Print"简单的VB程序设计"End SubPrivate Sub Command2_Click()ClsEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:自测题5单击退出之后的窗口:Private Sub Comma nd1_Click()HHEnd SubPrivate Sub Comma nd2_Click() =Val + Val End SubPrivate Sub Comma nd3_Click() End End Sub初始化窗口: 单击运算之后窗口: 单击清除之后的窗口:也 I 绘I lirr-:輕 g砖屮 ZBPL H J ^E 霸赴 BAy 噹晔了 ZILT. 相0 ■tap乜=1 业 '-JS-J Q -•ST F■ I” _l ■■ B 事电r 兴/涉审叭暂背巧応科1I gMd I T B ' A bJ El -; F 」 )-1 a □瓷 a QB aitr 硕八— y -I Su日 r>M| PLi.l CnhwJ x> 蚀-7 -■nJ肝 k4・Jii.— Tr«:h^.L 33 -:呻p Ju IpL*口- i-JN h —vid.]F TM IHFLlMv ■ -UKncnm-'|LUIPI> r■41•成 &.■ B WOQULL,:■—PMd P GPrivate Sub Command1_Click()Dim a$= Left(a, 2)End SubPrivate Sub Command2_Click()= Right(a, 2)End SubPrivate Sub Command3_Click()End Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习2 Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l% a = 7349e = a Mod 10 ' 个位d = (a \ 10) Mod 10 ' 十位c = (a \ 100) Mod 10 ' 百位b = a \ 1000 ' 千位i = (e + 7) Mod 10 ' 个位h = (d + 7) Mod 10 ' 十位g = (c + 7) Mod 10 ' 百位f = (b + 7) Mod 10 ' 千位交换后的个位交换后的千位交换后的十位交换后的百位l = f * 1000 + g * 100 + h * 10 + i = FalsePrint " 加密前的4位整数是7439"; (Chr(10)); " 加密后的结果是"; l End Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox(" 输入第一个数", "b = Val(InputBox(" 输入第一个数", "f = Fix(f * 100 + / 100& "x/y=" & f, , " 输出的结果"End Sub自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!Print " 和="; ePrint " 平均值="; f 输入一个数", 8)) 输入一个数", 7))MsgBox"x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10)a = Val(InputBox(" 输入第一个数的值"))b = Val(InputBox(" 输入第二个数的值"))c = Val(InputBox(" 输入第三个数的值"))d = Val(InputBox(" 输入第四个数的值"))End Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox(" 输入总头数"))f = Val(InputBox(" 输入总脚数"))x = (4 * h - f) / 2y = (f - 2 * h) / 2Print " 笼中鸡的头数为"; x; 只"Print " 笼中兔的头数为"; y; 只"End Sub自测练习1:Private Sub Form_Click()Dim a%, b%, c%a = Val(InputBox(" 请输入第一条边", " 边长"))b = Val(InputBox(" 请输入第二条边", " 边长"))c = Val(InputBox(" 请输入第三条边", " 边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint " 直角"ElseIf a = b And b = c ThenPrint " 等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint " 等腰三角形"ElsePrint " 一般三角形"End IfElsePrint " 不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下:等腰三角形:般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox(" 请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口: 输入一个数: 运行结果: 自测练习3Private Sub Comma nd1_Click()Dim a%, b% a = ValSelect Case a > 0Case a < 20MsgBox "行李费为元/kg",," 行李费Case a >= 20 And a < 50MsgBox "行李费为元/kg",," 行李费Case a >= 50 And a < 100MsgBox "行李费为元/kg",," 行李费Case Elseb = * 100 + (a - 100) * : MsgBox " 行李费为"& b & "元",,"行李费End SelectEnd Sub初始窗口: 输入10: 输入25: 输入55: 输入120: 自测练习1Op tio n Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As In teger a(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10 a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFori = 11 To 16a(i) = a(i - 1) + a(i - 2)Print a(i);Next iPrintFor i = 17 To 20 a(i) = a(i - 1) + a(i - 2) Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load()= 10000= 5000End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4 a(i, j) = Int(Rnd * 10) + 1a(i, j);Next jNext i " 对角线的元素如下"For i = 1 To 4 a(i, i);Next iFor i = 1 To 4 a(i, 5 - i);Next iFor i = 1 To 4 t = a(1, i) a(1, i) = a(4, i) a(4, i) = t Next iFor i = 1 To 4 t = a(i, 2) a(i, 2) = a(i, 3) a(i, 3) = t Next iFor i = 1 To 4Forj = 1 To 4 a(i, j);Next jNext iEnd Sub运行初始界面:运行结果界面: 自测练习1Sub itostr(a As In teger)Dim b%, c$ a = VaiWhile a >= 1 c = Chr(a Mod 10+ 48) & c0 Fornnl施机;^生的拒畔相应处運输入矩阵茹处理般曲越$a = a \ 10WendEnd SubPrivate Sub Command1_Click()Dim a As Integer a = ValCall itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function area(n) As DoubleDim c#, d#, e#, s# n = Val c = (1 - 0) / nWhile e <= 1 d = I * c: e = (I + 1) * c s = s + (Sin(d) + Sin(e)) * c / 2 area = s WendEnd FunctionPrivate Sub Command1_Click()Dim s As DoubleCall area(n) = area(n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click() n =Val(InputBox(" 请输入n 的值")) x = Val(InputBox(" 请输入x 的值"))Print "e 的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integer a = 1: b = 1: c = 1For i = 1 To n a = x * a: b = b * i: c = c + a / bNext i es = cEnd Function运行初始界面:输入数据:运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox(" 输入y 的值", " 输入数据"))Insertfun a%(), YPrintFor i = 1 To 6Print a(i); " ";Next iEnd Sub运行初始界面:插入数据:运行结果:自测练习1:Private Sub Command1_Click()If = 1 Then = " 报名参加羽毛球比赛" End IfIf = 1 Then = " 报名参加乒乓球比赛"If = 1 And = 1 ThenEnd If= " 报名参加羽毛球,乒乓球比赛"End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load()= 24 = " 黑体" = &HFF&End SubPrivate Sub Option1_Click() = " 我是学生"End SubPrivate Sub Option2_Click() = " 我是教师"End SubPrivate Sub Option3_Click() = " 我是工人"Private Sub Option4_Click()End Sub= " 我是农民"End Sub运行初始界面:运行结果:自测练习6:Private Sub Command1_Click()For i = 0 To - 1If (i) = ThenExit ForEnd IfNext iIf i > - 1 ThenEnd IfEnd SubPrivate Sub Command2_Click()If <> -1 ThenFor i = 0 To - 1If (i) = ThenEnd IfExit ForNext iEnd IfEnd SubPrivate Sub Command3_Click()End Sub运行初始界面:自测练习7:Private Sub Command1_Click()= TrueEnd SubPrivate Sub Form_Load()= 20= 20= 20= 20End SubPrivate Sub Timer1_Timer() lbltem = = + 10If VSbwd >= 100 Then lbltishi = " 水开了" = FalseEnd IfEnd Sub运行初始界面:运行结果:自测练习1:Private Sub myhelp_Click()End SubPrivate Sub mymenu1_Click() = " 百货大楼"End SubPrivate Sub mymenu2_Click() = " 利客隆"End SubPrivate Sub mymenu3_Click() = " 稻香村"End Sub运行初始界面:运行结果界面:自测练习2:Private Sub Dis_Click() = " 菜单程序设计" = 20 = " 黑体"End SubPrivate Sub Hid_Click() = FalseEnd Sub运行初始界面:运行结果界面:自测练习3:Private Sub vbhelp_Click() r = MsgBox(" 帮助", , " 程序设计题")End SubPrivate Sub Vbnew_Click() r = MsgBox(" 新建", , " 程序设计题")End SubPrivate Sub vbopen_Click() r = MsgBox(" 打开", , " 程序设计题")End SubPrivate Sub vbsave_Click()自测练习1: r = MsgBox ("存盘”,," 程序设计题")End Sub运行初始界面: 运行结果: 自测练习4:Private Sub Comma nd1_Click()End Sub运行初始界面:打开萱我菊園(1):文件名oa ) ; I立件类型电》:Ir 以只读方式打开區IPrivate Sub Command1_Click()Dim a As String, n%, i%, j%我最近皈由 O ■ \ 27 我的文趋 岡上嘟居^41121(1£S □141130110041145029 口 411旳[)13_辛诒_经济L1D1 亡J jag 己1« iT^ Temp 匚PySoEt 巴第五次实脸要貳文楼 □新建文件夹g2O074£3LS294SS£4 总听ni咫S ! O S6u_p L nyi n J& 1tfySystem已義单SCX倉第五欢实脸要求丈档四寫件基^操作测试內容回数据1国數据1®数据l.dbc0掏门鄱爰甘濒SllfU 实甜直评d Hl 取消Open "E:\" For Input As #1Input #1, a n = Len(a)For i = 1 To nIf Mid(a, i, 1) = "%" Then j = j + 1 Next iClose #1Open "E:\" For Output As #1Print #1, jClose #1End Sub运行初始界面:运行结果:自测练习3:Private Sub Form_Click()Dim x$Open "e:\" For Input As #1Do While Not EOF(1)LoopClose #1Open "e:\" For Append As #1Print #1, x$Close #1Line Input #1, x$运行初始界面:自测练习4Private Sub Form_load()Print " 26 个英文字母"PrintPrint " a b c d e f g h i j k l m n o p q r s t u v w x y z" Print " 字母个数分别为"End SubPrivate Sub Form_Click()Open "E:\" For Output As #1文本$ = InputBox(" 请输入文本") n = UCase( 文本$)Print #1, nOpen "E:\" For Output As #1For i = 1 To Len(n)ReDim Preserve a(1 To 26) j = Asc(Mid(n, i, 1)) - 64 a(j) = a(j) + 1Next iClose #1For j = LBound(a) To UBound(a)Print a(j);Next jClose #1Dim a%()。

vb实验报告(答案)

vb实验报告(答案)
1)界面设计
2)属性设置
控件对象属性属性值
Text1 Name Txt1
Command1 Name Cmd1
Cmd1 Caption计算
Txt1 Caption全国计算机等级考试二级
3)代码设计
Private Sub Cmd1_Click()
Print Txt1.SelText
End Sub
17、在名称为Form1的窗体上画一个文本框,其名称为Text1,编写适当的事件过程。程序运行后,如果单击窗体,则可使文本框移到窗体的左上角;而如果改变文本框中的内容,则可使文本框移到窗体的右上角。
2、已知字符串A的值为“AbcDe“,现在把它全部转换为大写字母,正确的语句是______Ucase(“AbcDe“)________。
3、有如下程序
a=300 : b=20
a=a + b : b=a–b
a=a–b
print a
print b
分析该程序的功能是_____a与b互换______
4、可以同时删除字符串前导和尾部空白的函数是(C)。
A. ShowB. Hide C. LoadD. Unload
3、在窗体上有多个控件,要实现程序运行后焦点默认在某一控件上,应该设置的属性是(C)。
A.设置Enabled的值为TrueB.设置TabIndex的值为1
C.设置TabIndex的值为0D.设置Index的值为0
4、设窗体上有一个文本框Text1,要求只能显示信息,不能输入,则应设置(B)。
Text1.Left = Text1.Left + 50
End Sub
14、在窗体上部设置一个文本框(text1),文本框的下面设置3个命令按钮,其中左边按钮(command1)中标有“单击此按钮”,中间按钮(command2)中标有“清除”,右边按钮(command3)中标有“程序结束”。当程序运行时,用鼠标单击左边按钮时,屏幕上部的文本框中显示“欢迎使用vb6.0”;如果单击中间按钮,则清除文本框中显示的内容;而如果单击右边的按钮,则结束程序。

国家二级VB机试(上机操作)模拟试卷5(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷5(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷5(题后含答案及解析) 全部题型 2. 基本操作题 3. 简单应用题 4. 综合应用题基本操作题1.请根据以下各小题的要求设计Visual Basic应用程序(包括界面和代码)。

在标题为”文本框”、名称为Forml的窗体上画一个名称为Textl的文本框,无初始内容,其高、宽分别为2000、1800,可显示多行,有水平滚动条,并通过属性窗口把文本框的字体样式设置为”斜体”(如图2.49所示)。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjtl.vbp,窗体文件名为sjtl.frm。

正确答案:步骤1:新建一个”标准。

EXE”工程,如表3-26在窗体中画出控件并设置其相关属性。

步骤2:按要求将文件保存至考生文件夹中。

2.在名称为Forml的窗体上画一个名称为Listl的列表框,通过属性窗口输入4个列表项:”数学”、”物理”、”化学”、”语文”,如图2-50所示。

请编写适当的事件过程,使得在装入窗体时,把最后一个列表项自动改为”英语”;单击窗体时,则删除最后一个列表项。

注意:要求程序中不得使用变量,每个事件过程中只能写一条语句。

存盘时必须存放在考生文件夹下,工程文件名为sjt2.vbp,窗体文件名为sjt2.frm。

正确答案:步骤1:新建一个”标准EXE”工程,在窗体Forml中加入一个列表框,在属性设置窗口中将其Name属性设置为Listl,在其List属性中添加四个项目,依次为”数学”、”物理”、”化学”和”语文”。

注意:每输入完一项后按<Ctrl+Enter>键换行再输入下一项。

步骤2:打开代码编辑窗口,编写相应的事件过程:参考代码:Private Sub Form_Click( )Listl.RemoveItem Listl.ListCount_1Enld SubPrivate Sub Form_Load( )Listl.List(Listl.ListCount-1)=“英语”End Sub步骤3:按要求将文件保存至考生文件夹中。

国家二级VB机试(上机操作)模拟试卷328(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷328(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷328(题后含答案及解析) 全部题型 2. 基本操作题 3. 简单应用题 4. 综合应用题基本操作题1.(1)在名称为Forml的窗体上添加一个名称为Commandl的命令按钮,标题为“打开文件”,再添加一个名称为CDl的通用对话框。

程序运行后,如果单击命令按钮,则弹出打开文件对话框,请按下列要求设置属性和编写代码:①设置适当属性,使对话框的标题为“打开文件”;②设置适当属性,使对话框的“文件类型”下拉式组合框中有两项可供选择:“文本文件”、“所有文件”(如图所示),默认的类型是“所有文件”;③编写命令按钮的事件过程,使得单击按钮可以弹出“打开文件”对话框。

要求:程序中不得使用变量,事件过程中只能写入一条语句。

注意:存盘时必须存放在考生文件夹下,工程文件名保存为sjt1.vbp,窗体文件名保存为sjt1.frm。

(2)在名称为Form1的窗体上添加一个名称为Command1的命令按钮,其标题为“移动本按钮”,如图所示。

要求编写适当的事件过程,使得程序运行时,每单击按钮一次,按钮向左移动100。

要求:程序中不得使用变量,事件过程中只能写入一条语句。

注意:存盘时必须存放在考生文件夹下,工程文件名保存为sjt2.vbp,窗体文件名保存为sjt2.frm。

正确答案:(1) 【操作步骤】步骤1:新建一个窗体,按照要求建立控件并设置其属性,如图3.21所示。

程序中用到的控件及属性见表3.13。

步骤2:打开代码编辑窗口,在指定位置编写如下代码。

Private sub Commandl_Click( ) CD1.ShowOpen’显示打开文件对话框End Sub 步骤3:调试并运行程序,关闭程序后按题目要求存盘。

(2) 【操作步骤】步骤1:新建一个窗体,按照要求建立控件并设置相应属性如表3.14所示。

步骤2:打开代码编辑窗口,在指定位置编写如下代码。

PriVate sub Commandl_Click( ) Command1.Left=Command1.Left-100 End Sub 步骤3:调试并运行程序,关闭程序后按题目要求存盘。

VB程序设计指导实验指导与习题解答上机答案

VB程序设计指导实验指导与习题解答上机答案

自测1程序代码Private Sub Command1_Click() Label1.FontSize = Label1.FontSize + 3End SubPrivate Sub Command2_Click() Label1.FontBold = TrueEnd SubPrivate Sub Command3_Click() Label1.FontUnderline = TrueEnd SubPrivate Sub Command4_Click() Label1.FontSize = 10Label1.FontBold = FalseLabel1.FontUnderline = FalseEnd Sub初始窗口:单机放大之后窗口:单机下划线之后窗口:单击加粗之后窗口:单击还原之后窗口:自测2程序代码Private Sub Command1_Click() Label1 = "visual basic"Text1 = "程序设计题"End SubPrivate Sub Command2_Click() Text1 = "visual basic"Label1 = "程序设计题"End Sub初始窗口:单击显示之后窗口:单击交换之后的窗口:自测题3Private Sub Command1_Click()Label1.FontSize = Label1.FontSize * (0.5) End SubPrivate Sub Command2_Click()Label1.Top = Label1.Top + 30Label1.Width = Label1.Width + 20Label1.Alignment = 1End Sub初始窗口:单击缩小两倍之后的窗口:单击向右下角移动之后的窗口:自测题4程序代码Private Sub Command1_Click() Form1.Caption = "VB学习" Print "简单的VB程序设计"End SubPrivate Sub Command2_Click() ClsEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Command3_Click() EndEnd Sub初始化窗口:单击显示之后的窗口:单击清除之后的窗口:单击退出之后的窗口:自测题5程序代码Private Sub Command1_Click()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text) End SubPrivate Sub Command3_Click()EndEnd Sub初始化窗口:单击运算之后窗口:单击清除之后的窗口:单击退出之后的窗口:自测练习1Private Sub Command1_Click() Dim a$a = Text1.TextLabel1.Caption = Left(a, 2) End SubPrivate Sub Command2_Click() a = Text1.TextLabel2.Caption = Right(a, 2) End SubPrivate Sub Command3_Click()Text1.Text = Label1.Caption & Label2.Caption End Sub初始窗口界面输入字符串截取前两个字符截取后两个字符字符串连接自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l% a = 7349e = a Mod 10 '个位d = (a \ 10) Mod 10 '十位c = (a \ 100) Mod 10 '百位b = a \ 1000 '千位i = (e + 7) Mod 10 '个位h = (d + 7) Mod 10 '十位g = (c + 7) Mod 10 '百位f = (b + 7) Mod 10 '千位j = ii = f '交换后的个位f = j '交换后的千位k = hh = g '交换后的十位g = k '交换后的百位l = f * 1000 + g * 100 + h * 10 + iText1.Visible = FalsePrint "加密前的4位整数是7439"; (Chr(10)); "加密后的结果是"; lEnd Sub初始界面单击窗体运行后的界面自测练习1Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数", "输入一个数", 8))b = Val(InputBox("输入第一个数", "输入一个数", 7))c = a + bd = a - be = a * bf = a / bf = Fix(f * 100 + 0.5) / 100MsgBox "x+y=" & c & Chr(10) & "x-y=" & d & Chr(10) & "x*y=" & e & Chr(10) & "x/y=" & f, , "输出的结果"End Sub自测练习2Private Sub Form_Click()Dim a%, b%, c%, d%, e%, f!a = Val(InputBox("输入第一个数的值"))b = Val(InputBox("输入第二个数的值"))c = Val(InputBox("输入第三个数的值"))d = Val(InputBox("输入第四个数的值"))e = a + b + c + df = e / 4Print "和="; e Print "平均值="; f End Sub自测练习3Private Sub Form_Click()Dim h%, f%, x%, y%h = Val(InputBox("输入总头数")) f = Val(InputBox("输入总脚数")) x = (4 * h - f) / 2y = (f - 2 * h) / 2Print "笼中鸡的头数为"; x; "只" Print "笼中兔的头数为"; y; "只"End Sub自测练习1:Private Sub Form_Click() Dim a%, b%, c%a = Val(InputBox("请输入第一条边", "边长"))b = Val(InputBox("请输入第二条边", "边长"))c = Val(InputBox("请输入第三条边", "边长"))If a + b > c And a + c > b And b + c > a ThenIf a * a + b * b = c * c Or a * a + c * c = b * b Or b * b = c * c = a * a ThenPrint "直角"ElseIf a = b And b = c ThenPrint "等边三角形"ElseIf a = b Or a = c Or b = c ThenPrint "等腰三角形"ElsePrint "一般三角形"End IfElsePrint "不是三角形"End IfEnd Sub不是三角形运行结果:初始窗口:输入三条边:运行结果:直角三角形运行结果:等边三角形运行结果如下:等腰三角形:一般三角形自测练习2:Private Sub Form_Click()Dim a%, b!a = Val(InputBox("请输入"))If a Mod 2 = 0 And a Mod 3 = 0 And a Mod 5 = 0 Then b = Sqr(a)Print a, bElseEndEnd IfEnd Sub初始化窗口:输入一个数:运行结果:自测练习3Private Sub Command1_Click()Dim a%, b%a = Val(Text1.Text)Select Case a > 0Case a < 20MsgBox "行李费为0.2元/kg", , "行李费"Case a >= 20 And a < 50MsgBox "行李费为0.3元/kg", , "行李费"Case a >= 50 And a < 100MsgBox "行李费为0.4元/kg", , "行李费"Case Elseb = 0.2 * 100 + (a - 100) * 0.5: MsgBox "行李费为" & b & "元", , "行李费"End SelectEnd Sub初始窗口:输入10:输入25:输入55:输入120:自测练习1Option Base 1Private Sub Form_Click()Dim i%, a(1 To 20) As Integera(1) = 1: a(2) = 1Print a(1);Print a(2);For i = 3 To 10a(i) = a(i - 1) + a(i - 2) Print a(i);Next iPrintFor i = 11 To 16a(i) = a(i - 1) + a(i - 2) Print a(i);Next iPrintFor i = 17 To 20a(i) = a(i - 1) + a(i - 2) Print a(i);Next i初始界面:运行结果界面:自测练习2Option Base 1Private Sub Form_Load() Form1.Width = 10000 Form1.Height = 5000 End SubPrivate Sub Command1_Click()Dim i%, j%, t%, a(1 To 4, 1 To 4) As Integer For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 10) + 1Picture1.Print a(i, j);Next jPicture1.PrintNext iPicture3.Print "对角线的元素如下"For i = 1 To 4Picture3.Print a(i, i);Next iPicture3.PrintFor i = 1 To 4Picture3.Print a(i, 5 - i);Next iFor i = 1 To 4t = a(1, i)a(1, i) = a(4, i)a(4, i) = tNext iFor i = 1 To 4t = a(i, 2)a(i, 2) = a(i, 3)a(i, 3) = tNext iFor i = 1 To 4For j = 1 To 4Picture2.Print a(i, j); Next jPicture2.PrintNext iEnd Sub运行初始界面:运运行结果界面:自测练习1Sub itostr(a As Integer) Dim b%, c$a = Val(Text1.Text)While a >= 1c = Chr(a Mod 10 + 48) & ca = a \ 10WendText2.Text = c End SubPrivate Sub Command1_Click()Dim a As Integera = Val(Text1.Text)Call itostr(a)End Sub运行初始界面:运行结果界面:验证其他数字:自测练习2:Public Function area(n) As Double Dim c#, d#, e#, s#n = Val(Text2.Text)c = (1 - 0) / nWhile e <= 1d = I * c:e = (I + 1) * cs = s + (Sin(d) + Sin(e)) * c / 2 I = I + 1Wendarea = sEnd FunctionPrivate Sub Command1_Click() Dim s As DoubleCall area(n)Text1.Text = area(n)End Sub运行初始界面:运行结果:自测练习3Private Sub Form_click()n = Val(InputBox("请输入n的值"))x = Val(InputBox("请输入x的值"))Print "e的值="; es(n, x)End SubPrivate Function es(n, x)Dim a As Double, b As Double, c As Double, i As Integer a = 1: b = 1: c = 1For i = 1 To na = x * a:b = b * i:c = c + a / bNext ies = cEnd Function运行初始界面:输入数据:运行结果:自测练习4:For i = 1 To 4For j = i + 1 To 5If a(i) > a(j) Thent = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iFor i = 1 To 5Print a(i); " ";Next iFor i = 1 To 5If Y < a(i) Thent = a(i): a(i) = Y: Y = tEnd IfNext iFor i = 1 To 6a(6) = tNext iEnd FunctionPrivate Sub Command1_Click()Dim i#, a%(1 To 6), Y%Y = Val(InputBox("输入y的值", "输入数据")) Insertfun a%(), YPrintFor i = 1 To 6Print a(i); " "; Next iEnd Sub运行初始界面:插入数据:运行结果:41011060蓝志鹏资源1102 实验8自测练习1:Private Sub Command1_Click()If Ch1.Value = 1 ThenText1.Text = "报名参加羽毛球比赛"End IfIf Ch2.Value = 1 ThenText1.Text = "报名参加乒乓球比赛"End IfIf Ch1.Value = 1 And Ch2.Value = 1 Then Text1.Text = "报名参加羽毛球,乒乓球比赛" End IfEnd Sub运行初始界面:运行结果:自测练习4:Private Sub Form_Load() Label1.Alignment = 2 Label1.FontSize = 24 Label1.FontName = "黑体" Label1.ForeColor = &HFF&End SubPrivate Sub Option1_Click() Label1.Caption = "我是学生" End SubPrivate Sub Option2_Click() Label1.Caption = "我是教师" End SubPrivate Sub Option3_Click() Label1.Caption = "我是工人" End SubPrivate Sub Option4_Click() Label1.Caption = "我是农民" End Sub运行初始界面:运行结果:。

vb上机练习试题及答案

vb上机练习试题及答案

第一章概述一、基本要求(1)熟悉VB集‎成开发环境‎(2)掌握代码窗‎口的应用及‎录入、编辑代码的‎基本方法(3)了解VB程‎序设计的基‎本步骤二、实习内容(1)实习熟悉V‎B集成开发‎环境各组成‎部分(2)输入一个数‎,求该数的平‎方并显示结‎果第二章一、基本要求(1)熟练掌握各‎种运算符的‎应用和优先‎顺序(2)掌握各种常‎用函数的功‎能、参数和返回‎值(3)掌握立即窗‎口的使用方‎法二、实验内容(1)回答整形、长整型、单精度、双精度类型‎数据占用字‎节数。

(2)已知直角三‎角形的两条‎直角边长,求斜边长。

Priva‎t e Sub Comma‎n d1_C‎l ick()Dim a%, b%, c%a = Val(Input‎B ox("输入第一条‎直角边长"))b = Val(Input‎B ox("输入第二条‎直角边长"))c = Sqr(a ^ 2 + b ^ 2)Print‎cEnd Sub(3)给小学生随‎机出两位数‎和一位数的‎加法题。

Priva‎t e Sub Comma‎n d1_C‎l ick()Dim a%, b%, c%a = Val(Input‎B ox("输入两位数‎"))b = Val(Input‎B ox("输入一位数‎"))c = a + bPrint‎cEnd Sub(4)用文本框输‎入一个带小‎数的数,对输入的数‎四舍五入保‎留2位小数‎。

Priva‎t e Sub Comma‎n d1_C‎l ick()Dim x#, y!x = Text1‎.Texty = Round‎(x, 2)Print‎yEnd Sub(5)输入某人姓‎名,判断是否你‎的本家。

Priva‎t e Sub Comma‎n d1_C‎l ick()Dim a$, b$, p As Boole‎a nb = "李"a = Input‎B ox("输入某人的‎姓名")If Left(a, 1) = b Thenp = TrueEnd IfPrint‎pEnd Sub(6)任意输入西‎安地区的固‎定电话号码‎(原为7位),将其升为8‎位(在原号码前‎面加8)。

国家二级VB机试(上机操作)模拟试卷100(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷100(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷100(题后含答案及解析) 全部题型 2. 基本操作题 3. 简单应用题 4. 综合应用题基本操作题1.请根据以下各小题的要求设计Visual Basic应用程序(包括界面和代码)。

(1)在名称为Forml的窗体上画一个标签,名称为L1,标题为“业余爱好”,再画一个名称为Chl的复选框数组,含三.个复选框,它们的Index属性分别为0、1、2,标题依次为“体育”、“音乐”、“美术”,请设置复选框的属性,使其初始状态见表3一1。

运行后的窗体如图3-11所示。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjtl.vbp,窗体文件名为sjtl.frm。

(2)在名称为Forml的窗体上画一个文本框,名称为Text1;再建立一个下拉菜单,菜单标题为“操作”,名称为M1,此菜单下含有两个菜单项,名称分别为Show和Hide,标题分别为“显示”、“隐藏”,请编写适当的事件过程,使得在运行时,单击“隐藏”菜单项,则文本框消失;单击“显示”菜单项,则文本框显示出来。

运行后的窗体如图3-12所示。

要求程序中不得使用变量,每个事件过程中只能写一条语句。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjt2.vbp,窗体文件名为sjt2.frm。

正确答案:第1小题本题只需按要求画出控件数组,并设置其Value属性。

【操作步骤】步骤1:新建一个“标准EXE”工程。

步骤2:在窗体Forml中加入一个标签和一个复选框,并用“复制”和“粘贴”的方法,生成包含三个元素的复选框数组。

步骤3:分别设置窗体和复选框数组中各元素的相关属性,其属性及值如表4.5所示。

步骤4:按要求将文件保存至考生文件夹中。

第2小题本题需用菜单设计器建立菜单,并编写“显示”和“隐藏”菜单项的单击事件过程控制文本框的visible属性变化。

【操作步骤】步骤1:新建一个“标准EXE”工程,在窗体Forml中画一个文本框,在属性设置窗口中将其Name属性值设置为Text1。

VB电脑课实验-答案汇总

VB电脑课实验-答案汇总

学院专业(班级)姓名学号任课教师目录实验一 Visual Basic编程环境和控件 (1)实验二窗体及基本控件使用 (7)实验三顺序结构程序设计 (14)实验四选择结构程序设计 (20)实验五选择结构程序设计(续) (25)实验六循环结构程序设计 (33)实验七循环结构程序设计(续) (38)实验八常用控件 (42)实验九常用控件(续) (51)实验十数组 (56)实验十一数组(续) (65)实验十二顺序文件 (70)实验十三过程 (77)实验十四过程(续) (84)实验十五菜单及通用对话框 (90)实验十六随机文件(选作) (94)附录:VB统考编程题(精选) (98)期末自测题(A卷) (108)期末自测题(B卷) (113)实验报告的整理与编写上机实验结束后,编写实验报告是软件工程的要求,也是培养科学作风的重要途径,实验报告的主要内容包括:(1)实验目的实验作为教学的一个重要环节,其目的在于更深入地理解和掌握课程教学中的有关基本概念,应用基本技术解决实际问题,从而进一步提高分析问题和解决问题的能力。

因此,当我们着手做一个实验的时候,必须明确实验的目的,以保证达到课程所指定的基本要求。

在写实验报告时,要进一步确认是否达到了预期的目的。

(2)实验内容实验的目的是要通过解决一些具体问题来达到的。

在书中,每一部分都安排了多个实验题目,根据教学安排、进度、实验条件、可提供的机时、学生的基础等因素,可以选择其中的几个或全部。

因此,在实验报告中,实验内容是指本次实验中实际完成的内容。

在每一个实验题目中,一般都提出一些具体要求,其中有些具体要求是为了达到实验目的而提出的,不仅有具体的实验题目,还应包括具体要求。

(3)程序设计说明包括算法设计思路,必要的流程图,界面设计说明、使用模块及变量的说明等。

(4)源程序代码Visual Basic的源程序包括界面设计和代码。

程序设计的产品是程序,它应与算法或流程图相一致,要与用户界面设计一致。

vb上机答案全部

vb上机答案全部

实验一Form1.print “程序设计基础教程”End subPrivate sub form_dblclick()Form1.clsEnd subDim a as single,b as single,c as single a=val(text1.text)b=val(text2.text)c=a*btext3.text=str(c)end subDim n as integer,a as singlen=val(text1.text)a= n^(1/3)text2.text=str(a)end subText1.text=“visual basic 程序设计”end subPrivate Sub Command2_click()Text1.text=“”end subText2.text=left(text1.text,5)end subPrivate Sub Command2_click()Text3.text=len(text1.text)end subForm1.Move 0, 0End SubPrivate Sub Command2_Click()Form1.Height = Form1.Height * 1.2Form1.Width = Form1.Width * 1.2End Sub7.Const pi as single=3.14159Command1_click()Dim a as single,b as single,c as single,s as single a=val(text1.text)b=val(text2.text)c=val(text3.text)s=a*b*sin((c*pi)/180)/2text4.text=round(s ,2)end sub实验二顺序Const pi as single=3.14159Private Sub Command1_click()Dim r as single,v as singler=val(text1.text)v=4/3 *pi*r^3label1.caption=format(v, “0.00”)end subDim a as single,b as single,c as single,d as single a=val(text1.text)b=val(text2.text)c=val(text3.text)d=(a+b+c)/3text4.text=format(d, “0.00”)end subText1.locked=falseEnd subPrivate Sub Text1_changeCommand2.enable=trueEnd subPrivate Sub Command_click()Text1.locked=trueCommand2.enable=falseEnd subText1.text=“欢迎光临”End subCommand2_click()Text1.text=“谢谢再见”End subText1.selstart=8Text1.sellength=9End subCommand2_click()Label2.caption=text1.seltext End subConst pi as single=3.14159Dim r as single,h as singlePrivate Sub Command click()Dim s as singler=text1.texth=text2.texts=2*pi*r^2+2*pi*r*htext3.text=format(s, “0.000”) end subPrivate Sub command2 click()dim v as singlev=pi*r^2*htext4.text=format(v, “0.000”) end subDim a as string,b as stringPrivate Sub Command1_click()a=text1.textb=text2.texttext3.text=“a” & “b”end subPrivate Sub command2_click()dim t as stringa=text1.textb=text2.textt=aa=bb=ttext1.text=atext2.text=blabel1.caption=“交换成功”end sub实验三选择Dim n as integerIf (n mod 3=0 )and (n mod 7=0 ) then Label2.caption=“Yes”ElseLabel2.caption=“No”End ifEnd subDim x as single,y as singlex=text1.texty=text2.textif x>0 and y>0 thentext3.text=“第一象限”elseif x<0 and y>0 thentext3.text=“第二象限”elseif x<0 and y<0 thentext3.text=“第三象限”else x>0 and y<0 thentext3.text=“第四象限”end ifend subDim a as single,b as single,c as single,d as single a=text1.textb=text2.textc=text3.textd=a+b+cif d>=270 thenif d>=285 thentext4.text=“Gold Medal”elsetext4.text=“Silver Medal”end ifelseif d>240 thentext4.text=“Bronze Medal”elseif a>95 or b>95 or c>95 thentext4.text=“Honor Medal”elsetext4.text=“No Medal”end ifend ifend subText.text=“我是博士生”End subOption2_clickText.text=“我是硕士生”End subOption3_clickText.text=“我是本科生”End subIf Check1.Value ThenLabel1.FontUnderline = TrueElseLabel1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.Value ThenLabel1.FontStrikethru = TrueElseLabel1.FontStrikethru = FalseEnd IfEnd SubDim n as singlen=text1.textif n=<4 thentext2.text=format(10,“0.0”)elseif n>4 and n<=15 thentext2.text=format(10+1.2*(n-4),“0.0”)elsetext2.text=format(1.8*n,“0.0”)end ifend subIf text1.text=“Teacher” thenIf text2.text=“123456” thenLabel3.caption=“登录成功”ElseLabel3.caption=“密码不正确”End ifElseif text1.text=“Student” thenIf text2.text=“654321” thenLabel3.caption=“登录成功”ElseLabel3.caption=“密码不正确”End ifElseLabel3.caption=“用户未注册”End ifEnd sub实验四循环Dim n As Integer, i As Integer, a As Long n = Text1.Texta = 0For i = 1 To nIf (i Mod 3 = 0) And (i Mod 7 <> 0) Thena = a + iEnd IfNext iLabel1.Caption = aEnd SubDim n As Integer, m As Integer, i As Integern = Text1.Text n=val(text1.text)m = Text2.Text m=val(text2.text)If m >= n Then for i=n to 1 step -1For i = n To 1 Step -1 if n mod i=0 and m mod i=0 then If (m Mod i = 0) And (n Mod i) = 0 Then text3.text=str(i)Text3.Text = I exit forExit For end ifEnd If next iNext iElseFor i = m To 1 Step -1If (m Mod i = 0) And (n Mod i = 0) ThenText3.Text = iExit ForEnd IfNext iEnd IfEnd SubDim n As Integer, m As Integer, i As Integer, a As Integer, s As Integer, flag AsBooleanm = Text1.Textn = Text2.Texts = 0For a = m To nflag = TrueFor i = 2 To a - 1If a Mod i = 0 Thenflag = FalseExit ForEnd IfNext iIf flag = True Then s = s + a Next aText3.Text = sEnd SubTimer1.Enabled = TrueEnd SubPrivate Sub Command2_Click() Timer1.Enabled = FalseLabel1.Left = 100End SubPrivate Sub Timer1_Timer() Label1.Left = Label1.Left + 100 End SubDim n As Single, i As Single, a As Single, s As Single n = Label1.Captions = 0For i = 1 To nFor a = 1 To is = s + aNext aNext iText1.Text = sEnd SubPrivate Sub HScroll1_Change()Label1.Caption = HScroll1.ValueEnd SubDim s As Single, n As Long, t As Long, i As Longs = Text1.Textt = 1For i = 1 To Len(s)If Right(s, 1) = "1" Thenn = n + tEnd Ift = t * 2s = Left(s, Len(s) - 1)Next iLabel1.Caption = nEnd SubPrivate Sub Command2_Click()Dim a As Long, q As Longa = Text1.TextDo While (a > 0)q = a Mod 2 & qa = a \ 2LoopLabel1.Caption = qEnd SubTimer1.Enabled = TrueCommand1.Enabled = FalseCommand1.Caption = "继续"Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Command2.Enabled = FalseCommand1.Enabled = TrueTimer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Label1.FontSize = Label1.FontSize * 1.1 If Label1.FontSize > 100 ThenLabel1.FontSize = 8End IfEnd Sub实验五数组Private Sub Command1_Click()Dim i As IntegerText1.text=""For i = 1 To 10a(i) = Int(Rnd * 81) + 10Text1.Text = Text1.Text & a(i) & Space(2) Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, t As Integer Text2.text=""For i = 1 To 9For j = i + 1 To 10If a(i) > a(j) Thent = a(j)a(j) = a(i)a(i) = tEnd IfNext jNext iFor i = 1 To 10If a(i) Mod 3 = 0 ThenText2.Text = Text2.Text & a(i) & Space(2) End IfNext iEnd SubPrivate Sub Command1_Click()Dim i As IntegerFor i = 1 To 10a(i) = Int(Rnd * 26) + 65Text1.Text = Text1.Text & a(i) & Space(2)Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, max As Integermax = a(1)For i = 2 To 10If max < a(i) Thenmax = a(i)End IfNext iText2.Text = maxText3.Text = Chr(max)End SubPrivate Sub Command1_Click()Dim i As IntegerFor i = 1 To 100a(i) = Int(Rnd * 26) + 65Text1.Text = Text1.Text & Chr(a(i)) & Space(2) Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, b As Integer, j As Integer r = 0b = Asc(Text2.Text)For i = 1 To 100If a(i) = b Thenj = j + 1End IfNext iText3.Text = jEnd SubPrivate Sub Command1_Click()Dim i As Integer, j As IntegerText1.Text = ""For i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 90) + 10Text1.Text = Text1.Text & a(i, j) & Space(2) Next jText1.Text = Text1.Text & vbCrLfNext iEnd SubPrivate Sub Command2_ClickDim i as Integer ,j as Integer ,s as Integer For i = 1 to 5j = 6 – is=s+a( i ,j )next iLabel1.caption =sEnd SubPrivate Sub Command1_Click()Dim n As Integer, i As Integeri = Val(Text1.Text)ReDim a(1 To i)a(1) = 1a(2) = 1For n = 3 To ia(n) = a(n - 1) + a(n - 2)Next nText2.Text = a(i)End SubPrivate Sub Command1_Click()Dim i As IntegerText1.text=""For i = 1 To 50a(i) = Int(Rnd * 90) + 10Text1.Text = Text1.Text & a(i) & Space(2) Next iEnd SubPrivate Sub Command2_Click()Dim i As IntegerText2.Text = 0For i = 1 To 50If a(i) Mod 3 = 0 And a(i) Mod 7 = 0 Then Text2.Text = Val(Text2.Text) + a(i)End IfNext iEnd SubPrivate Sub Command1_Click()Dim i As Integer, j As IntegerText1.Text = ""For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 41) + 10Text1.Text = Text1.Text & a(i, j) & Space(2)Next jText1.Text = Text1.Text & vbCrLfNext iEnd SubPrivate Sub Command2_Click()Dim i As Integer,j as integerFor i=1 to 4t=a(i,1)a(i,1)=a(i,3)a(i,3)=tNext tFor i = 1 To 4For j = 1 To 4Label1.Caption = Label1.Caption & a(i, j) & Space(2) Next jLabel1.Caption = Label1.Caption & vbCrLfNext iEnd Sub实验六常用控件Private Sub Op_Click(Index As Integer)Dim a As Integer, b As Integer, c As Integera = Val(Text1.Text)b = Val(Text2.Text)Select Case IndexCase 0c = a + bCase 1c = a - bCase 2c = a * bCase 3c = a / bEnd SelectText3.Text = Str(c)End SubPrivate Sub Command1_Click()Dim n As IntegerFor n = 1 To 10a(n) = Int(Rnd * 81) + 10List1.AddItem a(n)Next nEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, k As Integer, t% For i = 1 To 9For k = i + 1 To 10If a(i) > a(k) Thent = a(i)a(i) = a(k)a(k) = tEnd IfNext kNext iFor i = 1 To 10List2.AddItem a(i)Next iEnd SubPrivate Sub Command1_Click()Timer1.Enabled = FalseCommand2.Enabled = TrueCommand1.Enabled = FalseEnd SubPrivate Sub Command2_Click()Timer1.Enabled = TrueCommand1.Enabled = TrueCommand2.Enabled = FalseEnd SubPrivate Sub Command3_Click()List1.RemoveItem List1.ListIndexEnd SubPrivate Sub Timer1_Timer()List1.AddItem Int(Rnd * 90000 + 10000) End SubDim n As Integer, s As Integers = 0For n = 0 To 4If List1.Selected(n) = True Thens = s + 1End IfNext nText1.Text = sEnd SubList1.AddItem Combo1.TextEnd SubPrivate Sub List1_DblClick()List1.RemoveItem List1.ListIndexEnd SubText1.Text = Combo1.TextEnd SubPrivate Sub Command2_Click()Combo1.List(Combo1.ListIndex) = Text1.TextEnd SubPrivate Sub Timer1_TimerDim n as integerIf n>Combo1.ListCount-1 then n=0Combo1.ListIndex = nn=n+1End SubPrivate Sub Command1_ClickTimer1.Enabled =TrueCommand1.Enabled = FalseCommand2.Enabled = TrueEnd SubPrivate Sub Command2.ClickTimer1.Enabled = FalseCommand1.Enabled = TrueCommand2.Enabled =FalseEnd SubPrivate Sub Command3_Click()For j = 0 To Combo1.ListCount - 1If Combo1.List(j) = Trim(Text1.Text) Then Exit ForEnd IfNext jIf j = Combo1.ListCount ThenLabel1.Caption = "No Found"ElseLabel1.Caption = "Found"End IfEnd Sub实验七过程Dim i As Integer, n As Integer, p As Double n = Val(Text1.Text)p = 0For i = 1 To np = p + fact(i)Next iText2.Text = Str(p)End SubFunction fact(ByVal n As Integer) As Double Dim i As Integer, p As Doublep = 1For i = 1 To np = p * iNext ifact = pEnd FunctionDim x As Integer, y As Integer, z As Integer x = Val(Text1.Text)y = Val(Text2.Text)z = Val(Text3.Text)Swap x, ySwap x, zSwap y, zText4.Text = x & " " & y & Space(2) & z End SubPrivate Sub Swap(ByRef x%, ByRef y%)Dim t As IntegerIf x < y Thent = x: x = y: y = tEnd IfEnd SubDim m As Integer, n As Integerm = Val(Text1.Text)n = Val(Text2.Text)Text3.Text = m * n / Gcd(m, n)End SubFunction Gcd(ByVal m%, ByVal n%) As Integer Dim i As IntegerFor i = m To 1 Step -1If m Mod i = 0 And n Mod i = 0 ThenGcd = iExit FunctionEnd IfNext iEnd FunctionDim x As Integer, n As Integerx = Val(Text1.Text)n = Val(Text2.Text)Text3.Text = Square(x, n)End SubFunction Square(ByVal x%, ByVal n%) As Double Dim i As IntegerFor i = 0 To nSquare = Square + x ^ iNext iEnd FunctionDim m As Integer, n As Integer, i As Integer Text3.Text = ""m = Val(Text1.Text): n = Val(Text2.Text)For i = m To nIf Isprime(i) ThenText3.Text = Text3.Text & i & " "End IfNext iEnd SubFunction Isprime(n As Integer) As Boolean Dim i As IntegerIsprime = TrueFor i = 2 To n - 1If n Mod i = 0 ThenIsprime = FalseExit FunctionEnd IfNext iEnd FunctionPrivate Sub Command1_Click()Dim i As IntegerReDim a(9)Text1.Text = ""For i = 0 To 9a(i) = Int(Rnd * 90) + 10Text1.Text = Text1.Text & a(i) & Space(2) Next iEnd SubFunction sort(b() As Integer)Dim i As Integer, j As Integer, t As Integer For i = 0 To 8For j = i + 1 To 9If b(j) < b(i) Thent = b(j)b(j) = b(i)b(i) = tEnd IfNext jNext iFor i = 0 To 9sort = sort & b(i) & Space(2)Next iEnd FunctionPrivate Sub Command2_Click()Label1.Caption = sort(a())End SubDim i As Integersak = 0For i = 0 To k - 1sak = sak + a * 10 ^ iNext iEnd FunctionPrivate Sub Command1_Click()Dim i As Integer, n As Integer, s As Long, a As Integer a = Val(Text1.Text)n = Val(Text2.Text)s = 0For i = 1 To ns = sak(a, i) + sNext iText3.Text = sEnd Sub实验八图形Picture1.Picture = LoadPicture(App.Path & "\Wys.bmp") End SubPrivate Sub Command2_Click()Picture1.Picture = LoadPicture()End Sub2.If Check1.Value = 1 ThenImage1.BorderStyle = 1ElseImage1.BorderStyle = 0End IfEnd SubPrivate Sub Check2_Click()If Check1.Value = 1 ThenImage1.Picture = LoadPicture(App.Path & "\Pic.jpg") ElseImage1.Picture = LoadPicture()End IfEnd SubShape1.Shape = HScroll1.ValueEnd SubPrivate Sub VScroll1_Change()Shape1.FillStyle = VScroll1.ValueEnd SubPrivate Sub Command1_Click()Picture1.Line (0, 600)-(1600, 600)End SubPrivate Sub Command2_Click()Picture1.ClsPicture1.Circle (800, 600), 500, , , , 2End SubIf keyascii>48 or keyascii<57 ThenKeyascii=0Label1.Caption = "非法输入"ElseLabel1.Caption = "合法输入"End IfEnd SubImage1.Stretch = TrueImage1.Width = Image1.Width * Sqr(2 ^ (1 / 2)) Image1.Height = Image1.Height * Sqr(2 ^ (1 / 2)) End SubPrivate Sub Command2_Click()Image1.Stretch = TrueImage1.Width = Image1.Width * Sqr(2)Image1.Height = Image1.Height * Sqr(2)End SubPrivate Sub Command3_Click()Image1.Stretch = FalseEnd SubPicture1.backcolor=rgb(hsred.value,hsgreen.value,hsblue.value) End subHsgreen_changePicture1.backcolor=rgb(hsred.value,hsgreen.value,hsblue.value) End subHsred_changePicture1.backcolor=rgb(hsred.value,hsgreen.value,hsblue.value) End sub实验九文件Private Sub Command1_Click()Dim i As IntegerText1.Text = ""i = 1Open App.Path & "\Grade.txt" For Input As #1Do While Not EOF(1)Input #1, a(i)Text1.Text = Text1.Text & a(i) & Space(2)i = i + 1LoopClose #1End SubPrivate Sub Command2_Click()Dim i As Integer, s As Integers = 0For i = 1 To 30If a(i) = 100 Thens = s + 1End IfNext iText2.Text = sEnd SubDim s As StringText1.Text = ""Open App.Path & "\Infile.txt" For Input As #1 Do While Not EOF(1)Line Input #1, sText1.Text = Text1.Text & s & vbCrLfLoopClose #1End SubPrivate Sub Command2_Click()Dim a As Stringa = UCase(Text1.Text)Text1.Text = aOpen App.Path & "\Outfile.txt" For Output As #1 Print #1, aClose #1End SubPrivate Sub Command1_Click()Dim s As String, i As IntegerText1.Text = ""i = 1Open App.Path & "\Datain.txt" For Input As #1 Do While Not EOF(1)Input #1, a(i)Text1.Text = Text1.Text & a(i) & Space(2)i = i + 1LoopClose #1End SubPrivate Sub Command2_Click()Dim i As Integer, s As Integers = 0For i = 1 To 20If a(i) Mod 3 = 0 ThenText2.Text = Text2.Text & a(i) & Space(2)End IfNext iEnd SubDim s As StringText1.Text = ""Open App.Path & "\Dialog.txt" For Input As #1 Do While Not EOF(1)Line Input #1, sText1.Text = Text1.Text & s & vbCrLfLoopClose #1End SubPrivate Sub Command2_Click()Dim i As Integer, s As String, r As Integer r = 0For i = 1 To Len(Text1.Text)s = Mid(Text1.Text, i, 1)If Asc(s) >= 65 And Asc(s) <= 90 Thenr = r + 1End IfNext iText2.Text = rEnd SubPrivate Sub Command3_Click()Dim i As Integer, s As String, r As Integer r = 0For i = 1 To Len(Text1.Text)s = Mid(Text1.Text, i, 1)If Asc(s) >= 97 And Asc(s) <= 122 Thenr = r + 1End IfNext iText3.Text = rEnd SubFile1.Path = Dir1.PathEnd SubPrivate Sub Drive1_Change()Dir1.Path = Drive1.DriveEnd SubPrivate Sub File1_Click()Dim a As StringIf Right(File1.Path, 1) = "\" Thena = File1.Path + File1.FileNameElsea = File1.Path + "\" + File1.FileNameEnd IfText1.Text = aEnd Sub实验十界面设计Text1.locked=falseFSave.enable=trueEnd subFSave_clickText1.locked=tureFSave.enable=falseEnd sub2.dis_clicktext1.text=“计算机等级考试”end sub3.clea_clicktext1.text=“”end sub4.sqadd_clicklabel1.caption=(val(text1.text)^2)+(val(text2.text)^2) end subsqsub_clicklabel1.caption=(val(text1.text)^2)-(val(text2.text)^2) end submnuclean_clicktext1.text=“”text2.text=“”label1.caption=“”end sub4.Private Sub MnuRed_Click()Shape1.FillColor = vbRedEnd SubPrivate Sub MunBlue_Click()Shape1.FillColor = vbBlueEnd Sub5.Private Sub Command1_Click()Dim a As Integer, i As Integera = Text1.TextFor i = 1 To aIf Sqr(i) = Int(Sqr(i)) ThenList1.AddItem iEnd IfNext iEnd Sub制作人:102宿舍、尤昌波只供参考。

国家二级VB机试(上机操作)模拟试卷440(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷440(题后含答案及解析)

国家二级VB机试(上机操作)模拟试卷440(题后含答案及解析) 全部题型 2. 基本操作题 3. 简单应用题 4. 综合应用题基本操作题1.(1)在名称为:Form1的窗体上画一个标题为“直辖市”、名称为Framel 的框架,在框架中画一个名称为Combol的组合框,其编辑域为空,有如图所示的4个列表项,外观风格也与图中相同。

注意:存盘时必须存放在考生文件夹下,工程文件名为sjt1.vbp,窗体文件名为sjt1.frm。

(2)在名称为Form1的窗体上画一个名称为Command1、标题为“0”的命令按钮;再画一个名称为Timerl 的计时器,请通过属性窗口设置适当的属性,并编写适当的事件过程,使得程序运行时,单击命令按钮后,该按钮标题上的数字每2秒在原有基础上加2。

要求程序中不得使用变量,每个事件过程中只能写一条语句。

注意:存盘时必须存放在考生文件夹下,工程文件名为sit2.vbp,窗体文件名为sjt2.frm。

正确答案:(1)步骤1:新建一个窗体Form1。

步骤2:向窗体上添加一个Frame控件,并按照表4.13设置控件的属性。

步骤3:向Frame控件中添加一个ComboBox控件,按照表4.14设置控件的属性,设置完成后结果如图4.11所示。

步骤4:调试并运行程序,关闭程序后按题目要求存盘。

(2)步骤1:新建一个窗体Foiml。

步骤2:向窗体中添加一个命令按钮,按照表4.15设置控件的属性。

步骤3:向窗体中添加一个计时器控件,按钮表4.16设置控件的属性,设置完成后结果如图4.12所示。

步骤4:添加按钮的Click事件过程。

参考答案Private Sub Command1_Click( ) Timer1.Enaled=True End Sub 步骤5:添加计时器的Timer事件过程参考答案Private Sub Timerl_Timer( ) Command1.Caption=Val(Command1.Caption)+2 End Sub 步骤:6:调试并运行程序,关闭程序后按题目要求存盘。

VB期末考试上机题编程答案

VB期末考试上机题编程答案

VB期末考试上机题编程答案1。

新建一个工程,编写一个找出所有四位幸运数显示在列表框中,并将幸运数的个数显示在文本框中。

所谓幸运数是指凡前两位数字之和等于后两位数字之和的四位数.将原窗体文件和工程文件分别另存为为f.frm和p.vbp,保存在D盘的VBTest文件夹中。

如不按要求保存,造成文件无法上传,后果自负!具体要求:1、程序参考界面如图所示,编程时不得增加或减少界面对象或改变对象的种类,窗体及界面元素大小适中,且均可见;2、单击”查找"按钮,则开始查找并在列表框中显示结果,并在文本框中显示幸运数的个数;3、单击“清除”按钮,则将列表框和文本框清空;4、单击“退出"按钮,结束程序运行;5、程序中应包含一个过程,用于判断一个数是否是幸运数。

解:Private Sub Command1_Click()Dim i As Integer, a As IntegerFor i = 1000 To 9999If k(i) Then List1。

AddItem i: a = a + 1Next iText1.Text = aEnd SubPrivate Sub Command2_Click()List1。

ClearText1.Text = ”"End SubPrivate Sub Command3_Click()EndEnd SubPrivate Function k(n As Integer) As IntegerDim i As Integer, a As Integer, s1 As Integer, s2 As IntegerDim s As Strings = CStr(n)For i = 1 To Len(s) / 2s1 = s1 + Mid(s, i, 1)s2 = s2 + Mid(s, Len(s) + 1 - i, 1)Next iIf s1 = s2 Then k = TrueEnd Function2。

大学vb上机及课后习题答案实验1-2

大学vb上机及课后习题答案实验1-2

实验1.1.1 标签计算机等级考试True三号1实验1.1.2 200020012等级考试实验1.1.3 “”“”T2=T1实验1.1.4 改变按钮大小C1变宽C1.Width=C1.Width=100实验1.1.5 确认FalseFalseL1请确认C1是300800TrueC2否300800True实验1.1.6 列表框的使用北京山西辽宁浙江广东实验1.1.7 True3True3C1复制Text2=Text1实验1.1.8 计算机等级考试C1移动Text1.Left=0实验1.1.9 程序设计三号2粗体斜体TrueTrue实验1.2.1 计算机等级考试对齐方式字体左对齐居中右对齐宋体黑体Text1.Alignment=2Text1.Alignment=1“宋体”Text1.FontName=”黑体”实验1.2.2 选课CH1数学CH2语文CH3外语CH4计算机1实验1.2.3 20003000FalseCmd1显示图片Cmd2隐藏图片LoadPicture(App.Path&”\图片1.jpg”) LoadPicture(“”)实验1.2.4 FalseC:\VB\Sy02\图片2.jpg设置属性100240020020Picture1.Height=VScroll1.Value实验1.2.5 11001HScroll1.SetFocusText1=HScroll1.Value实验1.2.6 图形控件L11 2 3 4 5Shape1.Shape=L1.Text实验1.2.7 图形控件图形红色边框Shape1.Shape=3&HFF&实验1.2.8True“”三号1000Label1.Caption=Now。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第一题
1.制作如图所示窗体界面。

(用真实的姓名、班级及学号)
2.使时间每隔1秒刷新一次
3.单击“最大值”命令按钮时,算出通过键盘输入的5个数的最大

4.在列表框中输入20、22、24、26、28
Private Sub Command1_Click()
Dim a(1 To 5) As Integer
For i = 1 To 5
a(i) = InputBox("please input a number")
Next i
mmax = a(1)
For i = 1 To 5
If a(i) > mmax Then
mmax = a(i)
End If
Next i
MsgBox mmax
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Time
End Sub
第二题
1.两个文本框里输入两个数字从而确定一个范围。

2.单击“计算”按钮求出这个范围中能被3或5整除的数的平方和,
结果显示在label3中。

bel3的背景色每隔1.5秒蓝红交替。

Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
a = Text1.Text
b = Text2.Text
s = 0
For i = a To b
If a Mod 3 = 0 Or b Mod 5 = 0 Then
Label3.Caption = Label3.Caption & i & ","
s = s + i * i
End If
Next i
Label3.Caption = s
End Sub
Private Sub Timer1_Timer()
If Label3.BackColor = vbRed Then
Label3.BackColor = vbBlue
Else
Label3.BackColor = vbRed
End If
End Sub
第三题
1、单击按钮,在文本框中显示1到终值的所有整数的平方和
2、单击生成列表按钮,在列表框中显示1到终值之间的所有整数
Private Sub Command1_Click()
Dim a As Integer
a = Text1.Text
s = o
For i = 1 To a
s = s + i * i
Next i
Text2.Text = s
End Sub
Private Sub Command2_Click()
Dim a As Integer
a = Text1.Text
For i = 1 To a
List1.AddItem i
Next i
End Sub
第四题
1、“大家好”的背景颜色红蓝黄交替,单击“停止”按钮时停止
颜色变化
2、在文本框中写入任意数字,单击“生成列表”按钮,将1到文
本框中输入数字之间所有能被3整除得数在列表框中显示
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Dim a As Integer
a = Text1.Text
For i = 1 To a
If i Mod 3 = 0 Then
List1.AddItem i
End If
Next i
End Sub
Private Sub Timer1_Timer()
If Label1.ForeColor = vbRed Then
Label1.ForeColor = vbBlue
ElseIf Label1.ForeColor = vbBlue Then
Label1.ForeColor = vbYellow
Else: Label1.ForeColor = vbRed
End If
End Sub
第五题
1、“大家好”电子滚动平当单击按钮“开始”时从左向右滚动,
当滚动到屏幕最右端的时候,从新回到最左端开始滚动;单击“停止”按钮时停止滚动
2、在文本框中写入任意内容,单击“添加”按钮可以将文本框中
的内容加入到列表框中
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
List1.AddItem Text1.Text
End Sub
Private Sub Timer1_Timer()
Label1.Left = Label1.Left + 100
If Label1.Left > Form1.Width - Label1.Width Then
Label1.Left = 0
End If
End Sub
第六题
1、标签中写入“大家好”,每秒钟“大家好”和“哈哈”交替出
现(即,第一秒出现“大家好”。

第二秒出现“哈哈”依次交替)
2、提示:使用计时器控件完成交替出现
3、两个文本框中任意输入数字,当单击“显示”按钮,在标签2
中显示数值大的数,如果输入的数值相同,在标签2中显示“数值相等”。

Private Sub Command1_Click()
If Text1.Text > Text2.Text Then
Label2.Caption = Text1.Text
Else
If Text1.Text = Text2.Text Then
Label2.Caption = "数值相等"
Else
Label2.Caption = Text2.Text
End If
End If
End Sub
Private Sub Timer1_Timer()
If Label1.Caption = "大家好" Then
Label1.Caption = "哈哈"
Else
Label1.Caption = "大家好"。

相关文档
最新文档