2009秋VB05上机答案
国家二级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:按要求将文件保存至考生文件夹中。
VB2005课后习题解答
第三章1.Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim min As IntegerDim max As IntegerDim r1, r2, r3 As Integermin = Val(TextBox1.Text)max = Val(TextBox2.Text)If (max > min) ThenRandomize()r1 = CInt(Rnd() * Int(max - min + 1) + min)TextBox3.Text = r1r2 = CInt(Rnd() * Int(max - min + 1) + min)TextBox4.Text = r2r3 = CInt(Rnd() * Int(max - min + 1) + min)TextBox5.Text = r3End IfEnd Sub2.Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i As IntegerDim j, m, n, h, f, g As Integeri = TextBox1.Textj = i \ 100m = (i - j * 100) \ 50n = (i - j * 100 - m * 50) \ 20h = (i - j * 100 - m * 50 - n * 20) \ 10f = (i - j * 100 - m * 50 - n * 20 - h * 10) \ 5g = (i - j * 100 - m * 50 - n * 20 - h * 10 - f * 5) \ 1TextBox2.Text = jTextBox3.Text = mTextBox4.Text = nTextBox5.Text = hTextBox6.Text = fTextBox7.Text = gEnd SubEnd Class8.Public Class Form1Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChangedDim h, m As StringDim i As Integeri = ComboBox1.TextIf i = 1 Thenh = "星期一"m = "Monday"ElseIf i = 2 Thenh = "星期二"m = "Tuesday"ElseIf i = 3 Thenh = "星期三"m = "Wednesday"ElseIf i = 4 Thenh = "星期四"m = "Thursday"ElseIf i = 5 Thenh = "星期五"m = "Friday"ElseIf i = 6 Then h = "星期六" m = "Saturday"Elseh = "星期日" m = "Sunday"End IfTextBox1.Text = h TextBox2.Text = mEnd SubEnd Class9.Public Class Form1Public a As DatePublic b, c, d As IntegerDim ch As StringPrivate Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChangedb = Hour(a)If RadioButton1.Checked = True ThenIf b <= 12 And c < 0 Thench = "上午"ElseIf b >= 12 And c >= 0 Thenb = b - 12ch = "下午"End IfEnd IfLabel3.Text = b & ":" & c & ":" & d & chEnd SubPrivate Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChangeda = CDate(TextBox1.Text)If CheckBox1.Checked = True ThenLabel1.Visible = TrueLabel1.Text = CStr(Format(a, "yyyy年MM月dd日"))End IfEnd SubPrivate Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChangeda = CDate(TextBox1.Text)If CheckBox2.Checked = True ThenLabel3.Visible = Trueb = Hour(a) :c = Minute(a) :d = Second(a)End IfEnd SubPrivate Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChangeda = CDate(TextBox1.Text)If CheckBox1.Checked = True ThenLabel2.Visible = TrueLabel2.Text = CStr(Format(a, "dddd"))End IfEnd SubPrivate Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChangedb = Hour(a)If RadioButton2.Checked = True ThenIf b <= 12 And c <= 0 Thench = "上午"ElseIf b >= 12 And c >= 0 Thench = "下午"End IfEnd IfLabel3.Text = b & ":" & c & ":" & d & chEnd SubEnd Class14.Public Class Form1Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i, j As DoubleFor i = 1 To 500For j = i + 1 To 500If Math.Sqrt(i + j) = Fix(Math.Sqrt(i + j)) And Math.Sqrt(j - i) = Fix(Math.Sqrt(j - i)) ThenListBox1.Items.Add("自然数对:" & i & " " & j)End IfNextNextEnd SubEnd Class16.Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i As IntegerFor i = 1 To 1000If IsPerfect(i) = True ThenPerfect = Perfect & " " & iEnd IfNext iTextBox1.Text = "1到的完备数有:" & Chr(13) & PerfectEnd SubFunction IsPerfect(ByVal n As Long) As BooleanDim i As LongDim x As LongFor i = 1 To Int(n / 2)If n Mod i = 0 Thenx = x + iEnd IfNextIf x = n ThenIsPerfect = TrueElseIsPerfect = FalseEnd IfEnd FunctionEnd Class第四章6.Public Class Form1Dim A(4, 4) As IntegerDim B(4, 4) As IntegerDim C(4, 4) As IntegerPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim i, j As IntegerRandomize()For i = 0 To 4For j = 0 To 4A(i, j) = Int(Rnd() * 90) + 10myString = myString & CStr(A(i, j)) & " "NextmyString = myString & Chr(10)ListBox1.Items.Add(myString)myString = ""NextmyString = ""For i = 0 To 4For j = 0 To 4B(i, j) = Int(Rnd() * 90) + 10myString = myString & CStr(B(i, j)) & " "NextmyString = myString & Chr(10)ListBox2.Items.Add(myString)myString = ""NextEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i, j As IntegerDim myString As String = ""For i = 0 To 4For j = 0 To 4C(i, j) = A(i, j) + B(i, j)myString = myString & CStr(C(i, j)) & " "NextmyString = myString & Chr(10)ListBox3.Items.Add(myString)myString = ""NextEnd SubEnd Class8.Public Class Form1Dim student(9, 1) As StringDim i As Integer = 0Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Clickstudent(i, 0) = TextBox1.Textstudent(i, 1) = TextBox2.TextListBox1.Items.Add(student(i, 0) & Space(2) & student(i, 1))ListBox1.Refresh()i = i + 1If i > 9 ThenButton1.Enabled = FalseEnd IfEnd SubPrivate Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChangedSelect Case ComboBox1.SelectedItemCase Is = "及格"ListBox2.Items.Clear()For i = 0 To 9If student(i, 1) >= 60 ThenListBox2.Items.Add(student(i, 0) & Space(2) & student(i, 1)) End IfNextCase Is = "不及格"ListBox2.Items.Clear()For i = 0 To 9If student(i, 1) < 60 ThenListBox2.Items.Add(student(i, 0) & Space(2) & student(i, 1)) End IfNextEnd SelectEnd SubEnd Class10Public Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadCheckedListBox1.Items.Add("方便面 1.5")CheckedListBox1.Items.Add("口香糖 1.0")CheckedListBox1.Items.Add("火腿肠 1.2")CheckedListBox1.Items.Add("优酸乳 2.8")CheckedListBox1.Items.Add("可乐 1.4")CheckedListBox1.Items.Add("瓜子 3.0")CheckedListBox1.Items.Add("牙膏 2.1")CheckedListBox1.Items.Add("洗衣粉 5.8")End SubPrivate Sub MixedControls_Click(ByVal sender As System.Object, ByVal e As _System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click Dim i, j As IntegerSelect Case DirectCast(sender, Button).NameCase For i = 0 To CheckedListBox1.CheckedItems.Count - 1If CheckedListBox1.CheckedItems.Count <> 0 ThenFor j = 0 To CheckedListBox1.CheckedItems.Count - 1CheckedListBox2.Items.Insert(j,CheckedListBox1.CheckedItems(i).ToString)CheckedListBox1.Items.RemoveAt(i)Next jEnd IfNext iIf CheckedListBox1.Items.Count = 0 ThenButton1.Enabled = FalseButton2.Enabled = FalseEnd IfButton3.Enabled = TrueButton4.Enabled = TrueCase For i = 0 To CheckedListBox1.Items.Count - 1CheckedListBox2.Items.Add(CheckedListBox1.Items.Item(i)) NextCheckedListBox1.Items.Clear()Button1.Enabled = FalseButton2.Enabled = FalseButton3.Enabled = TrueButton4.Enabled = TrueCase For i = 0 To CheckedListBox1.CheckedItems.Count - 1If CheckedListBox2.CheckedItems.Count <> 0 ThenFor j = 0 To CheckedListBox2.CheckedItems.Count - 1 CheckedListBox1.Items.Insert(j,CheckedListBox2.CheckedItems(i).ToString)CheckedListBox2.Items.RemoveAt(i)Next jEnd IfNext iIf CheckedListBox1.Items.Count = 0 ThenButton1.Enabled = FalseButton2.Enabled = FalseEnd IfButton3.Enabled = TrueButton4.Enabled = TrueCase For i = 0 To CheckedListBox2.Items.Count - 1CheckedListBox1.Items.Add(CheckedListBox2.Items.Item(i))NextCheckedListBox2.Items.Clear()Button1.Enabled = TrueButton2.Enabled = TrueButton3.Enabled = FalseButton4.Enabled = FalseEnd SelectEnd SubEnd Class12.Public Class Form1Public Enum colorsBlue = 1Green = 2Black = 3Red = 4Yellow = 5End EnumPrivate Sub MixedControls_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click, Label2.Click, Label3.Click, Label4.Click, Label5.ClickDim label_colors As colorsDim i As IntegerSelect Case DirectCast(sender, Label).NameCase label_colors = CType(Label1.TabIndex, colors)Case label_colors = CType(Label2.TabIndex, colors)Case label_colors = CType(Label3.TabIndex, colors)Case label_colors = CType(Label4.TabIndex, colors)Case label_colors = CType(Label5.TabIndex, colors)End SelectSelect Case label_colorsCase Is = colors.BlueLabel1.BackColor = Color.BlueCase Is = colors.GreenLabel2.BackColor = Color.GreenCase Is = colors.BlackLabel3.BackColor = Color.BlackCase Is = colors.RedLabel4.BackColor = Color.RedCase Is = colors.YellowLabel5.BackColor = Color.YellowEnd SelectEnd SubEnd Class6.Public Class Form1Function fact(ByVal n As Integer) As IntegerFor n = 1 To 30Randomize()fact = CInt(Int(100 - 1 + 1) * Rnd() + 1)ListBox1.Items.Add(CStr(fact))NextEnd FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickfact(30)End SubEnd Class7Public Class Form1Function fact1(ByVal n As Integer) As Integer Dim i, j, k As Integeri = TextBox1.Textj = TextBox2.TextIf i > j Thenk = jElse : k = iEnd IfWhile (i Mod k <> 0 Or j Mod k <> 0)k = k - 1End WhileTextBox3.Text = kEnd FunctionFunction fact2(ByVal n As Integer) As IntegerDim a, b, c As Integera = TextBox1.Textb = TextBox2.TextIf a > b Thenc = aElse : c = bEnd IfWhile (c Mod a <> 0 Or c Mod b <> 0)c = c + 1End WhileTextBox4.Text = cEnd FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickfact1(1)fact2(1)End SubEnd Class8Public Class Form1Function fact(ByVal n As Integer) As IntegerDim i As IntegerFor i = 1000 To 9000If i Mod 17 = 0 And i Mod 37 = 0 Thenfact = iListBox1.Items.Add(CStr(fact))End IfNextEnd FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickfact(1)End SubEnd Class9Public Class Form1Function fact(ByVal n As Integer) As IntegerDim i, total, j As Integerfact = 1For j = 2 To 10total = 1For i = 1 To jtotal = total * iNextfact += totalNextTextBox1.Text = factEnd FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickfact(1)End SubEnd Class10Public Class Form1Public Sub count()Dim chSub As CharDim strIn As StringDim i As IntegerDim dx, xx, sz, qt As Integer strIn = TextBox1.TextFor i = 0 To strIn.Length - 1 chSub = strIn.Chars(i)Select Case chSubCase"A"To"Z"dx = dx + 1Case"a"To"z"xx = xx + 1Case"1"To"9"sz = sz + 1Case Elseqt = qt + 1End SelectNextTextBox2.Text = dxTextBox3.Text = xxTextBox4.Text = szTextBox5.Text = qtEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickcount()End SubEnd Class13Public Class form1Dim h, w As IntegerPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Loadh = PictureBox1.Heightw = PictureBox1.WidthEnd SubPrivate Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e _As System.EventArgs) Handles NumericUpDown1.ValueChangedPictureBox1.Height = h * NumericUpDown1.Value * 0.1PictureBox1.Width = w * NumericUpDown1.Value * 0.1End SubPrivate Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e _As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMoveMe.Cursor = Cursors.WaitCursorEnd SubEnd Class。
全国计算机VB上机题库及答案(全)
全国计算机等级考试二级VB上机考试新版题库及解析【2013年3月考试专用】考前复习必看资料:PiaoMo整理—1—第一套上机题题干166一、基本操作题请根据以下各小题的要求设计Visual Basic 应用程序(包括界面和代码)。
(1)在名称为Form1的窗体上建立一个名称为Command1的命令按钮数组,含三个命令按钮,它们的Index 属性分别为0、1、2,标题依次为"是"、"否"、"取消",每个按钮的高、宽均为300、800。
窗体的标题为"按钮窗口"。
运行后的窗体如图1所示。
注意:存盘时必须存放在考生文件夹下,工程文件名为sjt1.vbp ,窗体文件名为sjt1.frm 。
图1【操作步骤】步骤1:新建一个"标准EXE"工程,如表1在窗体中用"复制"和"粘贴"画出控件数组并设置属性。
表1(2)在名称为Form1的窗体上画一个名称为Sha1的形状控件,然后建立一个菜单,标题为"形状",名称为shape0,该菜单有两个子菜单,其标题分别为"正方形"和"圆形",其名称分别为shape1和shape2,如图2所示,然后编写适当的程序。
程序运行后,如果选择"正方形"菜单项,则形状控件显示为正方形;如果选择"圆形"菜单项,则窗体上的形状控件显示为圆形。
注意:程序中不能使用变量,每个事件过程中只能写一条语句。
保存时必须存放在考生文件夹下,工程文件名为sjt2.vbp ,窗体文件名为sjt2.frm 。
图2【操作步骤】步骤1:新建一个"标准EXE"工程,在窗体Form1中画一个名为Sha1的形状控件。
步骤2:选择【工具】→【菜单编辑器】命令,打开菜单设计器,如表2中的设置建立菜单项。
全国计算机二级VB上机试题库[题+答案]
一、基本操作题下面出现的“考生文件夹”均为c:\wexam\20060001。
请根据以下各小题的要求设计Visual Basic应用程序(包括界面和代码)。
1.在窗体上建立一个二级菜单,该菜单含有“文件”和“帮助”两个主菜单项(名称分别为vbFile和vbHelp),其中“文件”菜单包括“打开”、“关闭”和“退出”三个子菜单项(名称分别为vbOpen、vbClose和vbExit)。
只建立菜单,不必定义其事件过程。
注意:保存时必须存放在考生文件夹下,窗体文件名为kt1.frm,工程文件名为kt1.vbp。
2.在名称为Form1的窗体上建立两个名称分别为Cmd1和Cmd2、标题分别为“喜欢”和“不喜欢”的命令按钮。
编写适当的事件过程,要求程序运行后,如果单击“喜欢”命令按钮,则在窗体上显示“数理化”;如果单击“不喜欢”命令按钮,则在窗体上显示“政史地”。
程序中不能使用任何变量,直接显示字符串。
注意:保存时必须存放在考生文件夹下,窗体文件名为kt2.frm,工程文件名为kt2.vbp。
一、基本操作题答案1.【解题步骤】(1)打开“菜单编辑器”。
(2)菜单设计见表4-1。
表4-1标题名称内缩符号文件vbFile 0打开vbOpen 1关闭vbClose 1退出vbExit 1帮助vbHelp 0(3)按要求设计含有“文件”和“帮助”的菜单栏。
(4)为“文件”菜单设计“打开”、“关闭”和“退出”三个子菜单项。
(5)设计完成之后,按规定方式存盘。
2.【解题步骤】(1)建立界面和控件并设置控件属性。
程序中用到的控件及其属性见表4-2。
表4-2控件属性设置值按钮Name Cmd1Caption 喜欢按钮Name Cmd2Caption 不喜欢(2)编写程序代码。
参考代码:Private Sub Cmd1_Click()Print"数理化"End SubPrivate Sub Cmd2_Click()Print"政史地"End Sub(3)调试并运行程序。
VB语言程序设计课后编程及上机调试参考答案
V B语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = "练习"= "确定"= True= True= "Visual Basic程序设计教程"End Subex0102Private Sub Command1_Click()= "我有电脑"End SubPrivate Sub Command2_Click()= "我没有电脑"End SubPrivate Sub Command3_Click()= "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val= 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler =s = * r ^ 2= "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮= 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮= 0 '还原Private Sub Command3_Click() '"最小化"按钮= 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Valy = Val= x * x + y * yEnd Subex0206Private Sub command1_click()Dim x As Stringx == Left(x, 1) + Right(x, 1)End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integerx = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数 Showy = c * 100 + b * 10 + a '生成倒序数 Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = ValRandomizex = Int(1 + n * Rnd)= "第一个随机数" + Str(x)x = Int(1 + n * Rnd)= "第二个随机数" + Str(x)x = Int(1 + n * Rnd)= "第三个随机数" + Str(x)ex0303Private Sub Cmd1_Click()= True= "您已下达显示命令"End SubPrivate Sub Form_Click()= TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Subex0305Private Sub Form_Load()x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 3 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 2 + 16 + 0, "请确认") End Subex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Valb = Valc = Vald = ValIf a > b Then '求a、b中的较大数 m = aElsem = bEnd IfIf c > d Then '求c、d中的较大数 n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数 x = mElsex = nEnd If= xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As Stringt = Mid, 5, 1)Select Case tCase "2"p = "博士生"Case "3"p = "硕士生"Case "4"p = "本科生"Case "5"p = "专科生"Case Elsep = "无效学号"End Select= Left, 2) + "级"= pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If = 1 Thenr = 255End IfIf = 1 Theng = 255End IfIf = 1 Thenb = 255End If= RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()= "0"= 1= 1= 22= "黑体"= 1000End SubPrivate Sub TimClk_Timer()= Val + 1End Subex0406Private Sub Form_Load()= False= FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If > 0 Then= TrueEnd IfEnd SubPrivate Sub Command1_Click()= True= TrueEnd SubPrivate Sub Command2_Click()== False= FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100范围内的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + / 10End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = : y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext k= yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To - 1 '逐项判断If (i) Then '真时为选定Print (i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + dy = b * 1000 + a * 100 + a * 10 + cz = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数 a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Thens = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As IntegerShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数 a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数 max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click()Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数 n = max(c, d) '求c、d中的较大数 Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(k).Text)Next kCall Max(d(0), d(1), d(2), m)Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m)= mEnd Subex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox("输入一个数"))Print x; "的位数为:"; fnws(x)End SubFunction fnws(x As Long) As IntegerDim n As Integern = 1Do While x \ 10 > 0n = n + 1x = x \ 10Loopfnws = nEnd Functionex0705Private Sub C1_Click()End Subex0705APrivate Sub C2_Click()End Subex0706Dim n As IntegerPrivate Sub Command1_Click()usern = Trimpassw = TrimIf usern = "username" And passw = "password" ThenElsen = n + 1If n = 3 ThenEnd IfEnd If= ""= ""End Subex0706APrivate Sub Command1_Click()End Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出 For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符Elsek = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII码比数字大7Print Chr(k + 48); '以字符格式输出Next jPrint '换行Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() '“产生原稿文”按钮Randomizes = ""For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) '随机产生小写字母s = s + xNext k= s '显示在文本框中= ""= False '允许录入'设置焦点= ""= ""f = 0 '第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() '“结束”按钮EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)Dim c As Integer, k As IntegerIf f = 0 Then '第1次按键时,开始计时t = Timer '用t保存第1次按键的时间 f = 1 '1表示已按键和进入录入过程 End IfIf Len < 30 Then= Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid, k, 1) = Mid, k, 1) Thenc = c + 1End IfNext k= True '禁止录入= Round(c / 30 * 100, 2) & "%" '显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open "静夜思.txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xxLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '"产生随机数"For i = 1 To 20d(i) = Int(1 + 99 * Rnd)d(i)Next iEnd SubPrivate Sub Command2_Click() '"保存"Open "" For Output As #1For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出"Open "" For Input As #1Do While Not EOF(1)Input #1, xxLoopClose #1End SubPrivate Sub Command4_Click() '"结束"EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\"End IfMsgBox "操作完毕!"End Subex1002Private Sub A1_Click()= vbRedEnd SubPrivate Sub A2_Click()= vbBlueEnd SubPrivate Sub A3_Click()= vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()= "选择文件"= "文本文件|*.txt"= "C:\"=End SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)= Round(2 * * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integerr == "=" & rCall calzc(r)End SubPrivate Sub Form_Load()= 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp") Next kEnd SubPrivate Sub Image1_Click(Index As Integer)= 20Select Case IndexCase 0"箭头向上"Case 1"箭头向左"Case 2"箭头向右"Case 3"箭头向下"End SelectEnd Sub。
VB语言程序设计课后编程及上机调试参考答案
V B 语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = " 练习 "Command1.Caption = " 确定 "Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = "Visual BasicEnd Sub ex0102Private Sub Command1_Click()Txt.Text = " 我有电脑 "End SubPrivate Sub Command2_Click()Txt.Text = " 我没有电脑 " EndSub程序设计教程Private Sub Command3_Click()Txt.Text = "" ' 一对双撇号,中间不留空 End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Sub ex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r A 2Text1.Text = " 圆的面积为 " & sEnd Subex0204Private Sub Command1_Click() '"Form1.WindowState = 2 ' End Sub最大化 " 按钮最大化Private Sub Command2_Click() '"Form1.WindowState = 0 '还原 "按钮还原End SubPrivate Sub Command3_Click() '"Form1.WindowState = 1 '最小化 " 按钮最小化End Sub ex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * y End Sub ex0206Private Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1)End Sub ex0301 Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integer x = Val(InputBox(" 请输入一个三位数 "))a = Int(x / 100) ' 求百位数b = Int(x / 10) - a * 10 ' 求十位数c = x Mod 10 ' 求个位数Showy = c * 100 + b * 10 + a ' 生成倒序数Print x; " 倒序数为: "; y ' 显示倒序数End Sub ex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = Int(1 + n *Rnd) Label1.Caption 第一个随机数" + Str(x)x = Int(1 + n *Rnd)Label2.Caption = " 第二个随机数" +Str(x)x = Int(1 + n *Rnd)Label3.Caption = " 第三个随机数" +Str(x)End Sub ex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = " 您已下达显示命令 "End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer)ShowPrint " 输入字符: "; Chr(KeyAscii), "ASCII 码为 ;"; KeyAscii End SubPrivate Sub Form_DblClick()ClsEnd Sub ex0305 Private Sub Form_Load()x = MsgBox(" 在这里显示提示信息 ", 4 + 0, " 请确认 ")x = MsgBox(" 在这里显示 " + Chr(13) + " 提示信息 ", 3 + 0, " x = MsgBox(" 在这里显示 " + Chr(13) + " 提示信息 ", 2 + 16 + 0,End Sub ex0401Private Sub Form_Load()Dim x As Long, s As Stringx = In putBox(" 输入一个整数(1 〜35000)")s = " 奇数"If x Mod 2 = 0 Then s = " 偶数"MsgBox s End Sub ex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As SingleShowa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)If a > b Then ' 求 a、b 中的较大数m = aElsem = bEnd IfIf c > d Then ' 求 c、d 中的较大数n = cElsen = dEnd IfIf m > n Then ' 求 m、n 中的较大数x = mElsex = nEnd IfText5.Text = x 请确认")请确认")End Subex0403Private Sub Command1_Click()Dim t As String, p As String t = Mid(Text1.Text, 5, 1) Select Case tCase "2"p = " 博士生 "Case "3"p = " 硕士生 "Case "4"p = " 本科生 "Case "5"p = " 专科生 "Case Elsep = " 无效学号 "End SelectText2.Text = Left(Text1.Text, 2) + "Text3.Text = pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.FontSize = 22LabClk.FontName = " 黑体 "TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1End Sub ex0406 Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Text1.SelLength > 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = FalseEnd Sub ex0501 Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integers = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1 〜100范围内的奇数和:";sEnd Sub ex0502 Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k)Next kPrint Int(s * 10 + 0.5) / 10End Sub ex0503 Private Sub Form_Load()Showk = 2Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As IntegerDim c As Integer, n As IntegerShown = 0Print " 三位数的水仙花数是: "For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k Then Print kn = n + 1End IfNext kPrint " 一共有 " & n & " 个水仙花数 "End Sub ex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click()FontSize = 12ClsFor i = 0 To List1.ListCount -1If List1.Selected(i) Then 'Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c y = b * 1000 + a * 100 + a z = d * 100 + d * 10 + a If x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & d End IfNext dNext cNext bNext aEnd Sub ex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As Integer RandomizeFor i = 1 To 10 a(i) = Int(Rnd * 90 + 10) Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10 If a(k) < min Then min = a(k) pos = k 10 + d 10 + c 显示 "按钮单击事件逐项判断 真时为选定Next kPrint " 最小数: "; min, " 位置: "; posEnd Sub ex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8 c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Sub ex0603 Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As IntegerDim h As Integer, n As Integern = Val(InputBox(" 请输入数组个数 n: "))ReDim d(n)ShowPrint " 处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To m h = n - k + 1 t = d(h): d(h) = d(k): d(k) = t Next kPrint " 处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As IntegerShown = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) ' 产生一个随机数a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint " 所有元素之和; "; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint " 第 "; i; " 行元素之和; "; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint " 主对角线元素之和; "; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Then s = s + a(i, j)End IfNext jNext iPrint " 所有靠边元素之和; "; sEnd Sub ex0605 Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As Integer Show Randomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) 'a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then 'max = a(i, j): r = i: c = jEnd IfNext j, iPrint " 最大值为: "; maxPrint " 位于行: "; r, " 列: "; c End Sub ex0606 Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = True End SubPrivate Sub Form_Load()n = 1End Sub ex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd)k = 1Do While k < 20x = Int(10 + 90 * Rnd) 产生一个随机数判断有无更大数For j = 1 To kIf x = a(j) Then f = 1 Exit ForEnd IfNext jIf f = 0 Thenk = k + 1 a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Sub ex0701Private Sub Form_Click() Dim s As Long s = 0For k = 1 To 10 s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As LongDim t As Longt = 1For k = 1 To nt = t * kNext kjc = tEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As Single Dim d As Single, m As Single, n As Single Showa = Val(InputBox(" 输入第 1 个数 "))b = Val(InputBox(" 输入第 2 个数 "))c = Val(InputBox(" 输入第 3 个数"))d = Val(InputBox(" 输入第 4 个数 "))m = max(a, b) 'n = max(c, d) 'Print " 最大数为: " & max(m, n) End SubFunction max(x, y) As SingleIf x > y Then max = xElsemax = y 求a、 b 中的较大数求c、 d 中的较大数求m、n 中的较大End Function ex0703Private Sub Command1_Click()Dim d(5) As Single, m As SingleFor k = 0 To 5d(k) = Val(Text1(k).Text) Next kCall Max(d(0), d(1), d(2), m)Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m) Text2.Text = mEnd Sub ex0704Private Sub Form_Load() Dim x As Long Showx = Val(InputBox(" 输入一个数 "))Print x; " 的位数为: "; fnws(x) End SubFunction fnws(x As Long) As Integer Dim n As Integer n = 1 Do While x \ 10 > 0n = n + 1x = x \ 10 Loop fnws = nEnd Function ex0705Private Sub C1_Click()Form1.HideEnd Sub ex0705APrivate Sub C2_Click()Form1.ShowEnd Sub ex0706 Dim n As IntegerPrivate Sub Command1_Click()usern = Trim(Text1.Text)passw = Trim(Text2.Text)If usern = "username" And passw = "password" Then Form1.HideForm2.ShowElsen = n + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Sub ex0802 Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); ' For j = 1 To 2 * i - 1 'If j <= i Then 'k = j 'Elsek = 2 * i - j 'End IfIf k > 9 Then k = k + 7 ' Print Chr(k + 48); 'Next jPrint ' 输出当前行左边的空格,分号表示下一输出项紧接输出输出2*i-1 个字符按左、右两边指定输出字符左边输出的字符右边输出的字符字母的ASCII 码比数字大7 以字符格式输出换行End SubDim t As Single, f As IntegerPrivate Sub Command1_Click()RandomizeIII! For k = 1 To 30If Mid(Text1.Text, k, 1) = Mid(Text2.Text, k, 1) Then c = c + 1End IfNext k Text2.Locked = True ' 禁止录入Text4.Text = Round(c / 30 * 100, 2) & "%" ' 显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open " 静夜思 .txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Sub ex0902 产生原稿文”按钮x = Chr(Int(Rnd * 26) + 97) 's = s + xNext kText1.Text = s 'Text2.Text = ""Text2.Locked = False 'Text2.SetFocus 'Text3.Text = ""Text4.Text = ""f = 0 'End SubPrivate Sub Command2_Click()' EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer,Dim c As Integer, k As IntegerIf f = 0 Then' t = Timer' f = 1'1 End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "Elsec = 0For k = 1 To 30 ' 随机产生小写字母 显示在文本框中 允许录入 设置焦点 第 1 次按键标记, 0 表示未按键 “结束”按钮 As Integer) 第 1 次按键时,开始计时 用t 保存第1次按键的时间 表示已按键和进入录入过程 秒 " ' 显示用户当前所用时间统计录入正确的字母个数Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '" 产生随机数 "For i = 1 To 20 d(i) = Int(1 + 99 * Rnd) List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() '" 保存 "Open "MyFile4.txt" For Output As #1For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '" 读出 "Open "MyFile4.txt" For Input As #1Do While Not EOF(1) Input #1, x List2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '" 结束 "EndEnd Sub ex0903 Private Sub Form_Load()ShowFor k = 1 To 6第 7 章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & " 未编写!! " ElsePrint Mid(fn, 4) & " 已编写!! " End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir" If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox " 操作完毕! "End Subex1002Private Sub A1_Click()Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = " 选择文件 " CommonDialog1.Filter = " 文本文件 |*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2)End SubPrivate Sub HV_Scroll()Dim r As Integer r = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3 Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture(" 箭头 " & k + 1 & ".bmp")Next kEnd SubPrivate Sub Image1_Click(Index As Integer) Picture1.ClsSelect Case IndexCase 0Picture1.Print "Case 1箭头向上 "Picture1.Print " Case 2Picture1.Print " Case 3 箭头向左 " 箭头向右 "Picture1.Print "End SelectEnd Sub箭头向下 "。
VB语言程序设计课后编程及上机调试参考答案
For k = 100 To 999 a = Int(k / 100) b = Int((k - 100 * a) / 10) c = k Mod 10 If a * a * a + b * b * b + c * c *;1 End If
Next k Print " 一共有 " & n & " 个水仙花数 " End Sub
程序设计教程 "
ex0102
Private Sub Command1_Click()
Txt.Text = "
我有电脑 "
End Sub
Private Sub Command2_Click()
Txt.Text = "
我没有电脑 "
End Sub
Private Sub Command3_Click()
Txt.Text = "" '
s=s+k Next k Show Print "1 ~100 范围内的奇数和: "; s End Sub
ex0502 Private Sub Form_Load()
Dim s As Single Show s=0 For k = 1 To 200
s = s + k / (1 + k * k) Next k Print Int(s * 10 + 0.5) / 10 End Sub
x = Mid(s, k, 1) t = UCase(x) If t >= "A" And t <= "Z" Then
y=y+x End If Next k Text2.Text = y End Sub
09年6月正式会考vb操作题答案
========完善程序题(1).打开Z:\“VB \429”文件夹中的文件:“” 进行以下操作后并保存!在VB 代码窗口指定位置修改完善程序代码实现,求1×2+2×3+3×4+4×5+5×6 的值。
(2)打开Z:\“VB \435”文件夹中的文件:“” 进行以下操作后并保存!在VB 代码窗口指定位置修改完善程序代码实现,求657687981091-----的值。
答案:运行结果:答案:运行结果:答案:(3)打开Z:\“VB \426”文件夹中的文件:“” 进行以下操作后并保存!在VB 代码窗口指定位置修改完善程序代码实现,求1×2×3×4×……×10的值。
(4)打开Z:\“VB \417”文件夹中的文件:“” 进行以下操作后并保存!在VB代码窗口指定位置修改完善程序代码实现,求10191817161514131211+++++++++的值。
运行结果:答案:答案:运行结果:(5)打开Z:\“VB \432”文件夹中的文件:“” 进行以下操作后并保存!在VB代码窗口指定位置修改完善程序代码实现,求1011910897867564534232+++++++++的值。
=======界面设计题:新建一个VB 工程,工程文件名称为:“工程”,并添加一个窗体文件:“”,保存在Z:\下的VB 文件夹下的425文件夹下。
按下表的要求添加控件,并设置其属性,操作后保存!新建一个VB 工程,工程文件名称为:“工程”,并添加一个窗体文件:“”,保存在Z:\下的VB 文件夹下的431文件夹下。
进行如下操作后并保存! 按下表的要求添加控件,并设置其属性,操作后保存!运行结果:答案:新建一个VB工程,工程文件名称为:“工程”,并添加一个窗体文件:“”,保存在Z:\下的VB 文件夹下的416文件夹下。
按下表的要求添加控件,并设置其属性,操作后保存!新建一个VB工程,工程文件名称为:“工程”,并添加一个窗体文件:“”,保存在Z:\下的VB 文件夹下的434文件夹下。
2009年秋至2010年秋江苏省计算机二级VB考试真题及参考答案
2009秋VB考试真题及参考答案第一部分:计算机基础知识1.下列关于个人移动通信的叙述中,错误的是____A.第1代个人移动通信(简称1G)采用的通信技术是数字通信技术B.目前广泛使用的GSM手机采用的通信技术属于第2代移动通信技术(简称2G)C.第3代移动通信技术(简称3G)将无线通信与互联网、多媒体通信相结合D.3G有多个国际技术标准,其中也有我国自主制定的3G技术标准。
2.在下列有关集成电路的叙述中,正确的是2。
A.现代集成电路所使用的半导体材料都是硅B.所有的集成电路都是数字集成电路C.Moore定律认为单块集成电路的集成度平均每年翻一番D.Intel公司微处理器产品Core 2 Duo,其集成度已高达数千万个电子元件3.与十六进制数AB等值的八进制数是3 。
A. 253B.254C.171D.1724.在下列有关PC机CPU的叙述中,错误的是4。
A.CPU中包含几十个甚至上百个寄存器,用来临时存放数据、指令和控制信息B.所有PC机的CPU都具有相同的指令系统,因而PC机可使用相同的软件C.一台计算机至少包含1个CPU,也可以包含2个、4个、8个甚至更多个CPUD.Intel公司是国际上研制和生产CPU的主要公司,我国也能生产CPU5.在下列有关PC机主板上部件的叙述中,错误的是5 。
A.BIOS保存在主板上的一个闪存中,其内容在关机后通常不会改变B.CMOS中保存有用户设置的开机口令,关机后主板上的电池继续给CMOS供电C.启动CMOS设置程序可以重新设置CMOS中的数据,该程序是BIOS的组成部分D.网卡通常集成在主板上,由主板上独立的IC实现其功能,与芯片组无关6.从PC机存储器的层次结构来看,下列存储器中存取速度最快的是6 。
A.Cache存储器B.RAM和ROMC.寄存器D.硬盘和优盘7.在下列4种PC机常用I/O接口中,数据传输速率最高的是7。
A.PS/2B.SATAC.IEEE-1394bB 2.08.在下列有关I/O操作、I/O总线和I/O接口的叙述中,错误的是8。
VB语言程序设计课后编程及上机调试参考答案
VB语言程序设计课后编程及上机调试参考答案VB语言程序设计课后编程及上机调试参考答案ex0101Private Sub Label1_Click()Caption = "练习"Command1.Caption = "确定"Label1.FontBold = TrueLabel1.AutoSize = TrueLabel1.Caption = "Visual Basic程序设计教程" End Subex0102Private Sub Command1_Click()Txt.Text = "我有电脑"End SubPrivate Sub Command2_Click()Txt.Text = "我没有电脑"End SubPrivate Sub Command3_Click()Txt.Text = "" '一对双撇号,中间不留空End Subex0104Private Sub Command1_Click()Dim x As Singlex = Val(Text1.Text)Text2.Text = 15 * xEnd Subex0202Private Sub Form_Click()Dim r As Single, s As Singler = 4.6s = 3.14159 * r ^ 2Text1.Text = "圆的面积为" & sEnd Subex0204Private Sub Command1_Click() '"最大化"按钮 Form1.WindowState = 2 '最大化End SubPrivate Sub Command2_Click() '"还原"按钮 Form1.WindowState = 0 '还原End SubPrivate Sub Command3_Click() '"最小化"按钮 Form1.WindowState = 1 '最小化End Subex0205Private Sub command1_click()Dim x As SingleDim y As Singlex = Val(Text1.Text)y = Val(Text2.Text)Text3.Text = x * x + y * yEnd Subex0206Private Sub command1_click()Dim x As Stringx = Text1.TextText2.Text = Left(x, 1) + Right(x, 1) End Subex0301Private Sub Form_Load()Dim x As Integer, y As IntegerDim a As Integer, b As Integer, c As Integer x = Val(InputBox("请输入一个三位数"))a = Int(x / 100) '求百位数b = Int(x / 10) - a * 10 '求十位数c = x Mod 10 '求个位数Showy = c * 100 + b * 10 + a '生成倒序数Print x; "倒序数为:"; y '显示倒序数End Subex0302Private Sub Command1_Click()n = Val(Text1.Text)Randomizex = Int(1 + n * Rnd)Label1.Caption = "第一个随机数" + Str(x)x = Int(1 + n * Rnd)Label2.Caption = "第二个随机数" + Str(x)x = Int(1 + n * Rnd)Label3.Caption = "第三个随机数" + Str(x) End Subex0303Private Sub Cmd1_Click()Lab1.Visible = TrueLab1.Caption = "您已下达显示命令"End SubPrivate Sub Form_Click()Cmd1.Visible = TrueEnd Subex0304Private Sub Form_KeyPress(KeyAscii As Integer) ShowPrint "输入字符:"; Chr(KeyAscii), "ASCII码为;"; KeyAsciiEnd SubPrivate Sub Form_DblClick()ClsEnd Subex0305Private Sub Form_Load()x = MsgBox("在这里显示提示信息", 4 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 3 + 0, "请确认")x = MsgBox("在这里显示" + Chr(13) + "提示信息", 2 + 16 + 0, "请确认")End Subex0401Private Sub Form_Load()Dim x As Long, s As Stringx = InputBox("输入一个整数(1~35000)")s = "奇数"If x Mod 2 = 0 Then s = "偶数"MsgBox sEnd Subex0402Private Sub Command1_Click()Dim a As Single, b As SingleDim c As Single, d As SingleDim m As Single, n As Single, x As Single Showa = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)If a > b Then '求a、b中的较大数m = aElsem = bEnd IfIf c > d Then '求c、d中的较大数n = cElsen = dEnd IfIf m > n Then '求m、n中的较大数x = mElsex = nEnd IfText5.Text = xEnd Subex0403Private Sub Command1_Click()Dim t As String, p As String t = Mid(Text1.Text, 5, 1)Select Case tCase "2"p = "博士生"Case "3"p = "硕士生"Case "4"p = "本科生"Case "5"p = "专科生"Case Elsep = "无效学号"End SelectText2.Text = Left(Text1.Text, 2) + "级" Text3.Text = pEnd Subex0404Private Sub Command1_Click()r = 0: g = 0: b = 0If Check1.Value = 1 Thenr = 255End IfIf Check2.Value = 1 Theng = 255End IfIf Check3.Value = 1 Thenb = 255End IfLabel1.BackColor = RGB(r, g, b)End SubPrivate Sub Command2_Click()EndEnd Subex0405Private Sub Form_Load()LabClk.Caption = "0"LabClk.Alignment = 1LabClk.BorderStyle = 1LabClk.FontSize = 22LabClk.FontName = "黑体"TimClk.Interval = 1000End SubPrivate Sub TimClk_Timer()LabClk.Caption = Val(LabClk.Caption) + 1 End Subex0406Private Sub Form_Load()Command1.Enabled = FalseCommand2.Enabled = FalseEnd SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Text1.SelLength > 0 ThenCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command1_Click()Command1.Enabled = TrueCommand2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text2.Text = Text1.SelTextCommand1.Enabled = FalseCommand2.Enabled = FalseEnd Subex0501Private Sub Form_Load()Dim k As Integer, s As Integer, t As Integer s = 0For k = 1 To 100 Step 2s = s + kNext kShowPrint "1~100范围内的奇数和:"; sEnd Subex0502Private Sub Form_Load()Dim s As SingleShows = 0For k = 1 To 200s = s + k / (1 + k * k) Next kPrint Int(s * 10 + 0.5) / 10 End Subex0503Private Sub Form_Load()Showk = 2s = 0Do While k < 101s = s + k * (k - 1)k = k + 2LoopPrint sEnd Subex0504Private Sub Form_Load()Dim k As Integer, a As Integer, b As Integer Dim c As Integer, n As IntegerShown = 0Print "三位数的水仙花数是:"For k = 100 To 999a = Int(k / 100)b = Int((k - 100 * a) / 10)c = k Mod 10If a * a * a + b * b * b + c * c * c = k ThenPrint kn = n + 1End IfNext kPrint "一共有" & n & "个水仙花数"End Subex0505Private Sub Form_Load()ShowFor k = 1000 To 9999If k Mod 78 = 0 Thena = Int(k / 1000)b = Int(k / 100) - 10 * ac = Int(k / 10) - 100 * a - 10 * bd = k Mod 10If a = b And c = d ThenPrint kEnd IfEnd IfNext kEnd Subex0506Private Sub Command1_Click()Dim s As String, y As StringDim x As String, t As Strings = Text1.Text: y = ""For k = 1 To Len(s)x = Mid(s, k, 1)t = UCase(x)If t >= "A" And t <= "Z" Theny = y + xEnd IfNext kText2.Text = yEnd Subex0507Private Sub Command1_click() '"显示"按钮单击事件FontSize = 12ClsFor i = 0 To List1.ListCount - 1 '逐项判断 If List1.Selected(i) Then '真时为选定Print List1.List(i)End IfNext iEnd Subex0508Private Sub Form_Load()ShowFor a = 1 To 9For b = 1 To 9For c = 1 To 9For d = 1 To 9x = a * 1000 + b * 100 + c * 10 + d y = b * 1000 + a * 100 + a * 10 + c z = d * 100 + d * 10 + aIf x - y = z ThenPrint "A=" & a & ",B=" & b & ",C=" & c & ",D=" & dEnd IfNext dNext cNext bNext aEnd Subex0601Private Sub Command1_Click()Dim a(10) As Integer, min As Integer, pos As IntegerRandomizeFor i = 1 To 10a(i) = Int(Rnd * 90 + 10)Print a(i);Next iPrintmin = a(1)pos = 1For k = 2 To 10If a(k) < min Thenmin = a(k)pos = kEnd IfNext kPrint "最小数:"; min, "位置:"; posEnd Subex0602Private Sub Form_Load()Dim a As Variant, b As VariantDim c(8) As Integera = Array(3, 4, 2, 1, 5, 7, 8, 11, 13)b = Array(10, 6, 12, 9, 13, 8, 8, 1, 16)For k = 0 To 8c(k) = a(k) + b(k)Next kShowFor k = 0 To 8Print c(k)Next kEnd Subex0603Private Sub Form_Load()Dim d() As IntegerDim k As Integer, t As Integer, m As Integer Dim h As Integer, n As Integern = Val(InputBox("请输入数组个数n:"))ReDim d(n)ShowPrint "处理前数据 :"RandomizeFor k = 1 To nd(k) = Int((101 * Rnd - 50))Print d(k);Next kPrintm = Int(n / 2)For k = 1 To mh = n - k + 1t = d(h): d(h) = d(k): d(k) = tNext kPrint "处理的结果 :"For k = 1 To nPrint d(k);Next kEnd Subex0604Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim s As Long, i As Integer, j As Integer ShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(90 * Rnd + 10) '产生一个随机数a(i, j) = xNext jNext is = 0For i = 1 To nFor j = 1 To ns = s + a(i, j)Next jNext iPrint "所有元素之和;"; sPrintFor i = 1 To ns = 0For j = 1 To ns = s + a(i, j)Next jPrint "第"; i; "行元素之和;"; sNext iPrints = 0For i = 1 To ns = s + a(i, i)Next iPrint "主对角线元素之和;"; sPrints = 0For i = 1 To nFor j = 1 To nIf i = 1 Or i = n Or j = 1 Or j = n Then s = s + a(i, j)End IfNext jNext iPrint "所有靠边元素之和;"; sEnd Subex0605Option Base 1Private Sub Form_Load()Dim a(8, 8) As Integer, n As IntegerDim max As Integer, r As Integer, c As Integer ShowRandomizen = 8For i = 1 To nFor j = 1 To nx = Int(900 * Rnd + 100) '产生一个随机数a(i, j) = xPrint x;Next jPrintNext imax = 0: r = 1: c = 1PrintFor i = 1 To nFor j = 1 To nIf a(i, j) > max Then '判断有无更大数max = a(i, j): r = i: c = jEnd IfNext j, iPrint "最大值为:"; maxPrint "位于行:"; r, "列:"; cEnd Subex0606Dim n As IntegerPrivate Sub Cmd1_Click()n = n + 1If n = 3 Then n = 0Opt1(n).Value = TrueEnd SubPrivate Sub Form_Load()n = 1End Subex0607Private Sub Form_Load()Dim a(20) As IntegerRandomizea(1) = Int(10 + 90 * Rnd) k = 1Do While k < 20x = Int(10 + 90 * Rnd) f = 0For j = 1 To kIf x = a(j) Then f = 1Exit ForEnd IfNext jIf f = 0 Thenk = k + 1a(k) = xEnd IfLoopShowFor j = 1 To 20Print a(j)Next jEnd Subex0701Private Sub Form_Click() Dim s As Longs = 0For k = 1 To 10s = s + jc(k)Next kPrint sEnd SubFunction jc(n) As Long Dim t As Longt = 1For k = 1 To nt = t * kNext kjc = tEnd Functionex0702Private Sub Form_Load()Dim a As Single, b As Single, c As SingleDim d As Single, m As Single, n As SingleShowa = Val(InputBox("输入第1个数"))b = Val(InputBox("输入第2个数"))c = Val(InputBox("输入第3个数"))d = Val(InputBox("输入第4个数"))m = max(a, b) '求a、b中的较大数n = max(c, d) '求c、d中的较大数Print "最大数为:" & max(m, n) '求m、n中的较大数End SubFunction max(x, y) As SingleIf x > y Thenmax = xElsemax = yEnd IfEnd Functionex0703Private Sub Command1_Click()Dim d(5) As Single, m As Single For k = 0 To 5d(k) = Val(Text1(k).Text)Next kCall Max(d(0), d(1), d(2), m) Call Max(m, d(3), d(4), m)Call Max(m, m, d(5), m)Text2.Text = mEnd Subex0704Private Sub Form_Load()Dim x As LongShowx = Val(InputBox("输入一个数")) Print x; "的位数为:"; fnws(x) End SubFunction fnws(x As Long) As Integer Dim n As Integern = 1Do While x \ 10 > 0n = n + 1x = x \ 10Loopfnws = nEnd Functionex0705Private Sub C1_Click()Form1.HideEnd Subex0705APrivate Sub C2_Click()Form1.ShowEnd Subex0706Dim n As IntegerPrivate Sub Command1_Click() usern = Trim(Text1.Text)passw = Trim(Text2.Text)If usern = "username" And passw = "password" ThenForm1.HideForm2.ShowElsen = n + 1Text1.SetFocusIf n = 3 ThenForm1.HideForm3.ShowEnd IfEnd IfText1.Text = ""Text2.Text = ""End Subex0706APrivate Sub Command1_Click()Form2.HideForm1.ShowEnd Subex0906BPrivate Sub Command1_Click()Unload Form1Unload Form2Unload Form3EndEnd Subex0802Private Sub Form_Load()Dim i As Integer, j As IntegerShowFor i = 1 To 12Print String(20 - i, 32); '输出当前行左边的空格,分号表示下一输出项紧接输出For j = 1 To 2 * i - 1 '输出2*i-1个字符If j <= i Then '按左、右两边指定输出字符k = j '左边输出的字符k = 2 * i - j '右边输出的字符End IfIf k > 9 Then k = k + 7 '字母的ASCII 码比数字大7Print Chr(k + 48); '以字符格式输出Next jPrint '换行Next iEnd Subex0803Dim t As Single, f As IntegerPrivate Sub Command1_Click() '“产生原稿文”按钮Randomizes = ""For k = 1 To 30x = Chr(Int(Rnd * 26) + 97) '随机产生小写字母Next kText1.Text = s '显示在文本框中Text2.Text = ""Text2.Locked = False '允许录入Text2.SetFocus '设置焦点Text3.Text = ""Text4.Text = ""f = 0 '第1次按键标记,0表示未按键End SubPrivate Sub Command2_Click() '“结束”按钮EndEnd SubPrivate Sub Text2_KeyUp(KeyCode As Integer, ShiftAs Integer)Dim c As Integer, k As IntegerIf f = 0 Then'第1次按键时,开始计时t = Timer '用t保存第1次按键的时间f = 1 '1表示已按键和进入录入过程End IfIf Len(Text2.Text) < 30 ThenText3.Text = Round(Timer - t, 1) & "秒" '显示用户当前所用时间Elsec = 0For k = 1 To 30 '统计录入正确的字母个数If Mid(Text1.Text, k, 1) =Mid(Text2.Text, k, 1) Thenc = c + 1End IfNext kText2.Locked = True '禁止录入Text4.Text = Round(c / 30 * 100, 2) & "%" '显示准确率End IfEnd Subex0901Private Sub Command1_Click()Open "静夜思.txt" For Input As #1Do While Not EOF(1) '文件未结束时,循环Input #1, xList1.AddItem xLoopClose #1End Subex0902Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() '"产生随机数" For i = 1 To 20d(i) = Int(1 + 99 * Rnd)List1.AddItem d(i)Next iEnd SubPrivate Sub Command2_Click() '"保存" Open "MyFile4.txt" For Output As #1 For i = 1 To 20Write #1, d(i)Next iClose #1End SubPrivate Sub Command3_Click() '"读出" Open "MyFile4.txt" For Input As #1Do While Not EOF(1)Input #1, xList2.AddItem xLoopClose #1End SubPrivate Sub Command4_Click() '"结束" EndEnd Subex0903Private Sub Form_Load()ShowFor k = 1 To 6fn = "..\第7章\ex070" & k & ".vbp"If Dir(fn) = "" ThenPrint Mid(fn, 4) & "未编写!!"ElsePrint Mid(fn, 4) & "已编写!!"End IfNext kEnd Subex0904Private Sub Form_Load()chedir = "C:\Documents and Settings\Lin\My Documents\fsodir"If Dir(chedir, 16) = "" ThenMkDir chedirEnd Ifchefile = "C:\Windows\notepad.exe"If Dir(chefile) <> "" ThenFileCopy chefile, chedir & "\mynotepad.exe"End IfMsgBox "操作完毕!"End Subex1002Private Sub A1_Click()Label1.ForeColor = vbRedEnd SubPrivate Sub A2_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub A3_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 2 ThenPopupMenu mun0End IfEnd Subex1003Private Sub Command1_Click()CommonDialog1.DialogTitle = "选择文件"CommonDialog1.Filter = "文本文件|*.txt"CommonDialog1.InitDir = "C:\"CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileName End SubPrivate Sub Command2_Click()Unload MeEndEnd Subex1101Private Sub calzc(x As Integer)Text2.Text = Round(2 * 3.14159 * x, 2) End SubPrivate Sub HV_Scroll()Dim r As Integerr = HV.ValueText1.Text = "=" & rCall calzc(r)End SubPrivate Sub Form_Load()HV.Max = 300End Subex1102Private Sub Form_Load()For k = 0 To 3Image1(k).Stretch = TrueImage1(k).Picture = LoadPicture("箭头" & k + 1 & ".bmp")Next kEnd SubPrivate Sub Image1_Click(Index As Integer)Picture1.Font.Size = 20Picture1.ClsSelect Case IndexCase 0Picture1.Print "箭头向上"Case 1Picture1.Print "箭头向左"Case 2Picture1.Print "箭头向右"Case 3Picture1.Print "箭头向下"End SelectEnd Sub41。
VB2005习题解答
《Visual Basic 2005程序设计教程》习题解答习题11.VB 2005集成开发环境有哪几个重要组成部分?答:Visual Basic把支持软件开发的各种功能集成在一个公共的工作环境中,称之为“集成开发环境(IDE)”,主要有以下几个部分组成:(1)菜单栏菜单栏中显示了“文件”、“编辑”、“视图”、“项目”、“格式”等菜单项,包含了VB编程的常用命令。
单击菜单栏中的菜单名,即可弹出下拉菜单。
在下拉菜单中显示各种功能子菜单,包含执行该项功能的快捷键。
(2)工具栏菜单栏下面是工具栏。
工具栏提供了许多常用命令的快速访问按钮,如图1-13所示。
单击某个按钮,即可执行对应的操作。
(3)窗体窗体是应用程序的用户界面,用户需在窗体中设计窗体的外观。
在开发过程中,由用户在窗体上放置各种控件来为应用程序创建用户界面。
应用程序运行时,用户能看到这个窗体。
在系统默认情况下,系统会自动生成一个窗体,结构类似于在Windows系统下运行的窗体,操作也和Windows系统下运行的窗体类似。
(4)工具箱工具箱中提供了各种可用控件和组件。
默认情况下,工具箱中将控件和组件按不同的类型分为不同的组,通常分为所有Windows窗体、公共控件、容器、菜单和工具栏、数据、组件、打印、对话框、Crystal Reports和常规组,如图1-15所示。
用户可以根据需要在各组中选择控件和组件。
(5)属性窗口“属性”窗口包含选定对象(窗体或控件)的属性列表。
在设计程序时可通过修改对象的属性来设计外观和相关数据,这些属性值将是程序运行时各对象属性的初始值。
2.在VB 2005工具箱中有控件和组件,控件和组件的区别是什么?答:在.NET Framework中,控件是包含在窗体对象内的对象。
每种类型的控件都具有其自己的属性集、方法和事件,以使该控件适合于特定用途。
可以在设计器中操作控件,也可以编写代码以便在运行时动态操作控件。
控件必须从以下基本控件类之一派生:System.Windows.Forms.Control和System.Web.UI.Control。
2009年9月计算机等级考试二级VB真题及参考答案(标准)
(26)窗体上有1个名称为Textl的文本框;1个名称为Thnerl的计时器控件,其Lnterval属性值为5000, Enabled属性值是True。Timerl的事件过程如下: Private Sub Timerl_Timer() Static flag As Integer If flag=0 Then flag=1 flag=-flag If flag=1 Then Text1.ForeColor=&HFF& '&HFF&为红色 Else End If End Sub 以下叙述中正确的是( )。 B)flag的值只可能取0或1
我的淘宝
D)6 3
(23)在窗体上画1个命令按钮,并编写如下事件过程: Private Sub Commandl_Click() For i=5 To 1 Step -0.8 Print Int(i); Next i End Sub 运行程序,单击命令按钮,窗体上显示的内容为( )。 A)5 4 3 2 1 1 C)4 3 2 1 1 Private Sub Commandl Click() Dim a(3,3) For m=1 To 3 For n=1 To 3 If n=m Or n=4-m Then a(m,n)=m+n Else a(m,n)=0 End If Print a(m,n); Next n Print Next m End Sub B)5 4 3 2 1 D)4 4 3 2 1 1
我的淘宝
C)110 100
Function fun(a As Integer,b As Integer) While a>b a=a-b Wend fun=a End Function A)把a=a-b改为a=b-a
计算机二级VB上机操作练习题及答案
计算机二级VB上机操作练习题及答案计算机二级VB上机操作练习题及答案Visual Basic(简称VB)是Microsoft公司开发的一种通用的基于对象的程序设计语言,下面店铺为为大家带来计算机二级VB上机操作练习题及答案,希望大家喜欢!一、基本操作题(1)在名称为Forml、标题为“球类项目”且没有最大化和最小化按钮的窗体上画1个名称为Combol的组合框。
组合框中的文本内容为空,表项内容有“乒乓球”、“羽毛球”和“网球”3项。
运行后的窗体如图所示。
注意:存盘时必须存放在考生文件夹下,工程文件名为sjtl.vbp,窗体文件名为sjtl.frm。
(2)在名称为Forml、标题为“转换”的窗体上,画1个名称为Shapel、边框宽度为3的形状。
再画两个标题分别为“椭圆”和“圆”的命令按钮。
如下图所示。
要求:编写适当的事件过程,使得单击“椭圆”按钮时,Shapel 的形状变换为椭圆;单击“圆”按钮时,Shapel的形状变换为圆。
程序中不得使用变量,每个事件过程中只能写一条语句。
注意:存盘时必须存放在考生文件夹下,工程文件名为sjr2.vbp,窗体文件名为sjr2.frm。
二、简单应用题(1)考生文件夹中有工程文件sjt3.vbv。
窗体上显示有一个列表框和一个文本框,且列表框中已有若干列表项。
程序的功能是,程序运行时,当用户在列表框中单击并选中某个列表项时,该项的内容将显示到文本框中,用户可以在文本框中对相关内容进行编辑,按回车键后,能够用编辑好的内容替换被选中的列表项,并自动清空文本框;当双击某个列表项时,则从列表框中删除该列表项;当用户直接在文本框中键入文本并按回车键后,则把该文本添加为列表框的一个新列表项,添加完成后,将文本框清空。
运行窗体如图所示。
要求:程序已经给出,但不完整,请将其中的注释符去掉,把“?”改为正确的内容,以实现上述程序功能。
注意:考生不得修改窗体文件中已经存在的控件和程序。
最后程序按原文件名存盘。
全国计算机二级VB上机试题内容及答案分析-推荐下载
第 5 题: 在考生文件夹下有一个工程文件 sjt5.vbp,窗体上有两个图片框,名称为 P1、P2,分别用来表示信号灯和汽车,其中在 P1 中轮流装入"黄灯.ico"、 "红灯. ico"、"绿灯.ico"文件来实现信号灯的切换;还有两个计时器 Timer1 和 Timer2,Timer1 用 于变换信号灯,黄灯 1 秒,红灯 2 秒,绿灯 3 秒;Timer2 用于 控制汽车向左移动。运行 时,信号灯不断变换,单击"开车"按钮后。 汽车开 始移动,如果移动到信号灯前或信号 灯下,遇到红灯或黄灯,则停止移动, 当 变为绿灯后再继续移动。在窗体中已经给出了 全部控件和程序,但程序不完整, 要求阅读程序并去掉程序中的注释符,把程序中的 ?改为正确的内容,使其实 现上 述功能,但不能修改程序中的其他部分,也不能修改控件的属性。 最后把 修改后的文件 以原文件名存盘。
信息技术会考VB上机编程模拟题
2009信息技术会考VB上机编程模拟题说明:下列练习题是模拟系统中的一部分,要求学生平时练习时为每道题建一个专用文件夹,文件夹的名称可与窗体的Caption属性相同。
会考时共有四道编程题,其中A类题、B 类题、C类题、D类题各一题。
A类(每题8分)说明:A类题以顺序结构的解析算法为主,解决学生在数学、物理和生活中遇到的简单计算问题。
用到的控件有:标签框、文本框、滚动条、命令按钮等。
A01、编写加法器,在文本框中输入两个数,单击“计算”求和并显示结果;单击“清除”清除各项数值。
A02、编写计算水果价钱的程序。
在文本框中输入水果的购买量。
单击“一级”时按2.5元/kg计价,单击“二级”按2元/kg 计价,并在价钱框中显示价钱。
单击“清除”清除各框数据;单击“退出”退出程序。
A03、已知y= x3+|x-10|+4,编程求y的值。
要求:在文本框中输入x的值,单击“计算”按钮后在“y”框中显示y 的值;单击“退出”按钮退出程序。
A04、编程实现:在“半径”框中输入圆的半径,单击“确定”按钮时,“周长”、“面积”框中显示圆的周长和面积。
A05、编程计算圆锥的体积。
要求:输入圆锥的半径与高度,单击“计算”按钮可以计算出圆锥的体积并显示出来;单击V =πhr2 ,π取3.14“清除”按钮可以清除各项数值。
提示:A06、华氏温度(F )与摄氏温度(C )之间的转换关系为:。
编程实现:若用户在文本框中输入一个摄氏温度,单击“转换”按钮可以换算成华氏温度,并显示出来;单击“清除”按钮可以清除各温度值。
A07、某市近20年的生产总值情况如下:第1年是1000亿元,以后平均每年以5%的速度增长,通过滚动条求各年份该市生产总值是多少?提示:某年生产总值=A08、已知计算人口增长的公式是:,其中pl为所求人口数,p为人口基数,r为年增长率,n为经过的年头。
已知2000年我国有13.25亿人口,若年增长率固定为千分之1.5,请使用滚动条表示100年内我国的人口状况。
江苏计算机二级VB 2005春~2009秋答案
2005春第一部分信息技术基础知识1.A 2.B 3.D 4.C 5.C 6.B 7.A 8.B 9.A 10.C11.A 12.D 13.B 14.C 15.A 16.D 17.B 18.D 19.D 20.A第二部分Visual Basic程序设计一、选择题21.D 22.C 23.C 24.C 25.B26.D 27.D 28.B 29.C 30.D二、填空题(1) -1(2) 0.6(3) 1.8(4) 5.4(5) 10(6) 27(7) 9(8) 11(9) 2(10) 43(11) 7(12) 1(13) 16(14) 10(15) t=Sqr(2 + t)(16) Abs(A– 1)<0.00001(17) p=p & Mid(st,I + 1,1)(18) p(19) p=Mid(st,I+1,1)(20)max_st=p(21) Erase A(22) Sub1((L),A,flg)(23) Mid(CStr(x),I,1)<>Mid(Cstr(x),n-I+1,1)(24) A(Idx) = 1(25) k = 1(26) While K<10(27) InStr(28) Exit Function(29) Exit Function(30) Rec=Rec(n,m,k+1)2005秋第一部分信息技术基础知识1.C 2.B 3.D 4.B 5.A 6.C 7.B 8.D 9.B 10.D11.C 12.B 13.C 14.A 15.B 16.B 17.D 18.B 19.D 20.B第二部分Visual Basic程序设计一、选择题21.C 22.C 23.A 24.C 25.D26.B 27.C 28.B 29.A 30.D二、填空题(1) Text(2) 3(3) 15(4) 28(5) DCB(6) D(7) 3(8) 10 8(9) 5 2(10) 12 -10(11) 5 6 7 8(12) 13 14 15 16(13) 4 8 12 16(14) 2 6 10 14(15) a1 = a * x * (3 - 2 * i) / (2 * i)(16) Exit Do(17) Str(N) & "="(18) N = P(I) + P(J) + P(k)(19) Exit Sub(20)Idx = Idx + 1(21) Rc_NO = Rc_NO + 1(22) ub = UBound(a)(23) sum = 0(24) Idx = 1(25) js = js + 1(26) Open "c:\data.txt" For Input As #11(27) Do While Not EOF(11)(28) ReDim Preserve b(UBound(b) + 1)(29) b(i) = b(i - 1)(30) b(k) = n2006春第一部分信息技术基础知识1.D 2.B 3.A 4.C 5.D 6.D 7.D 8.A 9.C 10.B11.A 12.D 13.C 14.C 15.D 16.C 17.A 18.C 19.B 20.D第二部分Visual Basic程序设计一、选择题21.B 22.A 23.D 24.B 25.D26.C 27.B 28.A 29.C 30.D二、填空题(1) 200(2) 10(3) 0 :1(4) 2 :3(5) 4 :1(6) 11(7) 61(8) 136(9) 01 05 02(10) 8(11) 3(12) 4(13) 8(14) 16(15) Until Until A(I, J) <> 0(16) L = 6 - J(17) R = 6 - I(18) Chr(65 + I)(19) Loc(12) < LOF(12)(20)Get #12, , S(21) Rc_NO = Rc_NO + 1(22) n = n + 1(23) st = ""(24) List1.ListCount - 1(25) n + V al(Mid(S, j, 1)) * 2 ^ (8 - j)(26) n = 0(27) while N < Js(28) Sum = 0(29) Js = I - 1(30) Sum = L And K = 32006秋第一部分信息技术基础知识1.D 2.D 3.D 4.B 5.C 6.C 7.C 8.D 9.D 10.B 11.B 12.D 13.C 14.A 15.D 16.B 17.D 18.B 19.A 20.D第二部分Visual Basic程序设计一、选择题21.B 22.A 23.B 24.C 25.A26.D 27.C 28.C 29.D 30.D二、填空题(1) asicB(2) icBas(3) 3(4) 9(5) 15(6) 15(7) 36(8) 26(9) 17(10) 178(11) 178(12) 235(13) 458(14) 13(15) 37(16) Sum = a0(17) a0 * (-X) * (2 * n - 1) / (2 * n)(18) a0 = an(19) n = i Mod 10(20)n = Len(enc)(21) Chr(Asc(S) - P) & dec(22) sum = sum + score(i)(23) Format(av, "#.#")(24) a() As Single, maxv As Single, minv As Single(25) For i = 2 To UBound(a)(26) While Not EOF(11)(27) Input #11, S(k)(28) st(i + 1) = st(i)(29) st(i + 1) = temp(30) high = mid - 12007春第一部分信息技术基础知识1.B 2.C 3.B 4.D 5.D 6.A 7.B 8.C 9.C 10.C11.D 12.B 13.A 14.C 15.C 16.C 17.D 18.A 19.C 20.D第二部分Visual Basic程序设计一、选择题21.B 22.B 23.A 24.D 25.B26.A27.A 28.A 29.C 30.B二、填空题(1) 1(2) 0(3) 4(4) 1 1 1(5) 3 1 4(6) 1 3 1(7) 6(8) 8(9) 3(10) 42(11) 138(12) 5796(13) 34(14) 26(15) 8(16) -a * x * (2 * i - 1) / (2 * i + 2)(17) I=I+1(18) Exit Sub(19) pos2 + 1(20)pos2 <> 0(21) Text2 = Text2 & vbCrLf(22) While Not EOF(5)(23) Ub = UBound(A)(24) Sum + A(J, I - J + 1)(25) Sum = A(I, Ub)(26) If M < Sum Then M = Sum(27) N <> 1 (N Mod 2 <> 0)(28) S = N & "*3+1"(29) Exit Sub(30) If N <> 1 Then Call YZ(N)2007秋第一部分信息技术基础知识1.B 2.C 3.B 4.D 5.D 6.A 7.B 8.C 9.C 10.C11.D 12.B 13.A 14.C 15.C 16.C 17.D 18.A 19.C 20.D第二部分Visual Basic程序设计一、选择题21.B 22.B 23.A 24.D 25.B26.A27.A 28.A 29.C 30.B二、填空题(1) 1(2) 0(3) 4(4) 1 1 1(5) 3 1 4(6) 1 3 1(7) 6(8) 8(9) 3(10) 42(11) 138(12) 5796(13) 34(14) 26(15) 8(16) -a * x * (2 * i - 1) / (2 * i + 2)(17) I=I+1(18) Exit Sub(19) pos2 + 1(20)pos2 <> 0(21) Text2 = Text2 & vbCrLf(22) While Not EOF(5)(23) Ub = UBound(A)(24) Sum + A(J, I - J + 1)(25) Sum = A(I, Ub)(26) If M < Sum Then M = Sum(27) N <> 1 (N Mod 2 <> 0)(28) S = N & "*3+1"(29) Exit Sub(30) If N <> 1 Then Call YZ(N)2008春第一部分信息技术基础知识1.D 2.C 3.B 4.C 5.B 6.A 7.C 8.C 9.A 10.C11.B 12.A 13.D 14.A 15.B 16.A 17.C 18.A 19.B 20.D第二部分Visual Basic程序设计一、选择题21.D 22.A23.C 24.B 25.D26.C 27.A 28.C 29.B 30.C二、填空题(1) 9 12(2) 3 -3(3) 0 -6(4) DHL(5) NRV(6) XBF(7) -1(8) 1(9) 4(10) 10(11) 0(12) 15(13) 5 15(14) 2 35(15) –1 56(16) t = x(17) Abs(t) < eps(18) t * x ^ 2 / ((2 * n + 1) * (2 * n))(19) prime(n)(20)i = k(21) prime = False(22) ByV al n As Integer, a() As Integer(23) n = n \ k(24) k = k + 1(25) n = 1(26) str2 = str2 + convert(a(i))(27) d = Mid(st, i, 1)(28) s = ""(29) s = b & s(30) convert = s2008秋第一部分信息技术基础知识1.D 2.C 3.A 4.C 5.D 6.A 7.A 8.C 9.D 10.C11.D 12.D 13.A 14.B 15.B 16.B 17.A 18.B 19.C 20.D第二部分Visual Basic程序设计一、选择题21.B 22.A 23.D 24.C 25.D26.A 27.A 28.C 29.B 30.A 二、填空题(1) 2(2) 7(3) 16 15 14 13(4) 3 6(5) 4 7(6) 5 8 11(7) 30(8) 30(9) 15(10) 2 3(11) 5 8(12) 34 55(13) icBa(14) baicBa(15) baba(16) st = ""(17) k = (-1) ^ (i - 1) / st(18) Mid(st, i, 1) = p(19) CStr(i Mod 2) + h2b(20)Right("0000" & h2b, 4)(21) small & a(i)(22) Mid(small, i, 1) = 1(23) a(j) > a(j + 1)(24) n As Long, a() As Integer(25) n = n \ 10(26) k = k + 1(27) ReDim Preserve a(k + 1)(28) p = 0(29) a(j) = a(i)(30) j = j + 12009春第一部分信息技术基础知识1.D 2.B 3.B 4.D 5.B 6.D 7.A 8.C 9.D 10.A11.B 12.A 13.A 14.C 15.C 16.B 17.C 18.A 19.A 20.C第二部分Visual Basic程序设计一、选择题21.D 22.B 23.B 24.C 25.B26.D 27.C 28.D 29.A 30.B二、填空题(1) 2 1 0(2) 1 0 1(3) 0 1 2(4) 6(5) 5(6) 31(7) 19(8) 68(9) 12345(10) 123(11) OVER(12) 5(13) Y6(14) Z9(15) A10(16) x < -1 Or x > 1(17) fx + a * t(18) a2 = a(19) 0 To List1.ListCount – 1 或者 1 To List1.ListCount(20)List1.List(i) 或者List1.List(i-1)(21) scor = 0(22) Mid(Exact, j, 1) = Mid(anw, j, 1)(23) UBound(a)(24) Left - 1(25) i < 1(26) right = right - 1(27) ch = Mid(str, i, 1)(28) ""(29) m = n Mod 2(30) s = "1" & s2009秋第一部分信息技术基础知识1.A 2.D 3.A 4.B 5.D 6.C 7.B 8.B 9.B 10.D11.C 12.B 13.A 14.D 15.C 16.D 17.C 18.A 19.B 20.B第二部分Visual Basic程序设计一、选择题21.D 22.B 23.D 24.B 25.A26.C 27.B 28.D 29.B 30.C二、填空题(1) 15(2) 9(3) 2 (4) 5(5) 12(6) 25(7) 4 5 9(8) 5 -1 4(9) 1 2(10) 7(11) 36(12) 121(13) 101101(14) 001110(15) 011011(16) t = a1 / a2st = ""(17) a1 = a2 - a1(18) n <> 0(19) st(k + 1) = p(20)i = i + 1(21) If Left(q, 1) = Mid(st, i, 1) Then n = i - 1(22) ByV al n As Integer(23) sum1 + n Mod 10(24) k = 2(25) k = k + 1(26) c(1) = a(1)(27) p = p & CStr(q)(28) p = ""(29) Exit For(30) c(i) = n。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2009年(秋)上机 Visual Basic(VB05)答案
一、改错
【题目】本程序的功能是求给定范围内整数的每个数字的平方和。
Option Explicit
Private Sub Command1_Click()
Dim n As Integer, p() As Integer, sum As Long
Dim i As Integer, q As String
'sum = 0 'err 位置错
For n = 345 To 789
Call dv(n, p)
sum = 0
For i = 1 To UBound(p)
sum = sum + p(i) ^ 2
Next i
q = ""
For i = UBound(p) To 1 Step -1
q = q & p(i) & "^2+"
Next i
List1.AddItem n & ":" & Left(q, Len(q) - 1) & "=" & sum
Next n
End Sub
Private Sub dv(ByVal n As Integer, p() As Integer) 'err 无ByVal
Dim k As Integer
Do
k = k + 1
ReDim Preserve p(k)
p(k) = n Mod 10
n = n \ 10 'err n = n / 10 【或n = Int(n / 10) 或n = Fix(n / 10)】Loop Until n = 0
End Sub
二、编程题
【题目】编写程序,找出100以内间隔最远的一对相邻素数。
Option Explicit
Option Base 1
Private Sub Command1_Click()
Dim k As Integer, n As Integer, fb As Integer
Dim pn() As Integer, d As Integer, i As Integer
n = 2
Do
If prime(n) Then
k = k + 1
ReDim Preserve pn(k)
pn(k) = n
Picture1.Print n;
If k Mod 5 = 0 Then Picture1.Print End If
n = n + 1
Loop Until n = 100
fb = 0: k = 1
For i = 1 To UBound(pn) - 1
d = pn(i + 1) - pn(i) - 1
If d > fb Then
fb = d: k = i
End If
Next i
Text1 = pn(k) & "---" & pn(k + 1)
End Sub
Private Function prime(n As Integer) As Boolean Dim i As Integer
For i = 2 To Sqr(n)
If n Mod i = 0 Then Exit Function Next i
prime = True
End Function
Private Sub Command2_Click()
Picture1.Cls
Text1 = ""
End Sub
Private Sub Command3_Click()
End
End Sub。