实验一2.Private Sub Command1_Click() Label1.ForeColor = vbRedEnd SubPrivate Sub Command2_Click() Label1.BackColor = vbBlueEnd SubPrivate Sub Command3_Click() Label1.ForeColor = Form1.ForeColor Label1.BackColor = Form1.BackColor End SubPrivate Sub Command4_Click()EndEnd Sub3.Private Sub Command1_Click()Text1.FontSize = 30Command1.Enabled = False Command2.Enabled = True Command3.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text1.FontSize = 6Command2.Enabled = False Command1.Enabled = True Command3.Enabled = TrueEnd SubPrivate Sub Command3_Click()Text1.FontSize = 9Command3.Enabled = False Command1.Enabled = True Command2.Enabled = TrueEnd Sub4.Private Sub Command1_Click()a = 3.14r = Val(Text1.Text)Text2.Text = 2 * a * rText3.Text = a * r * rEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text3.Text = ""End SubPrivate Sub Command3_Click()EndEnd Sub5.Private Sub Command1_Click()Label1.BorderStyle = 1End SubPrivate Sub Command2_Click()Label1.Left = Label1.Left + 200Label1.Top = Label1.Top - 150End SubPrivate Sub Command3_Click()Label1.Visible = FalseEnd SubPrivate Sub Command4_Click()Label1.Visible = TrueEnd Sub6.Private Sub Command1_Click()Text2.Text = Text1.SelTextText3.Text = Text1.SelLengthText1.Locked = TrueEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd Sub7.Private Sub Command1_Click()Dim r, q, vq = Val(Text2.Text)r = Val(Text1.Text)v = Val(Text3.Text)Label5.Caption = r * 60 * 60 + q * 60 + v End SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text2.SetFocusText3.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Text1_keypress(keyascii As Integer) If keyascii = 13 Then Text2.SetFocusEnd SubPrivate Sub Text2_keypress(keyascii As Integer) If keyascii = 13 Then Text3.SetFocusEnd Sub8.(1)Dim a, v, s, cPrivate Sub Text1_KeyPress(KeyAscii As Integer) a = Val(Text1.Text)If KeyAscii = 13 Thenv = a * a * as = 6 * a * ac = 4 * aLabel5.Caption = vLabel6.Caption = sText2.Text = cEnd IfEnd Sub(2)Dim a, s, v, cPrivate Sub Text1_LostFocus()a = Val(Text1.Text)c = 12 * av = a * a * as = 6 * a * ac = Val(Text2.Text)Label5.Caption = vLabel6.Caption = sEnd Sub(3)Dim a, v, s, cPrivate Sub Text1_Change()a = Val(Text1.Text)v = a * a * as = 6 * a * ac = 12 * aLabel5.Caption = vLabel6.Caption = sText2.Text = cEnd Sub实验二2.Private Sub Picture1_Click()a = Int(Val(Text1.Text) / 100)b = Int((Val(Text1.Text) Mod 100) / 10)c = Int((Val(Text1.Text) Mod 100) Mod 10)d = a * a + b * b + c * cPicture1.Print a; b; c; dEnd Sub3.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)s = a / bText3.Text = Format(s, "###.##")Text4.Text = a \ bText5.Text = a Mod bEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd Sub4.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)Picture1.Print Int(Rnd * (b - a + 1) + a); Picture1.Print Int(Rnd * (b - a + 1) + a); Picture1.Print Int(Rnd * (b - a + 1) + a)t1 = Int(Rnd * (b - a + 1) + a)t2 = Int(Rnd * (b - a + 1) + a)t3 = Int(Rnd * (b - a + 1) + a)s = Sqr(t1 + t2 + t3)f = Format(s, "##.####")Picture1.Print "三个数和的平方根" & "=" & f End SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd Sub5.Private Sub Form_Load()Text1.Text = ""Text2.Text = ""End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Dim i, xIf KeyAscii = 13 ThenIf Len(Text1) > 25 Theni = InStr(Text1, Text2)x = Left(Text1, i - 1) + Mid(Text1, i + Len(Text2)) End IfEnd IfPicture1.Print xEnd Sub6.Private Sub Command1_Click()RandomizeText1.FontSize = Text1.FontSize * Int(Rnd * 3 + 2) Command1.Enabled = FalseCommand2.Enabled = TrueCommand3.Enabled = TrueEnd SubPrivate Sub Command2_Click()RandomizeText1.FontSize = Text1.FontSize / Int(Rnd * 3 + 2) Command1.Enabled = TrueCommand2.Enabled = FalseCommand3.Enabled = TrueEnd SubPrivate Sub Command3_Click()Text1.FontSize = 9Command1.Enabled = TrueCommand2.Enabled = TrueCommand3.Enabled = FalseEnd Sub实验三2.Private Sub Form_Click()FontItalic = TruePrint "斜体→程序设计语言"FontName = "黑体"Print "黑体→程序设计语言"FontName = "幼圆"Print "幼圆→程序设计语言"FontName = "楷体_gb2312"Print "楷体→程序设计语言"FontName = "隶书"Print "隶书→程序设计语言"FontName = "@宋体"Print "设置宋体字体旋转"End Sub3.Private Sub Command1_Click()Dim a&, day&, hour&, minute&, second&a = Val(Text1.Text)day = Int(a \ 86400)hour = Int((a Mod 86400) \ 3600)minute = Int((a Mod 3600) \ 60)second = Int(a Mod 60)Picture1.Print a&; "秒" & "=" & day&; "天" & hour&; "小时" & minute&; "分" & second; "秒" End Sub4.Private Sub Command1_Click()r = InputBox("输入圆半径")Text1.Text = rLabel5.Caption = 3.14 * r * rLabel6.Caption = 4 * 3.14 * r * rLabel7.Caption = 4 / 3 * 3.14 * r * r * rEnd SubPrivate Sub Command2_Click()Label5.Caption = ""Label6.Caption = ""Label7.Caption = ""Text1.SetFocusText1.Text = ""End Sub6.Private Sub Command1_Click()Dim H%, F%, X%, Y%H = Val(Text1.Text)F = Val(Text2.Text)X = (4 * H - F) / 2Y = (F - 2 * H) / 2Picture1.Print "鸡的数量"; XPicture1.Print "兔子的数量"; YEnd SubPrivate Sub Command2_Click()Label3.Caption = ""Text1.Text = ""Text2.Text = ""Text1.SetFocusEnd Sub7.Private Sub Form_Load()Text1.Text = ""Text2.Text = ""Label4.Caption = ""End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Dim p, dIf KeyAscii = 13 Thenp = Val(Text1.Text)d = Val(Text2.Text)s = p * dc = s - (s * 0.005 + s * 0.015 + s * 0.035 + 27.83) Label4.Caption = Format(c, "####.##")End IfEnd Sub实验四2.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)If a + b > c Or a + c > b Or b + c > a Thenp = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c))Label5.Caption = Format(s, "#00.000")ElseMsgBox "不能构成三角形"End IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Label5.Caption = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocusEnd SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入错误!重新输入"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text3.SetFocusEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "输入错误!重新输入"Text2.Text = ""Text2.SetFocusEnd IfEnd SubPrivate Sub Text3_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入错误!重新输入"Text3.Text = ""Text3.SetFocusEnd IfEnd Sub3.Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)Select Case Text3.TextCase "+"Text4.Text = a + bCase "-"Text4.Text = a - bCase "*"Text4.Text = a * bCase "/"If b = 0 ThenMsgBox "除数为零"Text2.Text = ""ElseText4.Text = a / bEnd IfCase "\"If b = 0 ThenMsgBox "除数为零"Text2.Text = ""ElseText4.Text = a \ bEnd IfCase "mod"Text4.Text = a Mod bCase "^"Text4.Text = a ^ bEnd SelectEnd SubPrivate Sub Command2_Click() Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Form_Load()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "输入出错!重新输入"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "输入错误!重新输入"Text2.Text = ""Text2.SetFocusEnd IfEnd Sub6.Private Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) ThenMsgBox "不是数字,重新输入!"Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Text2_LostFocus()If Not IsNumeric(Text2.Text) ThenMsgBox "不是数字,重新输入!"Text2.Text = ""Text2.SetFocusEnd IfEnd SubPrivate Sub Text3_LostFocus()If Not IsNumeric(Text3.Text) ThenMsgBox "不是数字,重新输入!"Text3.Text = ""Text3.SetFocusEnd IfEnd SubPrivate Sub Form_Load()Text1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenDim a(0 To 2) As Integera(0) = InputBox("输入第一个数字", 输入, 0)a(1) = InputBox("输入第二个数字", 输入, 0)a(2) = InputBox("输入第三个数字", 输入, 0)For j = 1 To 2For i = 0 To 2 - jIf a(i) < a(i + 1) Then t = a(i): a(i) = a(i + 1): a(i + 1) = t Next iNext jPicture1.Print a(0); ">"; a(1); ">"; a(2)End IfEnd Sub7.Private Sub Command1_Click()Dim a As Integera = Val(Text1.Text)If (a Mod 400) = 0 ThenLabel3.Caption = "是闰年"ElseLabel3.Caption = "不是闰年"End IfSelect Case Text2.TextCase 1, 3, 5, 7, 8, 10, 12Label5.Caption = 31Case 2If (a Mod 400) = 0 ThenLabel5.Caption = 28ElseLabel5.Caption = 29End IfCase 4, 6, 9, 11Label5.Caption = 30End SelectSelect Case Text2.TextCase 12, 1, 2Label4.Caption = "冬季"Case 3, 4, 5Label4.Caption = "春季"Case 6, 7, 8Label4.Caption = "夏季"Case 9, 10, 11Label4.Caption = "秋季"End SelectEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Picture1.ClsPicture2.ClsPicture3.ClsText1.SetFocusEnd Sub8.Private Sub Form_Click()a = Val(InputBox("M1"))b = Val(InputBox("M2"))c = Val(InputBox("M3"))d = (a + b + c) / 3If d > 95 ThenPrint "一等奖"End IfIf a = 100 And b = 100 And c >= 80 Or a = 100 And c = 100 And b >= 80 Or c = 100 And b = 100 And a >= 80 ThenPrint "一等奖"End IfIf d > 90 ThenPrint "二等奖"End IfIf a = 100 And b >= 75 And c >= 75 Or b = 100 And c >= 75 And b >= 75 Or c = 100 And b >= 75 And a >= 75 ThenPrint "二等奖"End IfIf a >= 70 And b >= 70 And c >= 70 ThenPrint "三等奖"End IfEnd Sub实验五2.Private Sub Picture1_Click()For n = 2 To 1000If n = n ^ 2 Mod 10 Then Picture1.Print nIf n = n ^ 2 Mod 100 Then Picture1.Print nIf n = n ^ 2 Mod 1000 Then Picture1.Print nNext nEnd Sub3.Private Sub Command1_Click()Dim n%, s$, t As Strings = 0n = 0For x = 10 To 10000If x Mod 3 = 2 Or x Mod 5 = 3 Or x Mod 7 = 2 Then t = t & x & vbCrLfn = n + 1s = s + xEnd IfNext xText1.Text = tPicture1.Print "数的和" & sPicture1.Print "数的个数" & nEnd SubPrivate Sub Command2_Click()Dim n%, s$, t As Strings = 0n = 0x = 10Do While x < 10000If x Mod 3 = 2 Or x Mod 5 = 3 Or x Mod 7 = 2 Then t = t & x & vbCrLfn = n + 1s = s + xEnd Ifx = x + 1LoopText1.Text = tPicture1.Print "数的和" & sPicture1.Print "数的个数" & nEnd Sub5.Private Sub Picture1_Click()Dim n%, s%n = Val(InputBox("n值"))s = 0For i = 1 To ns = s + i ^ 2NextPicture1.Print sEnd SubPrivate Sub Picture2_Click()Dim n As Integern = V al(InputBox("输入n值"))sum = 0Dim a1 As DoubleDim a2 As DoubleDim a As DoubleDim sum As Doublea1 = 1a2 = 1For i = 1 To nt = a1 + a2a1 = a2a2 = ta = a2 / a1sum = sum + aNext iPicture2.Print sumEnd SubPrivate Sub Picture3_Click() Dim n%, s%n = Val(InputBox("n值"))s = 0a1 = 1a2 = 1For i = 1 To nt = a1 * a2Next iPicture3.Print sEnd SubPrivate Sub Picture4_Click() Dim i, n As Integer, s As Double n = Val(InputBox("n值"))If n >= 1 ThenFor i = 1 To nt = 5 * 10 ^ na = t + 5 * 10 ^ ns = s + tNext iPicture4.Print sEnd IfEnd SubPrivate Sub Picture5_Click() Dim i, n As IntegerDim s As Singlen = Val(InputBox("n值"))For i = 1 To ns = s + (-1) ^ (i + 1) * (1 / i) Next it = Format(s, "##0.#######") Picture5.Print tEnd Sub8.Private Sub Command2_Click() Picture1.ClsEnd SubPrivate Sub Command1_Click() For n = 6 To 1000k = 0For x = 1 To n / 2If n Mod x = 0 Thenk = k + xEnd IfNext xIf k = n ThenPicture1.Print kEnd IfNext nEnd Sub10.Private Sub Form_Click()For i = 1 To 9For a = 1 To iPrint Tab(20 - i);NextFor n = 1 To iPrint Trim(n);NextFor s = n - 2 To 1 Step -1Print Trim(s);NextPrintNextEnd Sub实验六2.Private Sub Form_Click()Dim a(100)RandomizeMax = 20Min = 100s = 0n = 0For i = 1 To 100a(i) = Int(Rnd * 81 + 20)Picture1.Print a(i);If i / 10 = i \ 10 Then Picture1.PrintIf a(i) > Max Then Max = a(i)If a(i) < Min Then Min = a(i)s = s + a(i)Next iv = Format(s / 100, "##0.###")For i = 1 To 100If a(i) > (s / 100) Then n = n + 1NextLabel1.Caption = "max=" & Max & vbCrLf & "min=" & Min & vbCrLf & "平均值为" & v & vbCrLf & "大于平均值的元素个数为" & nEnd Sub3.Private Sub Command1_Click()Dim a(), b() As Variant, c() As Singlea = Array(2, 8, 7, 6, 4, 28, 70, 25)b = Array(79, 27, 32, 41, 57, 66, 78, 80)Print "第一个数组为:" & vbCrLfFor i = LBound(a) To UBound(a)Print a(i);Next iPrintPrint "第二个数组为:" & vbCrLfFor i = LBound(a) To UBound(a)Print b(i);Next iReDim c(UBound(a))PrintPrint "两个数组相对元素相加的结果为:" & vbCrLfFor i = LBound(a) To UBound(a)c(i) = a(i) + b(i)Print c(i);Next iPrintFor i = LBound(a) To UBound(a) - 1For j = LBound(a) To UBound(a) - 1 - iIf c(j) < c(j + 1) Thent = c(j)c(j) = c(j + 1)c(j + 1) = tEnd IfNextNextPrintPrint "相加的结果的降序为:" & vbCrLfFor i = LBound(a) To UBound(a)Print c(i);NextEnd Sub4.Private Sub Form_Click()Dim a(20)RandomizePrint " 对换前" & crlfFor i = 1 To 20a(i) = Int(Rnd * 89 + 11)Print a(i);If i / 10 = i \ 10 Then PrintNext iPrintPrint " 对换后" & crlfFor i = 1 To 10t = a(i): a(i) = a(i + 10): a(i + 10) = tNext iFor i = 1 To 20Print a(i);If i / 10 = i \ 10 Then PrintNext iEnd Sub6.Private Sub Picture1_Click()n = V al(Text1.Text)ReDim a(n + 1, n + 1), b(n + 1, n + 1)Clsk = 8For i = 1 To nPicture1.Print String((n - i) * k / 2 + 1, " ");For j = 1 To ia(i, 1) = 1a(i, i) = 1a(i + 1, j + 1) = a(i, j) + a(i, j + 1)b(i, j) = Trim(Str(a(i, j)))Picture1.Print b(i, j); String(k - Len(b(i, j)), " ");Next jPicture1.PrintNext iEnd Sub9.'Option Base 1Dim s() As String, n%Private Sub Command1_Click()For i = 1 To UBound(s) - iFor j = 1 To UBound(s) - iIf s(j) < s(j + 1) Then t = s(j): s(j) = s(j + 1): s(j + 1) = t Next jNext iFor i = LBound(s) To UBound(s)Picture2.Print s(i)Next iEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Thenn = n + 1ReDim Preserve s(1 To n)s(n) = Text1.TextPicture1.Print s(n)Text1.Text = ""Text1.SetFocusEnd IfEnd Sub实验七5.Private Sub tt(x, r)Dim s As StringDom = x Mod rx = x \ rIf m = 10 Then m = "A"If m = 11 Then m = "B"If m = 12 Then m = "C"If m = 13 Then m = "D"If m = 14 Then m = "E"If m = 15 Then m = "F"s = m & sLoop Until x = 0tt(x, r) = sEnd SubPrivate Sub Command1_Click() x = Val(Text1.Text)r = Val(Text2.Text)Call tt(x, r)End SubPrivate Sub Command2_Click() x = Val(Text1.Text)r = Val(Text2.Text)Text3.Text = zh(x, r)End SubPrivate Sub Command3_Click() Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd SubFunction zh(x, r)Dim s As StringDom = x Mod rx = x \ rIf m = 10 Then m = "A"If m = 11 Then m = "B"If m = 12 Then m = "C"If m = 13 Then m = "D"If m = 14 Then m = "E"If m = 15 Then m = "F"s = m & sLoop Until x = 0zh = sEnd Function。