vb实验作业参考答案
vb程序设计实验教程习题答案(精品).doc
实验教材实验-1:单项选择题:AACCC DCBBC2:填空题:(1).bas(2).vbp, ,frm(3)视图工具箱(4)对象(5)属性对象事件方法(6)Windows(7)事件行为(8)窗体模块实验二1:单项选择题:ADCCA BAB DC BBCBC BAB DC 2:基本运算题:(1)27(2) 3.33333333333333(3) 3(4)0(5)-3(6) 2(7)ab33(8)类型不匹配(9) 3(10)AB3实验三1:单项选择题:BCBDC2:填空题:(1)300(2)321456(3)Shanghai(4) 6 7 6(5)True(6)2+3=5(7)”area=” 12.56(8)VISUAL实验四1:单项选择题:CAACA2:填空题:(1)7(2) 3 5(3)输入的数小于0(4) 3(5)False(6)2010 is not leap year.试验五1:单项选择题:ACCAB ACCCB2:填空题:(1)9(2)@n ② 1(3)®Len(a)②n\2 ③Mid(a,(n-i+l),l)④Mid(a,(n-i+l),l)(4)@n Mod 3=1 And n Mod 5=1 And n Mod 7=1 ©While CountN<5(5)Mid(cl,l,i)实验六1:单项选择题:DB DCD ACADD2:填空题:(1)30(2) 3(3)①a(2)②a(3)③a(l)(4)①1 ②2 ③a(i)=a(6-i)(5)①i+j ②0 ③a(i,j)(6)©Print ②k ③a(k,j)=a(j,k)④a(k,j);实验七1:单项选择题:ABBACB2:填空题:(1)15(2)①Preserve a(n+l) ②a(i+l)=a(i) ③Exit For ④a(i+l)=m⑤0 to n+1 (或LBound(a) to UBound(a))(3)d,c,b,a实验八1:单项选择题:CADBD CACB2:填空题:(1)a=9 b=4(2)362516941(2)①a (2)UBound(b)③实验九1:单项选择题:DDDBB CAB CAD2:填空题:(1)①p=p*n ②Fac(n) ③ 10人-6(2)①Max=x ②Max=y ③p ④Max(x,a(n))(3)①number(i) ②n as integer (3)number=number+7* 10A(i-1)实验十1:单项选择题:DC BAB C实验十一1:单项选择题:DADBBB BDD实验十二1:单项选择题:CBCBC CBDAD DBC2:填空题:(1)①Label 1. FondName=Combo 1 .TextCombo2.Text ③ Label 1 .FontBold=True ④ Label 1 .FondItalic=True⑤ Label 1 .FondSize=Combo3.Text(2)①Listl.Text ©List 1 .RemoveitemListl.ListindexListl .Additem List2.Text ④ List2.RemoveItem实验十三实验十四1:单项选择题:DACDAABC2:填空题:(1)ShowFont(2)打开另存为颜色字体打印机帮助(3)工程部件Microsoft Common Dialog Control 6.0(4 ) ShowColor Action=3实验十五1:单项选择题:CB BCB B BAD2:填空题:(1)内建菜单弹出菜单(2)Click(3)工具(4)代码窗口Click(5)相同不同实验十六1:单项选择题:B CAAC ACDDB DCC2:填空题:(1)①Open "c:\studl.txt” For Output As #1Textl.Text=”End”White #l,Textl.Text(2)①For Input ②For Output As #2 ③Not Eof(l)Input #l,strl ⑤ Close #1,#2 ⑥Kill(“c:\old.txt”(3)①For Output ②For Input As #2。
vb实验八综合实验答案
实验八综合实验(4个学时)一、实验目的1.掌握常用控件的使用。
2.掌握下拉菜单的设计方法。
3.掌握创建多重窗体程序的有关技术。
4.了解常用事件及过程。
5.掌握顺序文件的打开、关闭和读写操作。
6.掌握三种鼠标事件的用法。
7.综合运用所学的知识,编写具有可视化界面的应用程序。
二、实验内容利用菜单、对话框、选择结构语句、循环结构语句、多窗体、常用控件、过程等知识点进行综合程序设计。
具体要求:1.在主窗体上,设计下拉式菜单:数值计算画图与动画顺序文件退出n! 编写画图程序读写古诗1+3+…+99 S6.1(说明:S6.1表示实验六的第1题)2.分别单击菜单项n!( 要求从键盘键入n的值),1+3+5+….99时,要求在主窗体中设置Label1显示题目,Label2显示结果界面如下图。
1)Form1中的代码设计如下:Private Sub accumulate_Click()Dim i As Integer, sum As IntegerFor i = 1 To 99sum = sum + iNext iLabel1.Caption = "1+2+3+4+…+99="Label2.Caption = sumEnd SubPrivate Sub factorial_Click()Dim a As IntegerLabel1.Visible = TrueLabel2.Visible = Truea = InputBox("请输入n的值", "注意")La bel1.Caption = "1×2×…×" & a & "="s = 1For i = 1 To as = s * iNext iLabel2.Caption = sEnd Sub2)将从键盘上输入n = 9时的运行界面剪切下来粘贴在下面。
vb实验报告(答案)
Print "数理化"
End Sub
Private Sub Cmd2_Click()
Print "政史地"
End Sub
心得体会:(可以从以下几个方面来总结:你在上机过程中遇到了哪些难题?你是怎么克服的?你对你的程序的评价?你的收获有哪些?你有什么没有解决的问题?等)
A. Text1.MaxLength = 0 B. Text1.Enabled = False
C. Text1.Visible = FalseD. Text1.Width = 0
5、设置命令按钮的属性时,只有将(A)属性设置为1,Picture属性才有效,否则无效。
A、StyleB、CaptionC、EnabledD、Default
试验报告(1)
院(系):课程名称:日期:
班级
学号
实验室
专业
姓名
计算机号
实验
名称
VB环境的熟悉与应用
成绩评定
所用
软件
Visual Basic 6.0
教师签名
实
验
目
的
或
要
求
1.熟悉VB的系统环境,了解VB程序的编写、保存和编译的方法过程。
2.初步了解几个常用控件的使用方法。
实
验
步
骤
、
心
得
体
会
1、在vb中____C_____被称为对象。
10、确定一个控件在窗体上位置的属性是__Left_______和___Top______。
11、窗体边框类型的默认值是___2___。
9、Visual Basic集成开发环境主要窗口包括__窗体设计窗口;代码设计窗口;_属性窗口;_工程资源管理器窗口_;_工具箱窗口。
VB实验教材的实验、习题答案
第一章VB开发环境与VB概述习题答案习题一、选择题第二章常用控件与界面设计习题答案习题一、选择题第三章实验与习题实验实验3_1…算术运算Private Sub Command1_Click()Const a As Single = 3, b As Single = 2, c As Single = -1, d As Single = 6Dim x As Single, y As Single, z As Single, m As Singlex = 2: y = 1: z = 1: m = 1List1.ClearList1.AddItem a / (b + c / b)List1.AddItem (x + Sqr(x ^ 2 + 1)) ^ (1 / 3)List1.AddItem ((2 * y) / (a * x + b * y) * (a * x - b * y))List1.AddItem 1 + 1 / (1 + 1 / m)List1.AddItem 1 / 2 * (d / 3) ^ (2 * x)List1.AddItem Log(y + Cos(x) ^ 2)List1.AddItem Abs((Exp(x) + Sin(x) ^ 3) / (x + y))List1.AddItem Log((Exp(x * y) + Abs(1 / Tan(z) + Cos(x) ^ 3)) / (x + y - z))List1.AddItem Sin(45 * 3.1415 / 180) + (Exp(10) + Log(10)) / Sqr(x + y + 1) List1.AddItem Log(a) / Log(b)End Sub…关系运算Private Sub Command2_Click()List1.ClearList1.AddItem Mid("Visual Basic", 1, 12) = Right("Language Visual Basic", 12) List1.AddItem "ABCRG" >= "abcde"List1.AddItem Int(134.69) >= CInt(134.9)List1.AddItem 78.9 / 32.77 <= 97.5 / 43.87 And -45.4 > -4.98List1.AddItem Str(32.345) = CStr(32.345)End Sub…逻辑运算Private Sub Command3_Click()Dim x As Integer, y As IntegerDim C1 As Integer, C2 As Integer, C3 As IntegerC1 = 70: C2 = 80: C3 = 90x = 9: y = -2List1.ClearList1.AddItem x + y < 10 And x - y > 0List1.AddItem (x% >= 0 And y% >= 0) Or (x% < 0 And y% < 0)List1.AddItem x = 0 Xor y = 0List1.AddItem C1 + C2 + C3 >= 255 Or C1 > 90 And C2 > 90 And C3 > 80End Sub实验3_2略实验3_3略实验3_4…零售结算Private Sub Command1_Click()Dim dj As Single, sl As Single, je As Single, n As IntegerLabel1.Caption = "金额:"dj = InputBox("请输入商品的单价:", "单价框")sl = InputBox("请输入商品的数量:", "数量框", 1)je = dj * sln = MsgBox("共计金额=" & je, vbOKCancel + vbInformation, "结果") If n = vbOK Then Label1.Caption = "金额:" & Str(je) & "元"End Sub…产生随机数Private Sub Command2_Click()Dim m As Integer, n As IntegerDim x1 As Integer, x2 As Integer, x3 As Integerm = V al(Text1.Text): n = Text2.TextRandomizex1 = Int(Rnd * (n - m + 1) + m)x2 = Int(Rnd * (n - m + 1) + m)x3 = Int(Rnd * (n - m + 1) + m)Label4.Caption = "结果为:" & Str(x1) & Str(x2) & Str(x3)End Sub…求逆序数Private Sub Command3_Click()Dim a As Integer, h As Integer, t As Integer, n As IntegerRandomizea = Int(Rnd * (999 - 100 + 1) + 100)h = Mid(CStr(a), 1, 1)t = Mid(CStr(a), 2, 1)n = Right(CStr(a), 1)Label5.Caption = a & "-->" & Format(n * 100 + t * 10 + h, "000")End Sub实验3_5略习题选择题填空题1、2 -32768~327672、整型长整型单精度双精度3、0 False “”4、Chr(Int(Rnd*(Asc(“L”)-Asc(“C”))+Asc(“C”)))x>0 And y>0 Or x<0 And y<0c>=”a” And c<=”z” Or c>=”A” And c<=”Z”x>=10 And x<20x<z Xor y<z5、False2TrueFalseTrueTrueTrueTrue6、18820010068.568765547、a=1 b=1a=2 b=1a=3 b=1a=4 b=18、Y Mod 4=0 And Y Mod 100<>0 Or Y Mod 400 =09、He Said, “Good morning”.10、EDEF11、(A>0 And A<>Int(A)) And (B<0 And B<>Int(B))12、a+b+c+d(a+b+c+d)/4sumaver13、(f-2*h)/2(4*h-f)/2简答题1、略2、Private Sub Form_Click()Const g = 9.8Dim V0 As Single, t As SingleDim S As SingleV0 = InputBox("请输入V0的值:")t = InputBox("请输入时间t的值:")S = (1 / 2) * g * t ^ 2 + V0 * tMsgBox ("位移量为:" & S)End Sub3、Private Sub Command1_Click()Dim l As Single, w As Single, h As SingleDim s As Singlel = Text1.Textw = Text2.Texth = Text3.Texts = (l * w + l * h + w * h) * 2Label1.Caption = sEnd Sub第四章选择分支与循环实验答案实验4-1方法一:x<=5 ; y方法二:Is<=2 ;Case Else实验4-2Shape1.BackColor=vbRed;Inter=15;Inter=Inter-1;Inter;实验4-3b<cb=aa=k实验4-4方法二:s*n ; t/s<10^-5实验4-5方法一:m>=10^-4 ; (-1)^(n+1)*m实验4-6x2=x3 ; <10^-6实验4-7实验4-8i+2*j+5*k=10 ; n实验4-9题目一:a) 5b)i=16 p=12 n=5c)i=9 p=8 n=1题目二:120 10实验4-10N=1 ;S=N& "*3 " & "+1 "实验4-11Len(st); Ch=Lcase(ch) ; Case Else ; Mid(Char,I,1)&St实验4-12i\100 ; (i Mod 100)\10习题一、选择题二、填空题1.Is=0 ; 1 To 10 ; Is >102. 93. 3 ; 4 154. this is a book ;This Is A Book5. 3 ; 3 ; 3 56. 32 07. 48. 15 19. 1 ; 401 ;10410. 1 2 3 ;1 3; 111. (3)12. 2 0 2413. 10 1414. BAABC CBAABC15. X Mod P=0 ; X=X+1 ;Find=False16. abs(t)<10^(-7) ; s+t17. Mid(n,1,1)=Mid(n,2,1) And Mid(n,3,1)=Mid(n,4,1)S=S+118. Mid(n,i,1)>Mid(n,i+1,1)19. "输入n";N/I=0 ;Print I第五章数组实验5_1Int(90 * Rnd) + 10a(i) = a(21 - i)a(21 - i) = t5_2k = x Mod 10i = i + 15_3s5_4max < a(i, j)row = Icol = j5_51ReDim Preserve prime(m)prime(j)5_6d Mod 25_7Exit Fora(j + 1) = a(j)5_8N – IA(j) = A(j + 1)5_9A(i, 1)JMin = MaxNot Flag5_10ch >= "0" And ch <= "9"P = P & chReDim Preserve C(k)5_11Private Sub Form_Click()Dim x As Integer, i As Integer, k As Integer, j As Integer Dim a() As Integerx = InputBox("输入正整数x=")i = 2Print x; "的质因子为:";Do While x >= iIf x Mod i = 0 Thenk = k + 1ReDim Preserve a(k)a(k) = ix = x \ iElsei = i + 1End IfLoopFor j = 1 To UBound(a)Print a(j);Next jEnd Sub习题一选择题二填空题1.V ariant2.ReDim A(N)A(1)If M < A(I) Then M = A(I)3.Int(26 * Rnd) + 65Chr(t)i + 1 To 10A(i) > A(j)4.InStr(s, ",")Right(s, Len(s) - n)s5. 4 5 66 5 43 2 16.T – 1I + 17.k = 6 - i – jmax = m8.j = aj = j - 39.i + 1i = i + 110. 237三编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("ÊäÈëm")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IFor I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As IntegerDim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopI = I + 1LoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As IntegerA(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10For J = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IText3.Text = SEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = V al(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub第六章参考答案实验实验6-11、Exit Do2、Y(X)3、X >= -1实验6-2【题目二】42 、26、8实验6-31、s1, key2、s As String3、ch >= "a" And ch <= "z"4、Mid(s, i, 1) = Chr(Asc(ch) + k - 26)思考:解密函数Private Sub dec(s As String, k As Integer) '解密过程Dim i As Integer, ch As String * 1For i = 1 To Len(s)ch = Mid(s, i, 1)If "A" <= ch And ch <= "Z" ThenIf Asc(ch) - k < Asc("A") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26 ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfElseIf ch >= "a" And ch <= "z" Then '多分支格式,ch介于小写a与z之间If Asc(ch) - k < Asc("a") ThenMid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26ElseMid(s, i, 1) = Chr(Asc(ch) - k)End IfEnd IfNext iEnd Sub实验6-41、b() As Integer, st As String2、L <= R3、ReDim Preserve b(R)4、L = L + 1辗转相除法求最大公约数函数Private Function Gcd(ByV al p As Integer, ByV al q As Integer) As IntegerDim r As Integerr = p Mod qDo While r <> 0p = qq = rr = p Mod qLoopGcd = qEnd Function实验6-5【题目一】age = age(n - 1) - 3【题目二】1、(Left + Right) / 22、Left = Mid + 1实验6-61、3 -12、7 43、3 -14、7 0实验6-7【题目一】1、Sqr(2 + t)2、Abs(a - 1) < eps【题目二】1、Dim X As Integer2、"S(" & I & ")=" & S(I)3、(j * i + 1)习题参考答案一选择题二、填空1(1)形式、(2)实在2(1)按地址传递、(2)ByV al3(1)窗体模块、(2)标准模块、(3)类模块4(1) 65(1)4 20 1016(1) 6 26 、(2)-2 987(1)10 6 、(2) 5 -58(1) 6 5 、(2)8 79(1)11 、(2)710(1)Fun(i) 、(2)Fun=p11(1) 4 、(2)20.712(1)29 、(2)28.713(1)k = j 、(2)b() As Integer14(1)gec 、(2)ge 、(3) 315(1)p1 = True And p2 = True 或p1 And p2 、(2)p1 = p2 – 2 、(3)Isp = True 、(4)m Mod i = 016(1)Convert(st) 、(2)Len(s) 、(3)"A" To "F" 、(4)k = k + p * h17(1)isualVi 、(2)sualV isu18(1)s + a 、(2)n + 1 、(3)x As Single, n As Integer 、(4)p * (x + i) / ((2 * i - 1) * i * x) 三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As BooleanDim K As IntegerReDim A(1)A(1) = 50————————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean)Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As IntegerDim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByV al idx As IntegerDim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub5、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1、编程验证任一大于2的偶数可以表示成两个素数之和。
VB编程实验报告答案 完整版
实验一:一、选择1.D2.D3.B4.A5.B6.C7.CD8.D9.D 10. BC11. A 12.D 13. D 14. C 15. A二、填空1.windows2. 中断3.工具箱4.代码5.分类6.form2.show7. 出现语法错误8. 错9. 事件10. 面向对象11.工程文件结构12. 工程13. 设计程序代码14. 双击窗体15. C:\Program Files\Microsoft Visual Studio\VB98 或者VB的安装文件夹16.属性17.方法18.font 19. form_load() 20.对象实验二:一、选择1.B2.C3. B4.C5.C6.C7.B8.B9.D 10. A11. C 12.C 13. C 14. B 15. A16.C 17.B 18.D 19.C 20. C二、填空1. Form_Click()2. Interval、50003..vbp .frm4.left top Height、Width twip5.picture6.load7. locked8. font Alignment9. GotFocus() LostFocus() 10. 属性窗口程序代码实验三:一、选择1.A2.BC3.BC4.A5.A6.A7.BCD8.D9.B 10. B11. B二、判断题不合法的变量:3. 4. 5. 6. 8. 10. 11. 14.15. 16.三、1、abs(x+y)2. (3+x*y)^23. (-b+sqr(b^2-4*a*c))/(2*a)4.sin(30*3.14/180)+exp(2)四、1. int(rnd* 71+20) 或int(rnd* 71)+202. x<0 and y>0 or x>0 and y<0 或者x*y<03. x mod 3=0 or x mod 7=0或x/3=x\3 or x/7=x\74. x>=10 and x<205. x>="A" and x<="Z"6. left(s,3)实验四:一、选择1.C2.D3. C4.D5.A6.D7.B8.B9.A 10. C二、填空1. 48.71E-01, -4.87122. 关系、逻辑、算术3. 900,100,mid(s,2,1)4.m、1,2,3 、print m & "月是第二季度"、end select 三、1. X=4 y=132. 10实验五一、选择B C B A C二、填空(1)for x=2 to 10s*(1-1/x)(2) 1 t>1E-6(3) j t(4) 5 11 5实验六一、选择B C C C D D D D C A实验七一、选择1C 2C 3D 4A 5B 6D 7AB 8A 9A 10A 二、填空(1)n!(2)1+1+2+3+4+……+n(3)n是否是素数(4)冒泡排序(5)递归调用产生斐波那契数列(6)求最大公约数和最小公倍数第八页编程2-1Private Sub Command1_Click()Label3 = Val(Text1) * Val(Text2)End SubPrivate Sub Command2_Click()Label3 = Val(Text1) / Val(Text2)End Sub2-2Private Sub Command1_Click()Picture1.Picture = LoadPicture("d:\tu1.jpg") End SubPrivate Sub Command2_Click()Picture1.Picture = LoadPicture("d:\tu2.jpg") End SubPrivate Sub Command3_Click()Picture1.Visible = FalseEnd Sub2-5Private Sub Form_Load()Image1.Picture = LoadPicture("C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\Sunset.jpg")End SubPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Image1_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Image1.Left = Int(Rnd * (Form1.ScaleWidth - Image1.Width)) Image1.Top = Int(Rnd * (Form1.ScaleHeight - Image1.Height)) End Sub第11页编程2-3Private Sub Command1_Click()Dim x%, y%x = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = (x Mod 10) * 100 + (x \ 10 Mod 10) * 10 + x \ 100Print "反序数:"; Format(y, "000")End SubPrivate Sub Command2_Click()Dim x%, y As Stringx = Int(Rnd * 900 + 100)Print "产生的随机数:"; xy = Trim(Str(x))Print "反序数:" & Right(y, 1) & Mid(y, 2, 1) & Left(y, 1)End SubPrivate Sub Form_Load()End Sub2-4Private Sub Command1_Click()Dim m%, n%Randomizem = Val(Text1): n = Val(Text2)x = Int(Rnd * (n - m + 1) + m)y = Int(Rnd * (n - m + 1) + m)z = Int(Rnd * (n - m + 1) + m)Label3 = m & "到" & n & "之间的3个随机数为: " & x & Space(3) & y & Space(3) & zEnd SubPrivate Sub Form_Load()End Sub2-5Private Sub Command1_Click()Label1.Caption = DateEnd SubPrivate Sub Command2_Click()Label2.Caption = TimeEnd SubPrivate Sub Command3_Click()Label3.Caption = WeekdayName(Weekday(Date)) End SubPrivate Sub Form_Load()End Sub第十五页2-1方法一Private Sub Command1_Click()Dim x!, a!, aa%, b!, bb%, c!, cc$x = Val(Text1)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")Label2 = "弧度" & Text1 & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub方法二Private Sub Command1_Click()x = InputBox("请输入弧度数值", "弧度转换", 0)xx = Val(x)a = x * 180 / 3.14aa = Int(a)b = (a - aa) * 60bb = Int(b)c = (b - bb) * 60cc = Format(c, "#.000")MsgBox "弧度" & x & "转换为" & aa & "度" & bb & "分" & cc & "秒"End Sub2-2Private Sub Command1_Click()Dim x%x = Val(Text1)If x / 400 = x \ 400 Or x Mod 4 = 0 And x Mod 100 <> 0 ThenLabel2 = Text1 & "年是闰年"ElseLabel2 = Text1 & "年不是闰年"End IfEnd Sub2-3方法二Private Sub Command1_Click()Dim x%, y%, z%x = InputBox("输入第一个数")y = InputBox("输入第二个数") z = InputBox("输入第三个数") If x > y Then t = x: x = y: y = t If y > z Then t = y: y = z: z = t If x > y Then t = x: x = y: y = t Print x, y, zEnd SubPrivate Sub Form_Load()End Sub方法一Private Sub Command1_Click() Dim x%, y%, z%x = Val(Text1)y = Val(Text2)z = Val(Text3)If x > y Then t = x: x = y: y = t If y > z Thent = y: y = z: z = tIf x > y Thent = x: x = y: y = tEnd IfLabel1 = x & Space(5) & y & Space(5) & z End Sub2-4方法一Private Sub Command1_Click()x = Val(InputBox("请输入上网时间:"))If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End SelectMsgBox "上网费用为:" & fei & "元"End IfPrivate Sub Command2_Click()EndEnd SubPrivate Sub Form_Load()End Sub方法二Private Sub Command1_Click()Dox = Val(InputBox("请输入上网时间:", , -1)) If x <> -1 ThenSelect Case xCase Is < 10fei = 25Case 10 To 50fei = x * 2Case 50 To 100fei = x * 1.5Case Is >= 100fei = x * 1End Selectzongfei = zongfei & Space(3) & fei MsgBox zongfei, , "上网费用为" ElseExit DoEnd IfLoopEnd SubPrivate Sub Command2_Click() EndEnd SubPrivate Sub Form_Load()End Sub2-5第18页2-3Private Sub Command1_Click()n = 0DoIf n Mod 2 = 1 And n Mod 3 = 2 And n Mod 5 = 4 And n Mod 6 = 5 And n Mod 7 = 0 Then Exit Don = n + 1LoopPrint nEnd Sub]2-5Private Sub Command1_Click()x = Val(Text1)y = x * 4n = 0Do While x <= yx = x * (1 + 0.1)n = n + 1Print xLoopPrint x, nEnd Sub2-6Private Sub Command1_Click()n = Val(InputBox("输入计算到第几项:", , 0)) For i = 1 To ns = s + (-1) ^ (i + 1) * iNextPrint n, sEnd SubPrivate Sub Form_Load()-8End Sub2-8Private Sub Command1_Click()Dim s As Double, pi As Doublen = 1: s = 0Do While 1 / (2 * n - 1) >= 0.0001s = s + (-1) ^ (n + 1) * 1 / (2 * n - 1)n = n + 1Looppi = 4 * sPrint piEnd Sub2-9Private Sub Command1_Click()For n = 100 To 999k = Trim(Str(n))If n = Left(k, 1) ^ 3 + Mid(k, 2, 1) ^ 3 + Right(k, 1) ^ 3 Then Print nNextEnd Sub2-11Private Sub Command1_Click()s = 0: Max = 0: Min = 1000For i = 1 To 20Randomizex = Int(Rnd * 50 + 51)Print x;If x > Max Then Max = xIf x < Min Then Min = xs = s + xNext iaver = s / 20PrintPrint "max="; Max, "min="; Min, "aver="; aver End SubPrivate Sub Form_Load()End Sub。
VB实验例题及解答
1、在窗体上创建一个命令按钮command1,完成下面操作:(1) 在form1的load事件中编写代码,使得窗体的前景色(form1.forecolor=vbBlue)为蓝色,窗体的字号为18号(form1.fontsize=18)。
(2) 在command1的click事件中编写代码,定义4个基本整型变量a,b,c,d。
给a赋值为10,b 赋值为3,求a对b整除后的商(c)和余数(d),并将商和余数输出在窗体上(print c,print d)。
解答Private Sub Form_Load()Form1.ForeColor = vbBlueForm1.FontSize = 18End SubPrivate Sub Command1_Click()a = 10b = 3c = a \ bd = a Mod bPrint cPrint dEnd Sub2、输入一个三位数,将它逆置后输出,要求将文本框中的数据按数值型数据进行处理,用算术表达式实现(利用mod、\、*、&等运算符)。
参考界面如下:解答法一Private Sub Command1_Click()Dim n#, a#, b#, c#, m#n = Text1.Texta = n \ 100b = n Mod 10c = (n Mod 100) \ 10Text2.Text = b * 100 + c * 10 + aEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Label2_Click()End Sub法二Private Sub Command1_Click()n = Text1.Texta = Left(n, 1)b = Mid(n, 2, 1)c = Right(n, 1)Text2.Text = c + b + aEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd SubPrivate Sub Label2_Click()End Sub3、完成上课讲解的分离数字的例子。
vb实验指导后题目-参考答案
期末自测题(A卷)文件部分的选择题要做,其它类型的题目不用做,不作考察选择题其它部分还没有时间做一、单选题(每题1分,共25分)1、211.66.160.1 是Internet上的( )。
(A) IP地址 (B)域名 (C)密码 (D)软件编号2、在以下四个www网址中,()网址不符合www网址书写规则。
(A) (B) (C) (D) 3、下列字符中,其ASCII码值最小的一个是()。
(A) A (B) a (C) Z (D) X4、下列软件中属于浏览器的是()。
(A) Excel (B) Internet Explorer (C) QQ (D) Visual Basic5、电子邮件(E-mail)地址的正确形式是()。
(A)用户名@域名 (B)用户名#域名 (C)用户名/域名 (D)用户名.域名6、下面变量名不合法的是()。
(A) a2 (B) abcd (C) a$x (D) Cd_E7、下列表达式中,正确的Visual Basic表达式是()。
(A) 2sin45° (B) ∏*R2 (C) x÷y×5 (D) (x+1)/(x^2+1)/28、下面逻辑表达式的值为真的是()。
(A) "A"> "a" (B) "abc"> "bc"(C) "That"> "Thank" (D) 12> 12.19、下列过程定义语句说明不合法的是()。
(A) Sub f1(ByRef n() As Integer) (B) Sub f1(ByRef n As Integer)(C) Sub f1(ByVal n() As Integer) (D) Sub f1(ByVal n As Integer)10、执行下面的4个打印语句,将出错的是()。
VB实验及答案
对象名称
属性名称
Form1
Caption
Command1 Caption
Label1
Caption
Label2
Caption
Label3
Caption
Text1、Text2 Text
属性值 象限判断 判断 X= Y=
(3)编写事件代码: Private Sub Command1_Click() Dim x!, y!
Private Sub Command2_Click() Dim f!, c! c = Val(Text2.Text) f = 9 / 5 * c + 32 Text1 = Str(f)
End Sub
(4)程序的运行及保存。 4 求圆的面积及圆柱体的体积,界面如图 2-3 所示。
【步骤】 (1)设计应用程序的界面:在窗体上创建两个命令按钮 Command1 和 Command2,四个标签 Label1、Label2、Label3 和 Label4,四个文本框 Text1、Text2、Text3 和 Text4。 (2)设置对象的属性
【步骤】
( 1 ) 在 窗 体 中 创 建 一 个 标 签 Label1 、 一 个 命 令 按 钮 Command1。
(2)在属性窗口中设置对象的属性:
对象名称
属性名称
属性值
Form1
Caption
设计界面
Label1
Caption
请留意此处
Command1
Caption
单击此处
(3)在 Command1 的 Click 事件中编写程序代码:
x = Val(Text1) y = Val(Text2) If x > 0 Then
VB实验参考答案
VB实验参考答案VB实验参考答案VB(Visual Basic)是一种常用的编程语言,广泛应用于软件开发领域。
在学习VB的过程中,进行实验是非常重要的一部分。
本文将为大家提供一些VB实验的参考答案,帮助大家更好地理解和掌握VB编程。
实验一:简单的计算器程序要求:编写一个简单的计算器程序,能够实现基本的加减乘除运算。
参考答案:```vbPrivate Sub btnCalculate_Click()Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)If rbAdd.Checked Thenresult = num1 + num2ElseIf rbSubtract.Checked Thenresult = num1 - num2ElseIf rbMultiply.Checked Thenresult = num1 * num2ElseIf rbDivide.Checked ThenIf num2 <> 0 Thenresult = num1 / num2ElseMsgBox("Error: Division by zero!")End IfEnd IftxtResult.Text = resultEnd Sub```实验二:学生成绩管理系统要求:编写一个学生成绩管理系统,能够实现学生信息的录入、查询和统计功能。
参考答案:```vbPrivate Sub btnAdd_Click()Dim name As StringDim score As Integername = txtName.Textscore = CInt(txtScore.Text)lstStudents.Items.Add(name & " - " & score)End SubPrivate Sub btnSearch_Click()Dim searchName As StringDim index As IntegersearchName = txtSearch.Textindex = lstStudents.FindString(searchName)If index <> -1 ThenlstStudents.SelectedIndex = indexElseMsgBox("Student not found!")End IfEnd SubPrivate Sub btnStatistics_Click()Dim totalScore As IntegerDim averageScore As DoubleDim count As IntegerFor Each item As String In lstStudents.ItemsDim score As Integer = CInt(item.Split("-")(1).Trim()) totalScore += scorecount += 1NextaverageScore = totalScore / counttxtTotalScore.Text = totalScoretxtAverageScore.Text = averageScore```实验三:简单的图书管理系统要求:编写一个简单的图书管理系统,能够实现图书信息的录入、查询和删除功能。
vb实验作业参考答案
vb实验作业参考答案VB实验作业参考答案引言:Visual Basic(VB)是一种基于事件驱动的编程语言,广泛应用于Windows操作系统的软件开发。
在学习VB编程过程中,实验作业是非常重要的一部分,通过实践来巩固所学知识。
本文将提供一些VB实验作业的参考答案,帮助读者更好地理解和掌握VB编程。
一、VB基础知识实验作业参考答案1. 实验题目:编写一个VB程序,实现两个整数的加法运算,并将结果显示在文本框中。
参考答案:```Private Sub btnAdd_Click()Dim num1 As IntegerDim num2 As IntegerDim result As Integernum1 = CInt(txtNum1.Text)num2 = CInt(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result)End Sub```2. 实验题目:编写一个VB程序,实现输入一个数字,判断该数字是奇数还是偶数,并在消息框中显示结果。
参考答案:```Private Sub btnCheck_Click()Dim num As Integernum = CInt(txtNum.Text)If num Mod 2 = 0 ThenMsgBox "该数字是偶数"ElseMsgBox "该数字是奇数"End IfEnd Sub```二、VB控件应用实验作业参考答案1. 实验题目:编写一个VB程序,实现一个简单的计算器功能,包括加法、减法、乘法和除法操作。
参考答案:```Private Sub btnAdd_Click()Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 + num2txtResult.Text = CStr(result) End SubPrivate Sub btnSubtract_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 - num2txtResult.Text = CStr(result) End SubPrivate Sub btnMultiply_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text) num2 = CDbl(txtNum2.Text)result = num1 * num2txtResult.Text = CStr(result) End SubPrivate Sub btnDivide_Click() Dim num1 As DoubleDim num2 As DoubleDim result As Doublenum1 = CDbl(txtNum1.Text)num2 = CDbl(txtNum2.Text)If num2 = 0 ThenMsgBox "除数不能为0"Elseresult = num1 / num2txtResult.Text = CStr(result)End IfEnd Sub```2. 实验题目:编写一个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实验教材习题答案 (1)
第1章VB集成环境与VB概述一、选择题第2章常用控件与界面设计一、选择题第3章数据、表达式与简单程序设计一、选择题第4章选择分支与循环一、选择题二、填空题1.5 7 13 12 14 112. 3 1 5 3 4 13. right(a$,i)4. 45. 6-i6. 6 11 10 21 13 347. 5 14 138. Is else end select9. a*(2*i-1)*(-1)*x/(2*i+2) i+110. 0 n-111. 1 t*(-1)*x^2/((2*k-1)*(2*k)) Abs(t)>eps12. count1=count+1 count1>013. sum=0 sum+j st & k & “+”14. 9 x三、编程题1.Option ExplicitPrivate Sub Command1_Click()Dim s As String, i As Integer, ch As String * 1Dim a As Integer, b As Integer, c As Integers = Text1.TextFor i = 1 To Len(s)ch = Mid(s, i, 1)If (ch >= "0" And ch <= "9") Thena = a + 1ElseIf (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z") Thenb = b + 1Elsec = c + 1End IfNextPrint "数字个数"; aPrint "字符个数"; bPrint "其他字符"; cEnd Sub2.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, n As IntegerDim a As Integer, b As Integer, c As IntegerFor i = 1 To 50n = Int(Rnd * 90 + 10)Print n;If i Mod 10 = 0 Then PrintIf n <= 40 Thena = a + 1ElseIf n <= 70 Thenb = b + 1Elsec = c + 1End IfNext iPrint "小于等于40的个数:"; aPrint "大于40小于等于70的个数:"; bPrint "大于70的个数:"; cEnd Sub3.Option ExplicitPrivate Sub Command1_Click()Dim x As SingleDim t As Long, n As Integerx = 1t = 1n = 1Do While 1 / t >= 0.0001x = x + 1 / tn = n + 1t = t * nLoopPrint xEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim k As Integer, sum As Integer, i As Integerk = InputBox("请输入一个正整数k", "输入框")For i = 1 To Len(CStr(k))sum = sum + Mid(k, i, 1)Next iMsgBox k & "的各位数字之和" & sumEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, iSum As LongFor i = 1 To 20iSum = iSum + i ^ 4NextPrint iSumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As IntegerDim sum1 As Integer, sum2 As LongDim i As Integer, j As IntegerFor a = 2 To 3000sum1 = 0sum2 = 0For i = 1 To a \ 2If a Mod i = 0 Then sum1 = sum1 + i Next ib = sum1For j = 1 To b \ 2If b Mod j = 0 Then sum2 = sum2 + j Next jIf sum2 = a And a < b Then Print a, bNextEnd Sub7.Private Sub Command1_Click() '打印菱形Dim i As Integer, j As IntegerClsFor i = 1 To 6 '打印菱形上边6行Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iFor i = 5 To 1 Step -1 '打印下半部分Print Tab(20);Print Spc(6 - i);For j = 1 To 2 * (i - 1) + 1If j = 1 Or j = 2 * (i - 1) + 1 ThenPrint "*";ElsePrint " ";End IfNext jPrintNext iEnd Sub8.Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, j As Integer, iSum As IntegerPrint "连续和为1250的正整数是:"For i = 1 To 500iSum = 0For j = i To 500iSum = iSum + jIf iSum >= 1250 Then Exit ForNextIf iSum = 1250 ThenPrint i; " ~"; jEnd IfNextEnd Sub9.Option ExplicitPrivate Sub Command1_Click()Dim a As Integer, b As Integer, c As IntegerFor a = 1 To 50For b = a To 50For c = b To 50If a ^ 2 + b ^ 2 = c ^ 2 ThenPrint a, b, cEnd IfNext cNext bNext aEnd Sub第5章数组一、选择题二、填空题1.Variant2.ReDim A(N)A(1)If M < A(I) Then M = A(I)3.Int(26 * Rnd) + 65Chr(t)i + 1 To 10A(i) > A(j)4.InStr(s, ",")Right(s, Len(s) - n)s5.T – 1I + 16.k = 6 - i – jmax = m7.j = 48j = j-38.i + 1i = i + 19. 23710. 3103511.numi + 1a(j)=temp三、编程题1.Option ExplicitOption Base 1Private Sub Command1_Click()Dim a(10) As IntegerDim i As Integer, max As IntegerFor i = 1 To 10a(i) = Int(90 * Rnd) + 10Print a(i);Next iPrinti = 1max = 0Do While i <= 10If a(i) Mod 3 = 0 ThenIf a(i) > max Thenmax = a(i)End IfEnd Ifi = i + 1LoopIf max = 0 ThenPrint "无要找的数"ElsePrint max & "是最大的能被3整除的数"End IfEnd Sub2.Option ExplicitOption Base 1Private Sub Command1_Click()Dim A() As IntegerDim I As Integer, m As IntegerDim K As IntegerReDim A(10)Print "原数组:";For I = 1 To 10A(I) = IPrint A(I);Next IPrintm = InputBox("????m")K = 9 + mReDim Preserve A(K)For I = 11 To KA(I) = A(I - 10)Next IFor I = 1 To 10A(I) = A(I + m - 1)Next IPrint "平移后的数组:";For I = 1 To 10Print A(I);Next IPrintEnd Sub3.Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, J As Integer, K As IntegerDim a() As Integer, n As Integer, p As Integer Dim s As String, Flag As Booleanp = 1For K = 10 To 100I = 1Do While I <= 10 And Not FlagJ = 1Do While J <= 10 And Not Flagn = I ^ 2 + J ^ 2If n = K ThenFlag = TrueReDim Preserve a(p)a(p) = Kp = p + 1s = I & Str(J) & Str(K)List1.AddItem sEnd IfJ = J + 1LoopI = I + 1LoopFlag = FalseNext KEnd Sub4.Option ExplicitPrivate Sub Command1_Click()Dim A(10) As IntegerDim B(10) As Integer, S As StringDim I As Integer, J As Integer, X As IntegerA(1) = Int(90 * Rnd) + 10S = A(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = A(J) Then Exit ForNext JIf J = I ThenA(I) = XS = S & " " & A(I)Exit DoEnd IfLoopNext IText1.Text = SB(1) = Int(90 * Rnd) + 10S = B(1)For I = 2 To 10DoX = Int(90 * Rnd) + 10For J = 1 To I - 1If X = B(J) Then Exit ForNext JIf J = I ThenB(I) = XS = S & " " & B(I)Exit DoEnd IfLoopNext IText2.Text = SS = ""For I = 1 To 10For J = 1 To 10If A(I) = B(J) ThenS = S & " " & A(I)End IfNext JNext IIf S = "" ThenText3.Text = "没有重复"ElseText3.Text = SEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub5.Option ExplicitPrivate Sub Command1_Click()Dim I As Integer, J As IntegerDim a() As Integer, K As Integer, Sum As Integer K = Val(Text1.Text)I = 1DoJ = K Mod 10ReDim Preserve a(I)a(I) = JSum = Sum + JK = K \ 10I = I + 1Loop Until K = 0Text2.Text = SumEnd Sub6.Option ExplicitPrivate Sub Command1_Click()Dim a(100, 2) As Integer, K As IntegerDim I As Integer, J As IntegerDim M As Integer, N As IntegerK = 1For I = 1 To 99For J = 1 To 99If I > J ThenM = I - JN = I + JIf Sqr(M) = Int(Sqr(M)) And Sqr(N) = Int(Sqr(N)) ThenList1.AddItem I & " " & Ja(K, 1) = Ia(K, 2) = JK = K + 1End IfEnd IfNext JNext IEnd Sub7.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsPicture3.ClsRandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, max As IntegerDim b(5) As Integer, c(5) As IntegerFor i = 1 To 5max = a(i, 1)For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)End Ifb(i) = maxIf max = a(i, j) Then c(i) = jNext jNext iFor i = 1 To 5Picture2.Print b(i)Picture3.Print c(i)NextEnd Sub8.Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click() '生成数组并显示Dim i As Integer, j As IntegerPicture1.ClsPicture2.ClsLabel3.Caption = "最大值?"Label4.Caption = "最小值?"RandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Int(90 * Rnd) + 10Picture1.Print a(i, j);NextPicture1.PrintNextEnd SubPrivate Sub Command2_Click() '交换并显示Dim i As Integer, j As Integer, t As IntegerDim maxi As Integer, mini As Integer, max As Integer, min As Integer max = 10: min = 99For i = 1 To 5For j = 1 To 5If max < a(i, j) Thenmax = a(i, j)maxi = iEnd IfIf min > a(i, j) Thenmin = a(i, j)mini = iEnd IfNextNextIf maxi <> mini ThenFor j = 1 To 5t = a(maxi, j)a(maxi, j) = a(mini, j)a(mini, j) = tNext jFor i = 1 To 5For j = 1 To 5Picture2.Print a(i, j);NextPicture2.PrintNextLabel3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"ElsePicture2.Print "最小值和最大值在一行"Label3.Caption = "最大值" & max & "在第" & maxi & "行"Label4.Caption = "最小值" & min & "在第" & mini & "行"End IfEnd SubPrivate Sub Form_click()Picture1.ClsPicture2.ClsLabel3.Caption = ""Label4.Caption = ""End Sub9.Option Base 1Private Sub Command1_Click()Dim i As Integer, j As Integer, n As Integer, a() As Integern = InputBox("请输入一个奇数N:")If n Mod 2 = 0 ThenMsgBox ("请重新输入奇数!")End IfReDim a(n, n)For i = 1 To nFor j = 1 To nIf i = (n + 1) / 2 And j = (n + 1) / 2 Thena(i, j) = -1ElseIf i = j Or i + j = n + 1 Thena(i, j) = 1Elsea(i, j) = 0End IfNext jFor i = 1 To nFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd Sub10.Option Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()Dim i As IntegerPrint "生成的数组:"RandomizeFor i = 1 To 10a(i) = Int(Rnd * 90) + 10Print a(i);NextPrintEnd SubPrivate Sub Command2_Click()Dim i As Integerx = InputBox("请输入要删除的数组元素下标:") Print "删除第" & x & "个数组元素后:"For i = x + 1 To 10a(i - 1) = a(i)NextFor i = 1 To 9Print a(i);NextEnd Sub11.Option ExplicitDim a(20) As Integer, i As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 20a(i) = Int(Rnd * 9) + 1Text1 = Text1 & a(i) & " "If i = 10 Then Text1 = Text1 & vbCrLf NextPrivate Sub Command2_Click()Dim j As Integer, k As Integer, b(20) As Boolean 'b(2)用来记录a(2)是否和前面的数相同,相同记为true,不再统计For i = 1 To 20k = 1If b(i) = False Then '如果b(i)=False,表示a(i)没有被统计过For j = i + 1 To 20If a(i) = a(j) Thenk = k + 1b(j) = TrueEnd IfNext jList1.AddItem a(i) & "出现次数:" & kEnd IfNextEnd SubPrivate Sub Command3_Click()Text1 = ""List1.ClearEnd Sub第6章过程一、选择题二、填空题1. 6 .2. 4 20 1013.第一行是 6 26 、第三行是-2 984.第一行10 6 、第二行 5 -55.第一行 6 5 、第三行8 76.第一行11 、第二行77.Fun(i)Fun=p8.第一行 4 、第二行2079.第一行29 、第二行28.710.J=kb( ) As Integerb( k-1) =b(k)i11.第一行gec 、第二行ge 、第四行 312.p1 = True And p2 = True 或p1 And p2= isp(i)Isp = Truem Mod i = 013.Convert(st)Len(s)"A" To "F"k = k + p * h14.isualVisualVisu15.s + an + 1x As Single, n As Integer 、p * (x + i) / ((2 * i - 1) * i * x)16.27617.Left(s, 1)Mid(s, i - 1, 1) = Mid(s, i, 1)n = 1c & CStr(n)18.chtempTrue19.val(mid(s,i,j))n as longprime=True20.A(2,2)的值是 6 ,A(3,1) 的值是8 ;A(4,2) 的值是 321.Option1(i)X22.1023.第一行7 6 ,第二行16 16 ,第三行,4524.第一行15 1 ,第二行35 3 ,第三行,50三、改错题1、Option Base 1Private Sub Command1_Click()Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim K As IntegerReDim A(1)A(1) = 50————————'K=1For I = 51 To 149K = 1 '位置错Logic = FalseCall Sub1(A, I, Logic)If Logic ThenK = K + 1ReDim A(K) 'ReDim Preserve A(K)A(K) = IEnd IfNext IFor I = 1 To UBound(A)Text1 = Text1 & Str$(A(I))If I Mod 5 = 0 Then Text1 = Text1 & vbCrLfNext IEnd SubPrivate Sub Sub1(A() As Integer, N As Integer, F As Boolean) Dim I As Integer, J As Integer, Ub As IntegerUb = UBound(A)For I = 1 To UbFor J = 2 To A(I)If A(I) Mod J = 0 And N Mod J = 0 ThenExit For 'Exit SubEnd IfNext JF = TrueNext IEnd Sub2、Option ExplicitOption Base 1Private Sub Command1_Click()Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As IntegerDim J As Integer, K As Integer, P() As IntegerReDim P(1)P(1) = 2For I = 3 To 150 Step 2For J = 2 To Sqr(I)If I Mod J = 0 Then Exit ForNext JIf J > Sqr(I) ThenReDim Preserve P(UBound(P) + 1)P(UBound(P) + 1) = I 'P(UBound(P)) = IEnd IfNext IFor I = 80 To 125If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)Text1 = Text1 & Str$(I) & "=" & Str(S1) & "*" & Str$(S2) & vbCrLf End IfNext IEnd SubPrivate Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As IntegerFor I = 1 To UBound(P)For J = 1 To UBound(P) - 1If N = P(I) * P(J) ThenS1 = P(I)S2 = P(J)'fun = TrueExit Functionfun = True '位置错End IfNext JNext IEnd Function3、Option ExplicitPrivate Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByVal idx As IntegerDim Ub As Integer, Counter As Integer, K As IntegerUb = UBound(Chess)Chess(idx) = 0Counter = 1K = 0 '位置错Do Until Counter = Ub - 1Do Until K = 2idx = idx + 1If idx > Ub Then idx = 1K = K + Chess(idx)LoopChess(idx) = 0Counter = Counter + 1LoopFor Over = 1 To UbIf Chess(Over) <> 0 Then Exit ForNext OverEnd SubPrivate Sub Command1_Click()Dim Chess(32) As Integer, I As Integer, J As IntegerDim K As Integer, idx As IntegerFor I = 1 To 32For J = 1 To 32Chess(J) = 1Next JCall Get_Chess(Chess, I, K)If K = 23 ThenText1 = "从第" & Str$(I) & "号棋子开始取"Exit ForEnd IfNext IEnd Sub4、Option ExplicitPrivate Sub Form_Click()Dim S As String, Flg As BooleanDoS = InputBox("输入一个自然数")If S = "" Or Not IsNumeric(S) ThenMsgBox "请重新输入", 48 + vbOKOnlyElseExit DoEnd IfLoopjudge(S, Flg) ' Call judge(S, Flg) 或judge S, Flg If Flg ThenPrint S; "是回文数"ElsePrint S; "不是回文数"End IfEnd SubPrivate Sub judge(Ch As String, F As Boolean)Dim L As Integer, I As IntegerL = Len(Ch)F = True ' F = FalseFor I = 1 To LIf Mid$(Ch, I, 1) <> Mid$(Ch, L + 1 - I, 1) Then Exit Sub Next IF = False ' F = TrueEnd Sub四、编程题1.Private Function Prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iPrime = TrueEnd Function'方法一Private Sub Command1_Click()Dim m As Integer, i As Integerm = InputBox("请输入一个大于2 的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub If Prime(2) And Prime(m - 2) ThenPrint m & "=2 +" & m - 2ElseDoi = i + 1If Prime(2 * i + 1) And Prime(m - (2 * i + 1)) ThenPrint m & "=" & 2 * i + 1 & "+" & m - (2 * i + 1)Exit DoEnd IfLoop While 2 * i + 1 < m - (2 * i + 1)End If'方法二Private Sub Command2_Click()Dim m As Integer, i As Integer, p() As Integer, n As IntegerDim flg As Booleanm = InputBox("请输入大于2的偶数")If m <= 2 Or m Mod 2 <> 0 Then MsgBox "请输入大于2的偶数": Exit Sub ReDim p(1)p(1) = 2n = 1For i = 3 To m - 2 Step 2If Prime(i) Thenn = n + 1ReDim Preserve p(n)p(n) = iEnd IfNext iFor i = 1 To nFor j = 1 To nIf p(i) + p(j) = m ThenPrint m & "=" & p(i) & "+" & p(j)flg = TrueExit ForEnd IfNext jIf flg = True Then Exit ForNext iEnd Sub2.Private Function Fact(a As Integer) As LongIf a = 0 Or a = 1 ThenFact = 1ElseFact = a * Fact(a - 1)End IfEnd FunctionPrivate Sub Command1_Click()Dim n As Integer, m As Integer, result As Singlen = Val(Text1.Text)m = Val(Text2.Text)If n >= m Thenresult = Fact(n) / Fact(m) / Fact(n - m)Text3.Text = resultMsgBox "要求n>=m,请重新输入"Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub3.Private Function Istgs(n As Integer) As BooleanDim s As String, L As IntegerL = Len(CStr(n))s = CStr(n ^ 2)If Right(s, L) = n Then Istgs = TrueEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 10 To 300If Istgs(n) Then List1.AddItem n & "^2" & "=" & n ^ 2 Next nEnd SubPrivate Sub Command2_Click()EndEnd Sub4.Private Sub Command1_Click()Dim a(3, 4) As Integer, i As Integer, j As IntegerDim m As Integer, mj As IntegerRandomizeFor i = 1 To 3For j = 1 To 4a(i, j) = Int(900 * Rnd + 100)Print a(i, j);Next jPrintNext iFor i = 1 To 3m = 0Call max(a, i, m, mj)Print "第" & i & "行最大值为" & m & ",在第" & mj & "列"Next iEnd SubPrivate Sub max(a() As Integer, i As Integer, m As Integer, maxj As Integer) Dim j As Integerm = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > m Thenm = a(i, j)maxj = jEnd IfNext jEnd SubPrivate Sub Command2_Click()EndEnd Sub5.Private Function Judge(n As Integer) As BooleanDim sum As Integersum = yz(n)If yz(sum) = 2 * n Then Judge = TrueEnd FunctionPrivate Function yz(n As Integer) As IntegerDim i As IntegerFor i = 1 To nIf n Mod i = 0 Then yz = yz + iNext iEnd FunctionPrivate Sub Command1_Click()Dim n As IntegerFor n = 1 To 500If Judge(n) Then Print nNext nEnd SubPrivate Sub Command2_Click()EndEnd Sub6.Private Sub Command1_Click()Dim n As Integer, j As Integer, flg As BooleanFor n = 2 To 30flg = FalseFor j = 2 To nIf pfs(j) And n Mod j = 0 Thenflg = TrueExit ForEnd IfNext jIf flg = False Then Print n;Next nEnd SubPrivate Function pfs(n As Integer) As BooleanIf Sqr(n) = Int(Sqr(n)) Then pfs = TrueEnd Function7.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd Function'判断某数是否为回文数Private Function Hws(n As Long) As BooleanDim i As Integer, s As String, L As Integers = CStr(n): L = Len(s)For i = 1 To Len(s) / 2If Mid(s, i, 1) <> Mid(s, L + 1 - i, 1) Then Exit Function Next iHws = TrueEnd FunctionPrivate Sub Command1_Click()Dim x As Long, t As Longx = InputBox("请输入一个正整数:")t = xDo While Hws(t) = FalsePrint t; "+"; fxs(t); "="; t + fxs(t)t = t + fxs(t)LoopEnd Sub8.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Sub Command1_Click()Dim n As Long, t As LongFor n = 1 To 999t = fxs(n)If t ^ 2 = fxs(n ^ 2) And n Mod 10 <> 0 And n < t ThenList1.AddItem n & " " & tList2.AddItem n & "^2" & "=" & n ^ 2 & " " & t & "^2" & "=" & t ^ 2 End IfNext nEnd Sub9.Private Function fxs(n As Long) As LongDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext ifxs = sEnd FunctionPrivate Function Judge(n As Integer) As BooleanDim i As Integer, L As Integer, a(9) As Integer, t As IntegerIf Sqr(n) = Int(Sqr(n)) ThenL = Len(CStr(n))For i = 1 To Lt = Mid(CStr(n), i, 1)a(t) = 1Next iFor i = 0 To 9Sum = Sum + a(i)Next iIf Sum = L - 1 Then Judge = TrueEnd IfEnd FunctionPrivate Sub Command1_Click()Dim a As IntegerFor a = 300 To 2000If Judge(a) Then List1.AddItem aNext aEnd Sub10.Private Function F(n As Integer) As BooleanDim i As IntegerFor i = 1 To Len(CStr(n))If i Mod 2 = 1 And Mid(CStr(n), i, 1) Mod 2 <> 1 Then Exit FunctionIf i Mod 2 = 0 And Mid(CStr(n), i, 1) Mod 2 <> 0 Then Exit Function Next iF = TrueEnd FunctionPrivate Sub Command1_Click()Dim a(8) As Integer, i As Integer, j As IntegerRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tList1.AddItem a(i)If F(a(i)) Then List2.AddItem a(i)End IfLoop Until i = 8End SubPrivate Sub Command2_Click()List1.ClearList2.ClearEnd SubPrivate Sub CmdEnd_Click()EndEnd Sub11.Private Function prime(a As Integer) As BooleanDim i As IntegerFor i = 2 To Sqr(a)If a Mod i = 0 Then Exit FunctionNext iprime = TrueEnd FunctionPrivate Function nx(n As Integer) As IntegerDim i As Integer, s As StringFor i = 1 To Len(CStr(n))s = Mid(CStr(n), i, 1) & sNext inx = Val(s)End FunctionPrivate Sub Command1_Click()Dim n As Integer, t As IntegerFor n = 100 To 900t = nx(n)If prime(n) And prime(t) And n < t ThenList1.AddItem "(" & n & "," & t & ")"End IfNext nEnd SubPrivate Sub Command2_Click()List1.ClearEnd Sub12.Option Base 1Dim a(4, 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerRandomizeFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 90 + 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub Fp(a() As Integer, i As Integer, maxj As Integer, Flg As Boolean) Dim max As Integer, j As Integer, t As Integermax = a(i, 1): maxj = 1For j = 2 To UBound(a, 2)If a(i, j) > max Thenmax = a(i, j)maxj = jEnd IfNext jFor t = 1 To UBound(a, 1)If a(t, maxj) > max ThenFlg = FalseExit SubEnd IfNextFlg = TrueEnd SubPrivate Sub Command2_Click()Dim i As Integer, m As Integer, mj As Integer, f As BooleanFor i = 1 To 4f = Falsem = 0: mj = 0Call Fp(a, i, mj, f)If f = True ThenText1.Text = Text1.Text & "(" & i & "," & mj & "):" & a(i, mj) & vbCrLf End IfNext iEnd SubPrivate Sub Command3_Click()Picture1.ClsText1 = ""End Sub13.Private Sub Command1_Click()Dim a(30) As Integer, i As Integer, j As IntegerDim Flag As BooleanRandomizeDot = Int(900 * Rnd + 100)For j = 1 To iIf t = a(j) Then Exit ForNext jIf j = i + 1 Theni = i + 1a(i) = tText1.Text = Text1.Text + Str(a(i))If i Mod 10 = 0 Then Text1.Text = Text1.Text + vbCrLfIf IsDown(a(i)) ThenList1.AddItem a(i)Flag = TrueEnd IfEnd IfLoop Until i = 30If Flag = False Then List1.AddItem "无降序数"End SubPrivate Function IsDown(n As Integer) As BooleanDim i As Integer, S As StringS = CStr(n)For i = 1 To Len(S) - 1If Mid(S, i, 1) < Mid(S, i + 1, 1) Then Exit FunctionNext iIsDown = TrueEnd FunctionPrivate Sub Command2_Click()List1.ClearText1 = ""End Sub14.Option ExplicitPrivate Sub CmdFind_Click()Dim i As Integer, p As String, st As String, st1 As StringFor i = 100 To 999st = ""If csum(i) = zyz(i, st) Thenp = CStr(i)st1 = Left(p, 1) & "+" & Mid(p, 2, 1) & "+" & Right(p, 1)List1.AddItem i & ": " & st1 & "=" & Left(st, Len(st) - 1)End IfNext iIf List1.ListCount = 0 ThenList1.AddItem "无满足要求的数!"End IfEnd SubPrivate Function csum(m As Integer) As Integer '求各位数字之和Dim i As Integer, p As Stringp = CStr(m)For i = 1 To Len(p)csum = csum + Val(Mid(p, i, 1))Next iEnd FunctionPrivate Function zyz(ByVal m As Integer, st As String) As Integer '求所有质因子之和Dim i As Integeri = 2DoIf m Mod i = 0 Thenzyz = zyz + ist = st & i & "+"m = m \ iElsei = i + 1End IfLoop Until m = 1End Function15.Private Sub Command1_Click()Dim k As Integer, i As Integerk = InputBox("请输入要求的数列项数:")List1.AddItem "共输出前" & k & "项数列"For i = 0 To kList1.AddItem p(i)NextEnd SubPrivate Function p(n As Integer) As IntegerIf n = 0 Or n = 1 Or n = 2 Thenp = 1Elsep = p(n - 2) + p(n - 3)End IfEnd Function第7章文件一、选择题二、填空题1.顺序文件和随机文件2. EOF3. Write和Print4.返回或设置当前的工作目录5.5116.文件的写语句7.Append8.LOF9.关闭10.Pattern11.【1】For Input 【2】#2 【3】Not EOF(2) 12.【1】”END”【2】Text1.Text 或者Text113.【1】Input 【2】ch 【3】Len(mystr) 14.【1】Number 【2】s15.【1】For Append As #1 【2】"end" 【3】ct,nt 16.【1】For Input 【2】For Output As #2 【3】Not EOF(1) 【4】Line Input #1,str1 【5】Close #1,#2 【6】Kill “C:\old.txt 17.【1】Open "C:StuData.txt" For OutPut As #1 【2】Write 18.【1】"C:\data.txt" 【2】#1, a(i) 【3】k>1 And a(k-1)>b 【4】k = k -1三、综合题1.Option Base 1Dim arr(100) As IntegerPrivate Sub Command1_Click()Dim i As IntegerOpen "c:\in18.txt" For Input As #6For i = 1 To 100Input #6, arr(i)Next iClose #6End SubPrivate Sub Command2_Click()Dim i As IntegerText1.Text = ""Open "c:\out18.txt" For Output As #8For i = 1 To 100If arr(i) Mod 2 <> 0 ThenText1.Text = Text1.Text & Str(arr(i))Write #8, arr(i)End IfNext iClose #8End Sub2.Dim str As StringDim n As LongPrivate Sub Command1_Click()CommonDialog1.Filter = "文本文件(*.txt)|*.txt|All Files(*.*)|*.*"CommonDialog1.FilterIndex = 1CommonDialog1.Action = 1Open CommonDialog1.FileName For Input As #2n = LOF(2)str = Input(n, #2)Text1.Text = strClose #2End SubPrivate Sub Command2_Click()Dim i As IntegerFor i = 1 To Len(str)If Asc(Mid(str, i, 1)) <= Asc("Z") And Asc(Mid(str, i, 1)) >= Asc("A") Then Mid(str, i, 1) = LCase(Mid(str, i, 1))ElseIf Asc(Mid(str, i, 1)) <= Asc("z") And Asc(Mid(str, i, 1)) >= Asc("a") Then Mid(str, i, 1) = UCase(Mid(str, i, 1))End IfNext iText1.Text = strEnd SubPrivate Sub Command3_Click()Open "D:\out.txt" For Output As #3Print #3, strClose #3End Sub第8章程序调试一.选择题二.改错题1.a(i)=int(Rnd*19)+1 →a(i)=int(rnd*20)+1For l=1 to a(i)+1 →for i=2 to a(i)+1If l=a(i) →if l <> a(i)K=k+1 →k=k-1。
VB程序设计学习与实验指导书答案(包含实验答案)
VB学习与实验指导测试题参考答案第一章第二章第三章第四章第五章第六章第七章第八章第九章综合测试题一综合测试题二下篇实验教程实验2 Visual Basic 变量、函数与表达式的使用实验2-1 算术运算符的使用13178332262-2-22007-10-153 2.857143 2.85714285714286实验2-2 字符运算符的使用20071020071020172007-10-10102007-10-20出错,类型不匹配实验2-3 关系运算符的使用FalseFalseFalseFalseFalseFalseFalseTrueFalseTrue实验2-4 逻辑运算符的使用TrueTrueFalseTrueFalseFalseTrueTrueFalse5-59实验2-5 常用函数的使用3.14 3.147.389056098930651 -1 .999999998205103 4-1 1 0.70554755825 251250 0A a65 9748 688 -98 -89 -9aaa 4.5 aaa4.516 5Visua 6.0sua Basic Basic 6.0abcde EFGBasic Basic BasicVisual Basic 6.0 Basic8 8aaa dd2011-3-152011-3-15 14:35:5215320113001.731.731.7317.32E-010173%实验3 算法基础及程序控制结构实验3-1 三个数的交换A=CC=BB=TBC实验3-2 求周长和面积Const PI=3.14159262*PI*RPI*R*RPicture1.ClsFormat(L, ".00")Format(M, ".00")实验3-3 求分段函数的值x=Val(Text1.Text)y=1+Sin(x)y=Log(x)Text1.Text = ""Text2.Text = ""实验3-4 求一元二次方程的根Val(Text2.Text)Val(Text3.Text)b ^ 2 - 4 * a * c"x1=" & (-b + Sqr(delt)) / (2 * a)"x2=" & (-b - Sqr(delt)) / (2 * a)Text2.Text = ""Text3.Text = ""End实验3-5 判断素数N Mod k = 0k=NN Mod i=0k=2实验3-6 求最大公约数和最小公倍数M<NL=ML=NM Mod k = 0 And N Mod k = 0Text3.Text = kExit ForM>NL=ML=Nk Mod M = 0 And k Mod N = 0Text4.Text = kExit For实验3-7 判断升序数、降序数CStr(N)Len(S) – 1Mid(S, k, 1) >= Mid(S, k + 1, 1)k = Len(S)N = Val(Text1.Text)S = CStr(N)For k = 1 To Len(S) - 1If Mid(S, k, 1) <= Mid(S, k + 1, 1) Then Exit For Next kk = Len(S)实验3-8 判断回文数1Len(s)\2-1Mid(S, k, 1) <> Mid(S, Len(S) - k + 1, 1)k = Len(S) \ 2Mid(S, k, 1) + S1S = S1实验3-9 求级数的值Val(Text1.Text)1x ^ ns * nt / s <= 10 ^ -6Text2.Text = y实验3-10 查找数字串并求和Text1.Text = ""Text2.Text = ""List1.ClearText1.TextFalseWhile Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Flag = Truek = k * 10 + Mid(s, i, 1)i = i + 1Flag = Truesum + kText2.Text = sum实验3-11 随机产生20个奇数Int((99 - 10 + 1) * Rnd) + 10a Mod 2 = 1n Mod 5 = 0Picture1.Cls实验3-12 加密解密Chr(Asc("a") + (Asc(c) - Asc("a") + 3) Mod 26)c = Chr(Asc("A") + (Asc(c) - Asc("A") + 3) Mod 26) c & s2Text2.TextLen(s2)Mid(s2, i, 1)c = Chr(Asc("a") + (Asc(c) - Asc("a") + 23) Mod 26) c = Chr(Asc("A") + (Asc(c) - Asc("A") + 23) Mod 26) c & s1s1Text1.Text = ""Text2.Text = ""实验3-13 统计单词个数Text1.TextMid(s, i, 1) <> " " And i <= Len(s)i = i + 1Mid(s, start, i - start)nText1.Text = ""List1.Clear实验4 数组的使用实验4-1 一维数组的产生及输出i = 1 To 20Int((9 - 0 + 1) * Rnd + 0)i = 1 To 20Print a(i);Printi = 1 To 20Picture1.Print a(i);If i Mod 5 = 0 Then Picture1.Printi = 1 To 20Text1.Text & Space(2) & a(i)If i Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf v In aIf i Mod 5 = 0 Then Picture2.Print实验4-2 选手得分Int((50 - 10 + 1) * Rnd + 10) / 10i = 1 To 6sum = sum + score(i)max = score(1)min = score(1)score(i) > max Then max = score(i)score(i) < min Then min = score(i)(sum - max - min) / 4实验4-3 产生10个互不相同的整数Int((999 - 10 + 1) * Rnd + 10)t Mod 10 = 5Then Exit Forn= n + 1a(i) = tFor i = 1 To 10Print a(i);If i Mod 5 = 0 Then PrintNext i实验4-4 统计数字出现的次数IsNumeric(S) = FalseExit SubLen(S)c >= "0" And c <= "9"A(c) = A(c) + 1A(k) <> 0m = m + 1实验4-5 排序1 To 10Int((99 - 10 + 1) * Rnd + 10)Text1.Text & A(n) & " "1 To 9i + 1 To 10A(i) > A(j)T = A(j)A(j) = A(i)A(i) = T1 To 910 - iA(j) > A(j + 1)T = A(j + 1)A(j + 1) = A(j)A(j) = T1 To 10Text3.Text = Text3.Text & A(i) & " "10T = A(i)ji - 1k + 11 To 10Text4.Text = Text4.Text & A(i) & " "实验4-6 二维数组的产生及输出1 To 41 To 5Int((9 - 0 + 1) * Rnd + 0)1 To 41 To 5Print A(i, j);Print1 To 41 To 5Picture1.Print A(i, j);Picture1.Print1 To 41 To 5Text1.Text = Text1.Text & A(i, j) & " "Text1.Text = Text1.Text & vbCrLf实验4-6 查找最大和最小元素及其位置1 To 31 To 4A(i, j) = Int((99 - 10 + 1) * Rnd + 10)Picture1.Print A(i, j);Picture1.PrintA(1, 1), 1, 1A(1, 1), 1, 1A(i, j)ijA(i, j) < minA(i, j)ij"最大元素" & "A(" & maxi & "," & maxj & ")=" & max "最小元素" & "A(" & mini & "," & minj & ")=" & min实验4-7 矩阵转置Dim A() As Integer"请输入N的值"ReDim A(N, N) As IntegerFor i = 1 To NFor j = 1 To NA(i, j) = Int((99 - 10 + 1) * Rnd + 10)Text1.Text = Text1.Text & A(i, j) & " "Next jText1.Text = Text1.Text & vbCrLfNext it = A(i, j)A(i, j) = A(j, i)A(j, i) = tFor i = 1 To NFor j = 1 To NText2.Text = Text2.Text & A(i, j) & " "Next jText2.Text = Text2.Text & vbCrLfNext i实验5 过程实验5-1 孪生素数和降序素数Dim i As IntegerFor i = 2 To N - 1If N Mod i = 0 Then Exit FunctionNext iPrime = TrueDim a As IntegerDim b As Integera = N \ 10b = N Mod 10If a > b ThenDecNumber = TrueElseDecNumber = FalseEnd If10 To 100Prime(i) = True And Prime(i + 2) = TrueList2.AddItem i & "和" & i + 2DecNumber(i) = True And Prime(i) = TrueList3.AddItem i实验5-2 求多项式和k = 1a = f(x, k)S + ak = k + 1Single As SingleDim i As Integer, a As Singlea = (x + 1) / xFor i = 2 To ka = a * (x + i) / ((2 * i - 1) * x)Next ia实验5-3 进制转换Asc(C) - Asc("A") + 10Left(S, k - 1)Mid(S, k + 1)Change(Mid(S2, i, 1)) * N ^ (0 - i)T1 + T2Tran(8, S)Tran(16, S)Not (C >= "0" And C <= "7" Or C >= "A" And C <= "F" Or C = ".")实验5-4 Armstrong数i As Long, a As Long, b As LongCombo1.Text实验5-5Option Base 1Dim a(5) As IntegerDim b(5) As Integerb(i) = i * i + 1Text2.Text = Text2.Text & b(i) & " "1 To 51 To 5Gcd(a(i), b(j)) = 1Gcd = KExit For实验5-6Create(a)Output(a)Sort(a)Output(a)GetMaxMin(a, MaxData, MinData)MaxDataMinDataAverage(a)Int((99 - 10 + 1) * Rnd + 10)1 To UBound(a)a(i);a(i) > a(j)t = a(j)a(j) = a(i)a(i) = t2 To UBound(a)a(i) > MM = a(i)a(i) < NN = a(i)s = s + a(i)Average = s / UBound(a)实验6 界面设计实验6-1 用户登陆MsgBox "请登录!"PassWordInput=TxtPassW.TextUserIdInput=UserId And PassWordInput=PassWordCmdReset_Click实验6-2 学籍登记OptXb(0).Value = TrueList1.AddItem Space(4) & xh & Space(6) & xm & Space(6) & xb & Space(12) & xy & Space(16) & zy & Space(4)List1.RemoveItem List1.ListIndex实验6-3 字体格式设置Select Case OpFontCheck2.Value = 1OpColor = IndexOpFont = Index实验6-4 兴趣调查List1.AddItem ItemEndSelect Case IndexItem = Text1.Text实验6-5 调色板。
vb实验报告标准答案
竭诚为您提供优质文档/双击可除vb实验报告标准答案篇一:Vb郭贤海实验报告及答案实验1.1设计一个程序,程序运行的初始界面如图1-1所示。
当单击“显示”按钮时,在文本框中显示“欢迎使用Vb!”(图1-1);当单击“清除”按钮时,清除文本框内的文本;当单击“退出”按钮时,结束程序运行。
图1-1程序运行初始界面图1-2单击“显示”按钮后的程序界面实验1.2设计一个程序,程序运行的初始界面如图1-3所示,其中“显示”按钮为不可用。
同时要求:(1)当单击“改变文字”按钮时,在左边标签文字内容改为“你好,张三!”,同时“改变文字”按钮变为不可用(图1-4);(2)当单击“隐藏”按钮时,将左边标签设为不可见,同时“隐藏”按钮变为不可用,“显示”按钮变为可用(图1-5);(3)当单击“显示”按钮时,重新显示左边标签,同时“隐藏”按钮变为可用,“显示”按钮变为不可用(图1-4)。
图1-3第1题的程序运行初始界面图1-4单击“改变文字”按钮后的程序界面图1-5单击“隐藏”按钮后的程序界面四、实验原始记录实验1.1程序的界面设计。
(可以是多张主要的图。
下面的图要替换成你们自己设计的图。
如何取图?设计好界面,按“printscreensysRq”键,打开画图软件,单击“编辑|粘贴”命令,利用菜单栏下方的“选定”功能,选中窗体,按“ctrl+c”键,然后选中下面的实验样例图,按“ctrl+V”键,替换掉)程序代码。
privatesubcommand1_click()Text1.Text="欢迎使用Vb!"endsubprivatesubcommand2_click()Text1.Text=""endsubprivatesubcommand3_click()endendsub实验1.2程序的界面设计。
(可以是多张主要的图。
下面的图要替换成你们自己设计的图)程序代码。
privatesubcommand1_click()Label1.Visible=Truecommand2.enabled=Truecommand1.enabled=Falseendsubprivatesubcommand2_click()Label1.Visible=Falsecomma nd2.enabled=Falsecommand1.enabled=Trueendsub privatesubcommand3_click()Label1.caption="你好,张三!"command3.enabled=Falseendsub五、实验结果及分析实验1.1运行结果。
vb实验作业参考答案
VB实验作业参考答案作业一窗体设计 (2)作业二计算器 (4)作业三人民币张数求电阻值 (6)作业四(必做)建康城 (8)作业五阶乘累加 (9)作业六(必做)九九乘法表 (11)作业七(必做)I NPUT B OX 函数输入12个整数,赋值给3×4的二维数组 (12)作业八递归函数计算两个正整数的最大公约数,递归公式为 (13)作业九(必做)家电提货单 (15)作业十统计某个文本文件中各英文字母出现的次数,不区分大小写,并将结果打印到窗体上。
(17)作业十一设计一个程序,用于打开1个windows应用程序,如打开“记事本”“画图”、“计算器”等。
(19)作业十二通过菜单选择,对字体、字号进行设置 (21)作业一1.简答题(略)2.编程题:1)单击窗体后在窗体上显示“您好!×××同学”。
要求:(1)程序中用自己的姓名替代“×××”。
(2)文字以红色、仿宋体、加粗、三号字显示,并在字下加横线。
(3)建立一个命令按钮,结束时单击此按钮退出。
答案参照课本P27的例1-6。
2)设计一窗体,窗体上有1个文本框(Text1)、1个命令按钮(Command1),运行时文本框中显示“Visual Basic程序设计”,命令按钮标题为“结束”,文本框及命令按钮能随窗体大小的调整而自动调整大小及位置,其中调整文本框使其:Left=0,Top=0,宽度和高度都为窗体的一半;命令按钮:始终位于窗体右下角位置。
请编写:(1)用代码初始化各控件(提示:可写在Form_Load事件中)。
(2)文本框控件随窗体的大小而调整大小的代码,以及调整命令按钮位置始终位于窗体右下角的代码(提示:调整大小位置的代码写在Form_Resize事件中)。
(3)结束程序运行的代码(命令按钮)。
程序代码:Private Sub Form_Load()Text1.Left = 0Text1.Top = 0Text1.Width = Form1.Width / 2Text1.Height = Form1.Height / 2Command1.Left = Form1.ScaleWidth - Command1.WidthCommand1.Top = Form1.ScaleHeight - Command1.Height End SubPrivate Sub Form_Resize()Call Form_LoadEnd SubPrivate Sub Command1_Click()EndEnd Sub作业二1.填空题:(1)Visual Basic 算术表达式a+b/(b+c/(d+e/Sqr(2*a*b)))对应的数学表达式( ab ed c b ba 2+++ )。
VB经典例题(附答案)
实验4:编写一个程序。
要求在窗体内设置7个标签(Label)及7个文本框(TextBox),将每个标签的Text属性值设置为如下表达式。
在程序运行时,单击窗体空白区,可在对应的文本框中输出这些表达式的值。
1)8*3*6\22)7/6*3.2/2.15*(5.5+3.5)3)34\4+4.0^5/124)65\3 mod 3.4*fix(3.8)5)“abg”+”34” & “erert”6)true or not (8+3>=23)7)7>2 or 4<9实验目的:学习VB运算符的使用。
Public Class Form1Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ClickTextBox1.Text = 8 * 3 * 6 \ 2TextBox2.Text = 7 / 6 * 3.2 / 2.15 * (5.5 + 3.5)TextBox3.Text = 34 \ 4 + 4.0 ^ 5 / 12TextBox4.Text = 65 \ 3 Mod 3.4 * Fix(3.8)TextBox5.Text = """abg""" + """34""" & """erert"""TextBox6.Text = True Or Not (8 + 3)>= 23TextBox7.Text = 7 > 2 Or 4 < 9End SubEnd Class实验5:编写一个程序。
设a=2,b=3,c=4,d=5,S="ABCDEFGHI]K",求下列表达式的值:(1) 5+(a+b)2(2) cos(b)(sin(a)+1) (3) 8e3ln2(4) Left(S,4) (5) Mid(S, 3,4) (6) Instr(S, "EFG")(7) Lcase(Right(S, 5)) (8) Len(Mid((S, 3)实验目的:学习VB中函数的使用。
VB实验作业参考答案
1)单击窗体后在窗体上显示“您好!×××同学”。
要求:(1)程序中用自己的姓名替代“×××”。(2)文字以红色、仿宋体、加粗、三号字显示,并在字下加横线。(3)建立一个命令按钮,结束时单击此按钮退出。
答案参照课本P27的例1-6。
2)设计一窗体,窗体上有1个文本框(Text1)、1个命令按钮(Command1),运行时文本框中显示“Visual Basic程序设计”,命令按钮标题为“结束”,文本框及命令按钮能随窗体大小的调整而自动调整大小及位置,其中调整文本框使其:Left=0,Top=0,宽度和高度都为窗体的一半;命令按钮:始终位于窗体右下角位置。请编写:
Command1.Top = Form1.ScaleHeight - Command1.Height
End Sub
Private Sub Form_Resize()
Call Form_Load
End Sub
Private Sub Command1_Click()
End
Dim r1 As Single, r2 As Single, Rp As Single, Rs As Single
r1 = InputBox("请输入第一个电阻值:")
r2 = InputBox("请输入第二个电阻值:")
Rp = (r1 * r2) / (r1 + r2)
Rs = r1 + r2
程序代码:
Private Sub Command1_Click()
Dim sg As String, tz As String, bz As String
sg = Text1.Text
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VB实验作业参考答案作业一窗体设计 (2)作业二计算器 (4)作业三人民币张数求电阻值 (6)作业四(必做)建康城 (8)作业五阶乘累加 (9)作业六(必做)九九乘法表 (11)作业七(必做)I NPUT B OX 函数输入12个整数,赋值给3×4的二维数组 (12)作业八递归函数计算两个正整数的最大公约数,递归公式为 (13)作业九(必做)家电提货单 (15)作业十统计某个文本文件中各英文字母出现的次数,不区分大小写,并将结果打印到窗体上。
(17)作业十一设计一个程序,用于打开1个windows应用程序,如打开“记事本”“画图”、“计算器”等。
(19)作业十二通过菜单选择,对字体、字号进行设置 (21)作业一1.简答题(略)2.编程题:1)单击窗体后在窗体上显示“您好!×××同学”。
要求:(1)程序中用自己的姓名替代“×××”。
(2)文字以红色、仿宋体、加粗、三号字显示,并在字下加横线。
(3)建立一个命令按钮,结束时单击此按钮退出。
答案参照课本P27的例1-6。
2)设计一窗体,窗体上有1个文本框(Text1)、1个命令按钮(Command1),运行时文本框中显示“Visual Basic程序设计”,命令按钮标题为“结束”,文本框及命令按钮能随窗体大小的调整而自动调整大小及位置,其中调整文本框使其:Left=0,Top=0,宽度和高度都为窗体的一半;命令按钮:始终位于窗体右下角位置。
请编写:(1)用代码初始化各控件(提示:可写在Form_Load事件中)。
(2)文本框控件随窗体的大小而调整大小的代码,以及调整命令按钮位置始终位于窗体右下角的代码(提示:调整大小位置的代码写在Form_Resize事件中)。
(3)结束程序运行的代码(命令按钮)。
程序代码:Private Sub Form_Load()Text1.Left = 0Text1.Top = 0Text1.Width = Form1.Width / 2Text1.Height = Form1.Height / 2Command1.Left = Form1.ScaleWidth - Command1.WidthCommand1.Top = Form1.ScaleHeight - Command1.Height End SubPrivate Sub Form_Resize()Call Form_LoadEnd SubPrivate Sub Command1_Click()EndEnd Sub作业二1.填空题:(1)Visual Basic 算术表达式a+b/(b+c/(d+e/Sqr(2*a*b)))对应的数学表达式( ab ed c b ba 2+++ )。
(2)产生一个10-99之间的随机整数的表达式( int(rnd*90)+10 )。
(3)整形变量X 中存放了一个两位数,要将两位数交换位置,例如,73变成37,实现的表达式是( (x mod 10)*10+ x\10 )。
(4)算术表达式Fix(-3.95)+int(-3.02)+Cint(-3.5)+25 mod 10\3的值是( -10 )。
(5)表达式Ucase(Mid(″abcdefgh ″,3,4))的值是( CDEF )。
2.使用立即窗口显示下列表达式的值(设x=5,y=15,z=3),并分析所输出的结果。
(1)Len(x & y &''z'') (2)Sgn(10 mod 6) & x+y(3)x mod z +x^2\y+z (4)x^2-y*2>3*z and z^3<>x^2(5)(y mod 10) *10+y\10 (6)Mid(str(x^3),2,2) & y+z(7)Ucase(Left(Mid(''This is a Book'',6),4)) (8)Date()+10(9)Timer Mod 3600 (10)Hour(time())3.编程题:(1)编一个模拟简易计算器的程序,运行界面如下图所示:程序代码:Private Sub Form_Load()Label1.Caption = ""End SubPrivate Sub Command1_Click() ' 加法Label1.Caption = "+"Text3 = Str$(Val(Text1) + Val(Text2))End SubPrivate Sub Command2_Click() ' 减法Label1.Caption = "-"Text3 = Str$(Val(Text1) - Val(Text2))End SubPrivate Sub Command3_Click() ' 乘法Label1.Caption = "×"Text3 = Str$(Val(Text1) * Val(Text2))End SubPrivate Sub Command4_Click() ' 除法Label1.Caption = "÷"Text3 = Str$(Val(Text1) / Val(Text2))End SubPrivate Sub Command5_Click() ' 清除Text1.Text = ""Text2.Text = ""Text3.Text = ""Label1.Caption = ""End Sub(2)编一个程序,当单击窗体时,在窗体上任意位置,随机输出一个大写的英文字母。
提示:随机大写的英文字母由表达chr(Int(Rnd*26)+65)产生,窗体上的随机位置通过设置当前坐标CurrentX,CurrentY属性来确定。
程序代码:Private Sub Form_Click()Dim ch As StringForm1.CurrentX = Form1.ScaleWidth * Rnd '随机确定当前x坐标Form1.CurrentY = Form1.ScaleHeight * Rnd '随机确定当前y坐标ch = Chr(65 + Int(26 * Rnd)) '随机产生一个大写字母Print chEnd Sub作业三1.填空题;(1)下面程序执行的结果是(A=2 B=3 C=2)。
Private Sub Form_Click()a = 1:b = 2:c = 3a = bb = cc = aPrint "a="; a; "b="; b; "c="; cEnd Sub(2)下面程序执行的结果是(5)。
Private Sub Form_Click()a$ = "123": b$ = "456"c = Val(a$) + Val(b$)Print c \ 100End Sub(3)下面程序执行的结果是(BABCBACBC)。
Private Sub Form_Click()x$ = "a": y$ = "b": z$ = "c"x$ = y$ & x$: y$ = y$ & z$: z$ = x$ & z$ & y$Print x$ + y$ + z$End Sub(4)下面程序执行的结果是( 1 2 False)。
Private Sub Form_Click()Dim x%, y%, z%x = 1: y = 2z = x = yPrint x; y; xEnd Sub(5)当程序运行后,在文本框Text1中输入1234,窗体上的输出结果是(1-12-123-1234-)。
Private Sub Text1_Change()Print Text1 & "-";End Sub2.编程题:1)编写程序,输入一个职工的工资,打印输出发给该职工的人民币张数最少的方案。
程序代码:Public Sub Form_click()Dim hundred As Integer '100元票面数量Dim fifty As Integer '50元票面数量Dim Twenty As Integer '20元票面数量Dim ten As Integer '10元票面数量Dim five As Integer '5元票面数量Dim two As Integer '2元票面数量Dim one As Integer '1元票面数量Dim total As Integer '总计最小钞票数量Dim X As Integer '职工工资Dim tmp As IntegerX = Val(InputBox("输入职工工资 X=?", "输入框"))hundred = X \ 100 '求100元票面数量tmp = X Mod 100 ' 求剩余金额fifty = tmp \ 50tmp = tmp Mod 50Twenty = tmp \ 20tmp = tmp Mod 20ten = tmp \ 10tmp = tmp Mod 10five = tmp \ 5tmp = tmp Mod 5two = tmp \ 2one = tmp Mod 2total = hundred + fifty + Twenty + ten + five + two + oneForm1.Print "100元票" & (hundred) & "张", "50元票" & Str(fifty) & "张"Form1.Print "20元票 " & Str(Twenty) & "张", "10元票" & Str(ten) & "张"Form1.Print "5元票" & Str(five) & "张", "2元票" & Str(two) & "张"Form1.Print "1元票" & Str(one) & "张"Form1.PrintForm1.Print "-----------------------------------------------"Form1.Print "合计票:" & Str(total) & "张"End Sub2)编写程序,使用InputBox函数输入两个电阻的值,求它们并联和串联的电阻值,使用MsgBox消息框输出结果,要求结果保留小数点后三位。