VB实验2-4答案.doc

上传人:坚持 文档编号:2086745 上传时间:2019-04-20 格式:DOC 页数:10 大小:17.26KB
下载 相关 举报
VB实验2-4答案.doc_第1页
第1页 / 共10页
VB实验2-4答案.doc_第2页
第2页 / 共10页
VB实验2-4答案.doc_第3页
第3页 / 共10页
VB实验2-4答案.doc_第4页
第4页 / 共10页
VB实验2-4答案.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、VB 实验二实验 2-1Private Sub Command1_Click()Dim r As Single, v As Singler = Val(Text1.Text)v = (4 / 3) * 3.14159 * r 3Label2 = Format(v, “0.000“)End Sub实验 2-2Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)p = (1 / 3) * (a + b + c)Text4.Text = Format(p, “0.00“)End Su

2、b实验 2-3Dim s As Integers = Val(Text1)Text2.Text = Mid(s, 1, 1)Text3.Text = Mid(s, 2, 1)Text4.Text = Mid(s, 3)实验 2-4Dim a As Integer, b As Single, c As Integer, d As Integer, e As Singlea = Val(Text1)b = Val(Text2)c = Val(Text3)d = Val(Text4)e = (63360 * a + 36 * b + 12 * c + d) / 39.37Text5.Text = F

3、ormat(e, “0.000“)实验 2-5Text1.Enabled = TrueText1.Enabled = False实验 2-6Private Sub Form_Load()Command1.Caption = “编辑(&E)“Command2.Caption = “保存(&S)“End SubPrivate Sub Command1_Click()Text1.Locked = FalseEnd SubPrivate Sub Text1_Change()Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Text1.L

4、ocked = TrueCommand2.Enabled = FalseEnd Sub实验 2-7(居中在杂项)Private Sub Command1_Click()Text1.Text = “欢迎光临“End SubPrivate Sub Command2_Click()Text1.Text = “谢谢再见“End SubPrivate Sub Form_Load()Text1.TabIndex = 0Command1.Default = TrueCommand2.Cancel = TrueEnd Sub实验 2-8Private Sub Command1_Click()Text1.Sel

5、Start = 8Text1.SelLength = 9Text1.SetFocusEnd SubPrivate Sub Command2_Click()Label1.Caption = Text1.SelTextEnd SubPrivate Sub Text1_Change()If Len(Text1.text) 100 Thenp = (n - 100) * 0.03 + 5ElseIf 0 0) And (y 0) ThenText3.Text = “第一象限“ElseIf (x 0) ThenText3.Text = “第二象限“ElseIf (x 0) And (y = 95) Or

6、 (b = 95) Or (c = 95) Thenr = “Honor Medal“Elser = “No Medal“End IfText4.Text = rEnd Sub实验 5Private Sub Option1_Click()Text1.Text = “我是博士生“End SubPrivate Sub Option2_Click()Text1.Text = “我是硕士生“End SubPrivate Sub Option3_Click()Text1.Text = “我是本科生“End Sub实验 6Private Sub Command1_Click()If Option1.Val

7、ue ThenText1.Text = “支持湖人队“ElseIf Option2.Value ThenText1.Text = “支持公牛队“End IfEnd SubPrivate Sub Command2_Click()Option1.Value = FalseOption2.Value = FalseText1.Text = “没有选择任何团队“End Sub实验 7Private Sub Check1_Click()If Check1.Value ThenLabel1.FontUnderline = TrueElseIf Check2.Value ThenLabel1.FontStr

8、ikethru = TrueEnd IfEnd Sub实验 8Dim a As IntegerPrivate Sub Command1_Click()If Check1.Value = False And Check2.Value = False And Check3.Value = False And Check4.Value = False ThenText1.Text = 4500ElseIf Check1.Value = 1 Thena = 4500 + 1000Elsea = 4500End IfIf Check2.Value = 1 Thena = a + 800Elsea = a

9、End IfIf Check3.Value = 1 Thena = a + 600Elsea = aEnd IfIf Check4.Value = 1 Thena = a + 500Elsea = aEnd IfText1.Text = Str(a)End IfEnd SubVB 实验四实验 1Private Sub Command1_Click()Dim sum As Double, n As Integer, i As Integern = Val(Text1.Text)sum = 0For i = 1 To nIf (i Mod 3 = 0) And (i Mod 7 0m = nn =

10、 ii = m Mod nLoopText3.Text = Str(n)End Sub实验 3Private Sub Command1_Click()Dim i, j, m, n, sum As Integer, flag As Booleanm = Val(Text1.Text)n = Val(Text2.Text)sum = 0For i = m To nflag = TrueFor j = 2 To i - 1If i Mod j = 0 Thenflag = FalseExit ForEnd IfNext jIf flag = True Thensum = sum + iEnd IfN

11、ext iText3.Text = Str(sum)End Sub实验 4Private Sub Command1_Click()Dim i, sum As Integer, n As Stringn = Len(Text1.Text)sum = 0For i = 1 To nIf Mid(Text1.Text, i, 1) = “1“ Thensum = sum + 2 (n - i)End IfNext iLabel1.Caption = Str(sum)End SubPrivate Sub Command2_Click()Dim n, i As Integern = Val(Text1.

12、Text)Label1.Caption = “Do While n max Thenmax = a(i)End IfNext iText2.Text = Str(max)Text3.Text = Chr(max)End Sub实验 3Option ExplicitDim i, j As Integer, a(1 To 100) As String, b(1 To 100) As StringPrivate Sub Command1_Click()For i = 1 To 100a(i) = Chr(Int(Rnd * 26) + 65)Text1.Text = Text1.Text & a(i) & Space(1)Next iEnd SubPrivate Sub Command2_Click()Dim sum As IntegerFor i = 1 To 100b(1) = 0For j = 1 To 100If a(i) = Text2.Text Thenb(j) = b(j - 1) + 1End IfNext jText3.Text = Str(a(j)Next iEnd Sub实验 4实验 5

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 试题真题

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。