《vb代码5费下载》由会员分享,可在线阅读,更多相关《vb代码5费下载(10页珍藏版)》请在金锄头文库上搜索。
1、11!+2!+3!+Private Sub Command1_Click()Dim n%, i%, s%, m%n =val( InputBox(请输入一个正整数) 编写程序计算m = 1For i = 1 To nm = m * is = s + mNext iLabel1.Caption = sEnd Sub2随机产生10个数,最大和最小,对调,蓝色标记Private Sub Command1_Click()Dim a(1 To 10) As Integer, i%, min%, max%, t%Print 产生的10个数是:For i = 1 To 10a(i) = Int(Rnd *
2、91 + 10)Print a(i);Next imin = 1max = 1For i = 2 To 10If a(i) a(max) Then max = iIf a(i) a(min) Then min = iNextt = a(max)a(max) = a(min)a(min) = tPrintPrint 调换之后的数:Form1.FontSize = 16Form1.ForeColor = vbBlueFor i = 1 To 10Print a(i);Next iEnd Sub3水平滚动条,乘积的Private Sub Form_Load()HScroll1.Min = 100HS
3、croll1.Max = 200HScroll2.Min = 100HScroll2.Max = 200End SubPrivate Sub HScroll1_Change()Label1.Caption = HSEnd SubPrivate Sub HScroll2_Change()End Sub4AaaaBbbbCcccdddd Private Sub Command1_Click() Dim i%, s As String s = a For i = 1 To 4 Print String(4 - i, ); String(4, s) s = Chr(Asc(s) + 1) Next i
4、 End Sub5 计算S=1+(1+2)+(1+2+3)+(1+2+3+4)+.+(1+2+3+4+5+.n) _请在给出的)Sum = 0For i = 1 To nj = j + iSum = Sum + jNext iText1.Text = s= & SumEnd Sub6通过键盘输入10个数 , 求这十个数的平均数?其中小于平均数的数字个数? _将小于平均数的数字个数及这十个数的平均数以红色16号字显示在form上 Dim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Val(InputBox(请输入第 & i & 个数)Next iPrin
5、t 输入的十个数为:For i = 1 To 10Print a(i);Next iFor i = 1 To 10Sum = Sum + a(i)Next iaver = Sum / 10PrintForm1.FontSize = 16Form1.ForeColor = vbRedPrint 十个数的平均数为:; averPrint 小于平均数的数为:For i = 1 To 10If a(i) aver ThenPrint a(i);End IfNext iEnd Sub7.计算S=1+22+23+24.+210.请在给出的VB3-12.FRM文件中的Private Sub Command1
6、_Click()中完成程序,要求程序运行时,计算结果显示在标签控件Label1中。 _S=1+22+23+24.+210.=21+22+23+24.+210-1Sum = 0For i = 1 To 10Sum = Sum + 2 iNext is = Sum - 1Print s;End Sub10个1100之间的数并存放在数组中,以蓝色17号字显示数组? _找到其中6的倍数,并求出这些数的和,将这些6的倍数和他们的和以蓝色16号字显示在窗体中ClsDim a(1 To 10) As IntegerFor i = 1 To 10a(i) = Int(Rnd * 100 + 1)Next iF
7、orm1.ForeColor = vbBlueForm1.FontSize = 17Print 十个随机数为:For i = 1 To 10Form1.Print a(i);Next iSum = 0PrintForm1.ForeColor = vbBlueForm1.FontSize = 16Print 是6的倍数为:For i = 1 To 10If a(i) Mod 6 = 0 ThenPrint a(i);Sum = Sum + a(i)End IfNext iPrintPrint 6的倍数之和为:Print Sum;End Sub9.S=1+(1+2)+(1+2+3)+(1+2+3+
8、4)+.+(1+2+3+4+5+.n)n = InputBox(请输入正整数n)Sum = 0: j = 0For i = 1 To nj = j + iSum = Sum + jNext iPrint SumEnd Sub10个1100之间的整数存放在数组中,以蓝色18号字显示窗体中 _找到其中最大小的数,并将此数从数组中删除 _将删除以后的数组以蓝色18号字显示在窗体中Color = vbBlueForm1.FontSize = 18For i = 1 To 10a(i) = Int(Rnd * (91) + 10)Next iFor i = 1 To 10Print a(i);Next
9、ii = 1For j = i + 1 To 10If a(i) a(j) Thenk = a(i)a(i) = a(j)a(j) = kEnd IfNext jPrintPrint 最大数为:Print a(1)Print 删除最大数重新排列为:For i = 2 To 10Print a(i);Next i Private Sub Command1_Click()编写程序Dim x As Integer, y As Integer, t As Integer, r As Integerx = Val(Text1.Text)y = Val(Text2.Text)If x y Then t =
10、 x: x = y: y = tr = x Mod yDo While (r 0)x = y: y = r: r = x Mod yLoopLabel4.Caption = 最大公约数= & yEnd Sub12.12345,2468,369,48,5Private Sub Command1_Click()编写程序打印给出的图形Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 6 - iPrint i * j; Spc(1);Next jPrintNext iEnd Sub+22+222+Private Sub Form_Clic
11、k()Dim i As Integer, j As Long, sum As Long, n As Longn = Val(InputBox(请输入一个整数)j = 0For i = 1 To nj = j + 2 * 10 (i - 1)sum = sum + jNext iPrint 2+22+222+.; j; =; sumEnd Sub14.1+22+333+Private Sub Form_Click()Dim i As Integer, j As Long, sum As Long, n As Long, k As Integern = Val(InputBox(请输入一个整数)F
12、or i = 1 To nFor j = 1 To ik = k + i * 10 (j - 1)Next jsum = sum + kNext iPrint 1+22+33+.; k; =; sumEnd Sub15.12 43 6 94 8 12 165 10 15 20 25Private Sub Form_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To iPrint i * j; Spc(2);Next jPrintNext iEnd Sub16.通过键盘输入10个数,找到其中大于60的数,并求出这些数的和
13、,将大于60的数和和它们的和一红色16号字显示在标签中。Private Sub Command1_Click()Dim x%, i%, sum%, s As Strings = 大于60的数Print 10个数为For i = 1 To 10 x = Val(InputBox(请输入十个正整数) Print x; If x 60 Then sum = sum + x s = s & x & End IfNext iLabel1.ForeColor = vbRedLabel1.FontSize = 16Label1.Caption = s & 总和 & sumEnd Sub17.编写调色板程序,
14、当改变3种颜色的滚动条时,相应的label4,label5,label6显示滚动条的变化数值,而label7显示调出的颜色.Private Sub B_Change()Label7.BackColor = RGB(R.Value, G.Value, B.Value)End SubPrivate Sub G_Change()Label7.BackColor = RGB(R.Value, G.Value, B.Value)End SubPrivate Sub Label7_Click()End SubPrivate Sub R_Change()Label7.BackColor = RGB(R.Value, G.Value, B.Value)End Sub18.1在t