教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 法律文档 >

vb程序设计教程课后答案与实验题答案(第三版)(5)

来源:网络收集 时间:2026-08-29
导读: pf = Format(x * x, \pfg = Format(Sqr(x), \lf = Format(x * x * x, \lfg = Format(x ^ (1 / 3), \ Print \平方为:\平方根为:\立方为:\立方根为:\lfg End Sub C.1 Private Sub Form_Click() Dim x!, y! x = Val(I

pf = Format(x * x, \pfg = Format(Sqr(x), \lf = Format(x * x * x, \lfg = Format(x ^ (1 / 3), \

Print \平方为:\平方根为:\立方为:\立方根为:\lfg

End Sub

C.1

Private Sub Form_Click() Dim x!, y!

x = Val(InputBox(\输入x的值\If x < 1000 Then y = x

ElseIf x < 2000 Then y = 0.9 * x

ElseIf x < 3000 Then y = 0.8 * x Else y = 0.7 * x End If Print y End Sub

C.2

Private Sub Form_Click() Dim x!, y!

x = Val(InputBox(\输入上网时间\If x < 10 Then y = 30

ElseIf x < 50 Then y = 30 + 2.5 * (x - 10) Else

y = 30 + 2.5 * 40 + 2 * (x - 50) End If

If y > 150 Then y = 150 End If Print y End Sub

C.3

Private Sub Command1_Click() Dim x!, y!, z!

x = InputBox(\ y = InputBox(\ z = InputBox(\

Print \ x y z\ Print \排序前\ \ \ If x < y Then t = x: x = y: y = t If x < z Then t = x: x = z: z = t If y < z Then t = y: y = z: z = t

Print \排序后\ \ \End Sub

Private Sub Command2_Click() Dim x!, y!, z!

x = InputBox(\ y = InputBox(\ z = InputBox(\

Print \ x y z\ Print \排序前\ \ \ 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 End If End If

Print \排序后\ \End Sub

C.4

Dim a(3) As Integer

Private Sub Command1_Click() Picture1.Cls For i = 0 To 2

a(i) = Int(Rnd * 100 + 200) Picture1.Print a(i) Next i End Sub

Private Sub Command2_Click() Picture2.Cls Dim z As Integer For i = 0 To 1

If a(i) > a(i + 1) Then z = a(i + 1) a(i + 1) = a(i) a(i) = z

\ End If Next i

Picture2.Print a(0) Picture2.Print a(1) Picture2.Print a(2) End Sub

C.5

Private Sub Text2_LostFocus() Dim m%, n%, y% m = Val(Text1) n = Val(Text2)

If n Mod 2 <> 0 Then

MsgBox (\脚数必定为偶数\ Text2 = \

Text2.SetFocus Else

y = n / 2 - m If y < 0 Then

MsgBox (\脚数必须≥2倍的头数,请重新输入\ Text2 = \

Text2.SetFocus Else

x = n / 2 - m Label2 = y Label3 = m - y End If End If End Sub

C.6

Private Sub Command1_Click() Dim a!, b!, c!, x1!, x2!, de! a = Text1 b = Text2 c = Text3

de = b * b - 4 * a * c t = 2 * a

If de = 0 Then

Text4 = Format(-b / t, \ Text5 = Format(-b / t, \ElseIf de > 0 Then

Text4 = Format((-b + Sqr(de)) / t, \ Text5 = Format((-b - Sqr(de)) / t, \

Else

Text4 = Format(-b / t, \ Text5 = Format(-b / t, \End If End Sub

Private Sub Command2_Click() Text1 = \Text2 = \Text3 = \Text4 = \Text5 = \End Sub

C.7

Private Sub Text3_LostFocus() Select Case Trim(Text3) Case \

Text4 = Val(Text1) + Val(Text2) Case \

Text4 = Val(Text1) - Val(Text2) Case \

Text4 = Val(Text1) * Val(Text2) Case \

If Val(Text2) = 0 Then

MsgBox \分母为零,重新输入\ Text2 = \

Text2.SetFocus Else

Text4 = Val(Text1) / Val(Text2) End If End Select End Sub

C.8

Private Sub Text1_LostFocus() Select Case Trim(Text1) Case 1

Text2 = \ Case 2

Text2 = \ Case 3

Text2 = \ Case 4

Text2 = \

Case 5

Text2 = \ Case 6

Text2 = \ Case 7

Text2 = \ Case Is > 7, Is < 1

MsgBox \数字为1~7,重新输入\ Text1 = \

Text1.SetFocus End Select End Sub 或者

Private Sub Text1_LostFocus() If Text1 > 7 Or Text1 < 1 Then

MsgBox \数字为1~7,重新输入\ Text1 = \

Text1.SetFocus Else

Text2 = Choose(Text1, \\End If End Sub

D.1

Private Sub Form_Click() For i = 1 To 9

Print Tab(10 - i); String(2 * i - 1, Trim(Str(i))) Next i End Sub

D.2

Private Sub Form_Click() For i = 1 To 10 Step 1

Print Tab(i); String((20 - 2 * i), Chr(64 + i)) Next i End Sub

D.3

Private Sub Command1_Click() Dim s!, t!, i& s = 1 t = 1

For i = 1 To 100000

…… 此处隐藏:862字,全部文档内容请下载后查看。喜欢就下载吧 ……
vb程序设计教程课后答案与实验题答案(第三版)(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/435676.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)