《VB程序改错40题.doc》由会员分享,可在线阅读,更多相关《VB程序改错40题.doc(69页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateVB程序改错40题第2题 (1第57题 (1.0分) 题号:465-【程序改错】-题目:用InputBox函数输入一个字符串,编写程序按与 输入的字符相反的次序用Msgbox函数输出这个字 符串。如输入字符串为abcdefgh,则输出为h gfedcba,输出效果如图1。-Option ExplicitPrivate Sub Command1_Click() Dim
2、pristr As String, outstr As String Dim i As Integer pristr = InputBox(please input a string) *FOUND* For i = 0 To Len(pristr) *FOUND* outstr = outstr + Mid(pristr, Len(pristr) - i) Next i *FOUND* MsgBox outstr, , The Output Result End Sub答案:=(答案1)=For i = 0 To Len(pristr) - 1=或=For i = 0 To -1+Len(p
3、ristr)=(答案2)=outstr = outstr + Mid(pristr, Len(pristr) - i, 1)=或=outstr = Mid(pristr, Len(pristr) - i, 1)+outstr=(答案3)=MsgBox outstr, vbQuestion, The Output Result 第59题 (1.0分) 题号:147-【程序改错】-题目:下面的程序用来产生并输出图示的杨辉三角。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1-Option ExplicitPublic Sub readin(a() As In
4、teger, n As Integer) Dim i, j As Integer For i = 1 To n*FOUND* a(i, n) = 1 a(i, 1) = 1 Next i For i = 3 To n*FOUND* For j = 2 To n a(i, j) = a(i - 1, j) + a(i - 1, j - 1) Next j Next iEnd SubPublic Sub printf(a() As Integer, n As Integer) Dim i, j As Integer For i = 1 To n*FOUND* For j = 1 To n Prin
5、t Tab(5 * j + 10); a(i, j); Next j Print Next i PrintEnd SubPrivate Sub Form_Click() Dim x(10, 10) As Integer Call readin(x(), 6) Call printf(x(), 6)End Sub答案:=(答案1)=a(i, i) = 1=(答案2)=For j = 2 To i - 1=或=For j = 2 To -1 + i=(答案3)=For j = 1 To i第60题 (1.0分) 题号:146-【程序改错】-题目:用辗转相除法求两个整数的最大公约数。-Option
6、ExplicitFunction gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As Integer r = m Mod n Do While r 0*FOUND* n = m n = r r = m Mod n Loop*FOUND* gcd = rEnd FunctionPrivate Sub Form_Click() Dim a As Integer, b As Integer, c As Integer a = InputBox(输入一个整数) b = InputBox(输入一个整数) a = Val(a) b
7、 = Val(b)*FOUND* Call gcd(a, b) Print a, b, cEnd Sub答案:=(答案1)=m = n=(答案2)=gcd = n=(答案3)=c = gcd(a, b)第65题 (1.0分) 题号:492-【程序改错】-题目:输入两个正整数m和n,求其最大公约数。-Option ExplicitPrivate Sub Form_Click() Dim m As Integer, n As Integer, r As Integer m = InputBox(输入m的值:) n = InputBox(输入n的值:) Do While n 0 *FOUND* r
8、= m / n m = n *FOUND* n = m Loop *FOUND* Print 两数的最大公因子为:; nEnd Sub答案:=(答案1)=r = m Mod n=(答案2)=n = r=(答案3)=Print 两数的最大公因子为:; m第66题 (1.0分) 题号:467-【程序改错】-题目:从计算机输入三个数 , 找出中间数-Option ExplicitPrivate Sub FindMidNum() Dim x As Integer, y As Integer, z As Integer, A As Integer x = InputBox(PLEASE INPUT TH
9、E FIRST NUMBER) y = InputBox(PLEASE INPUT THE SECOND NUMBER) z = InputBox(PLESSE INPUT THE THIRD NUMBER) *FOUND* If x y Then A = x x = y y = A End If *FOUND* If y = z Then Print y *FOUND* ElseIf x = z Then Print z Else Print x End IfEnd SubPrivate Sub Form_Click() FindMidNumEnd Sub答案:=(答案1)=If x x T
10、hen=(答案2)=If y = z Then=或=If z = z Then=或=ElseIf z = x Then第70题 (1.0分) 题号:142-【程序改错】-题目:程序功能根据输入的学习成绩,分别显示优秀 (90分以上), 良好(75分以上),及格(60分以上) 不及格四个等级.-Option ExplicitPrivate Sub Form_Click()ClsDim i As Integeri = InputBox(请输入学习成绩)Select Case i*FOUND* Case 0 i 100 ,is0 =或= case is100=(答案2)=Case 90 to 100
11、=(答案3)=Case else第71题 (1.0分) 题号:473-【程序改错】-题目:下列程序进行-n阶乘运算,当阶乘的值超过-21147483648 溢出报错,并将结果输出为-1。-Option Explicit*FOUND*Private Function jc(ByVal n As Integer) As Integer Dim I As Integer Dim result As Long result = 1 I = 1 Do While I = n If result = a(i) Then a1 = a(i) a(i) = a(j) *FOUND* a(j) = a(i) E
12、nd If Next j Next i For i = 0 To 9 Print a(i) Next iEnd Sub答案:=(答案1)=For j = i + 1 To 9=或=For j = 1 + i To 9=(答案2)=If a(i) = a(j) Then=(答案3)=a(j) = a1第77题 (1.0分) 题号:490-【程序改错】-题目:输入一个字符串,将所有的小写字母都转换为大写字母。-Option ExplicitPrivate Sub Form_Click() Dim s1 As String, s2 As String, i As Integer, t As Stri
13、ng s1 = InputBox(输入字符串,#号结束) i = 1 *FOUND* s1 = Mid(s1, i, 1) While t # *FOUND* If t = a And t = a And t = z Then t = Chr(Asc(t) - 32)=(答案3)=Print 新字符串为:; s2第79题 (1.0分) 题号:487-【程序改错】-题目:设窗体中有图片框Pic1,现要求在其中绘制10个同心圆, 然后将此图以Test.BMP作文件名存入磁盘。-Option ExplicitPrivate Sub Command1_Click() Dim X As Integer
14、Dim Y As Integer Dim I As Integer Dim rad(9) As Integer X = Pic1.ScaleWidth / 2 Y = Pic1.ScaleHeight / 2 *FOUND* For I = 1 To 9 rad(I) = 500 * Rnd Next I I = 9 *FOUND* Do Until I 1 Pic1.Circle (X, Y), rad(I), RGB(256 * Rnd, 256 * Rnd, 256 * Rnd) *FOUND* I = I + 1 Loop SavePicture Pic1.Image, Test.BM
15、PEnd Sub答案:=(答案1)=for i=0 to 9 =或= for i=0 to 9 step 1=(答案2)=Do Until I i=(答案3)=I = I - 1 =或= i=-1+i第80题 (1.0分) 题号:460-【程序改错】-题目:已知C的公式表示如下: n! C=- (n-m)!*m! 函数过程fac( )求k!函数,在Fomr_Click事件中完成运算,请修正程序中错误。-Option ExplicitPrivate Function fac(k As Integer) As Single Dim x As Single, j As Integer *FOUND*
16、 x = 0 For j = 1 To k *FOUND* x = x j Next j fac = xEnd FunctionPrivate Sub Form_Click() Dim C As Single Dim m As Integer, n As Integer m = Val(InputBox(请输入一个整数(m):) n = Val(InputBox(请输入一个整数(n):) *FOUND* C = fac(n) / fac(n - m) * fac(m) Print C=; CEnd Sub答案:=(答案1)=x=1=(答案2)=x=x*j=或=x=j*x=(答案3)=C = f
17、ac(n) / fac(n - m) / fac(m)=或=C = fac(n) / (fac(n - m) * fac(m)=或=C = fac(n) / ( fac(n - m) * fac(m) )第82题 (1.0分) 题号:459-【程序改错】-题目:随机产生n个两位正整数(n由输入对话框输入,且n0), 求出其中的偶数之和,并在标签框Label1上显示。-Option ExplicitPrivate Sub Command1_Click() Dim n As Integer Dim i As Integer, sum As Long Dim rnddat As Integer n
18、= Val(InputBox(Please input a integer, Input N value) *FOUND* sum = n If n 0 Then For i = 1 To n *FOUND* rnddat = (Int(90 * Rnd) Me.Print rnddat; *FOUND* If rnddat / 2 = 0 Then sum = sum + rnddat End If Next i Label1.Caption = sum End IfEnd Sub答案:=(答案1)=sum=0=(答案2)=rnddat = (10 + Int(90 * Rnd)=或=rnddat = ( 10 + Int(90 * Rnd)=(答案3)=If rnddat Mod 2 = 0 Then=或=If rnddat / 2 = int(rnddat/2) Then=或=If rnddat / 2 = cint(rnddat/2) Then-