孙俏版VB4-5章答案_第1页
孙俏版VB4-5章答案_第2页
孙俏版VB4-5章答案_第3页
孙俏版VB4-5章答案_第4页
孙俏版VB4-5章答案_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、4.1代码Private Sub Text1_Change()If Len(Text1.Text) > 15 ThenText2.SetFocusEnd IfEnd Sub实验结果4.2题目在窗体上有3个名称分别为Text1、Text2和Text3的文本框,一个名称为C1,标题为"计算"的命令按钮,如图4-4所示。要求程序运行后,在Text1和Text2中分别输入两个整数,单击"计算"按钮后,可把两个整数之间的所有整数(含两个整数)累加起来并在Text3中显示。代码Dim a%, b%, c%Private Sub Command1_Click()

2、a = Text1.Textb = Text2.Textc = (b - a + 1) * (b + a) / 2Text3.Text = Val(c)End Sub实验结果4.3题目代码Dim a%, s%Private Sub Command1_Click() s = 0 For a = 100 To 200 If a Mod 3 = 0 Then s = s + a End If Next a Text1.Text = sEnd Sub实验结果44题目代码Dim sum As Integer, N As IntegerPrivate Sub Command1_Click()If N &l

3、t;= 0 ThenMsgBox "重新输入"ElseFor i = 1 To Na = Val(InputBox("输入学生的visual basic 成绩")sum = sum + aNext iEnd IfLabel1.Caption = sum/NEnd SubPrivate Sub Text1_Change()N = Val(Text1.Text)End Sub实验结果4.5题目代码Dim n As Integer, s As VariantP弄不清这些东西rivate Sub Form_click()For i = 1 To nb = 1 F

4、or j = 1 To i b = b * j Next j s = s + (2 * i - 1) / b Next i Print s End SubPrivate Sub Text1_Change()n = Val(Text1.Text)End Sub实验结果代码Dim s As Variant, t As VariantPrivate Sub Form_click()For i = 1 To 100b = 1 For j = 1 To i b = b * j Next j If (2 * i - 1) / b < t Then Exit For Else s = s + (2 *

5、 i - 1) / b End If Next i Print sEnd SubPrivate Sub Text1_Change()t = Val(Text1.Text)End Sub5.1题目代码Private Sub Command1_Click() Dim a(1 To 5) As Integer, b(1 To 4) As Integer, c(1 To 9) As Integer Dim i As Integer, j As Integer, k As Integer, t As Integer k = 1 For i = 1 To 5 a(i) = 2 * i - 1 c(k) =

6、 a(i) k = k + 1 Next i For i = 1 To 4 b(i) = 2 * i c(k) = b(i) k = k + 1 Next i Print "合并后C的值是:" For i = 1 To 8 For j = i + 1 To 9 If c(j) < c(i) Then t = c(j) c(j) = c(i) c(i) = t End If Next j Next i For i = 1 To 9 Print c(i) Next iEnd Sub实验结果5.2题目代码Option ExplicitPrivate Sub Command1

7、_Click() Dim arr(1 To 10), t, i As Integer For i = 1 To 10 arr(i) = InputBox("输入一个整数:") Print arr(i), Next For i = 1 To 10 / 2 t = arr(i) arr(i) = 10 - i + 1 arr(10 - i + 1) = t Next Print For i = 1 To 10 Print arr(i), NextEnd Sub实验结果5.3题目代码Private Sub Form_Click() Dim a(10, 10) For i = 1

8、To 10 For j = 1 To 10 If i = j Or (i + j) Mod 11 = 0 Then a(i, j) = 1 Else a(i, j) = 0 End If Print a(i, j); Next Print '换行 NextEnd Sub题目是9×9矩阵实验结果5.4题目代码Dim a, b, c ,i,nAs IntegerPrivate Sub Command1_Click(Index As Integer)Text1.Text = Text1.Text & Indexb = Text1.Textn=b+0End SubPrivat

9、e Sub Command2_Click(Index As Integer)Select Case IndexCase 0i = 0Case 1i = 1Case 2i = 2Case 3i = 3End SelectText1.Text = ""a = nEnd SubPrivate Sub Command3_Click()Text1.Text = ""End SubPrivate Sub Command4_Click()Select Case iCase 0c = a + nCase 1c = a - nCase 2c = a * nCase 3c = a / nEnd SelectText1.Text = cEnd SubPrivate Sub Command

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论