vb课后习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
习题3—4 (P126)
Private Sub Command1_Click()
Image1.Width = Image1.Width * 1.2
Image1.Height = Image1.Height * 1.2
End Sub
Private Sub Command2_Click()
Image1.Width = Image1.Width / 1.2
Image1.Height = Image1.Height / 1.2
End Sub
Private Sub Command3_Click()
Image1.Width = Form1.Width
Image1.Height = Form1.Height
End Sub
Private Sub Form_Load()
Image1.Left = 0
Image1.Top = 0
Image1.Picture = LoadPicture(App.Path & "\back.jpg") End Sub
习题3—5 (P126)
Dim mleft As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
mleft = Label1.Left + 100
If mleft + Label1.Width > Picture1.Width Then
mleft = 0
End If
Label1.Left = mleft
End Sub
习题4—1 (P170)
Private Sub Form_Load()
Form1.Show
Sum = 0
For i = 1 To 4
a = InputBox("请输入数值型数据")
Sum = Sum + a
ave = Sum / 4
Next
Print Sum; ave
End Sub
习题4—3 (P170)
Private Sub Command1_Click()
a = 5
b = 2.5
c = 7.8
pi = 3.14159265
y = pi * a * b / a + b * c
Print y
End Sub
习题4—4
Private Sub Command1_Click()
a = Val(Text1.Text)
tian = a \ 86399
xiaoshi = (a - tian * 86400) \ 1439
fenzhong = (a - tian * 86400 - xiaoshi * 1440) \ 59
miao = a - tian * 86400 - xiaoshi * 1440 - fenzhong * 60
Text2.Text = tian & "天" & xiaoshi & "小时" & fenzhong & "分钟" & miao & "秒" End Sub
习题4—5
Private Sub Command1_Click()
Const g As Single = 9.81
t = InputBox("请输入t的值")
v0 = InputBox("请输入v0的值")
s = 1 / 2 * g * t * t + v0 * t
Print Format(s, "0.##")
End Sub
习题4—6
Private Sub Command1_Click()
Sum = 0
For i = 2 To 100 Step 2
Sum = Sum + i
Next
Label1.FontSize = 20
Label1.Caption = "2+4+6+……+100=" & Sum
End Sub
习题4—7
Private Sub Command1_Click()
Do
a = InputBox("请输入三角形的第一条边长")
a1 = Val(a)
If a1 = -1 Then
End
End If
b = InputBox("请输入三角形的第二条边长")
b1 = Val(b)
If b1 = -1 Then
End
End If
c = InputBox("请输入三角形的第三条边长")
c1 = Val(c)
If c1 = -1 Then
End
End If
If (a1 + b1 > c1) And (a1 + c1 > b1) And (b1 + c1 > a1) Then s = a1 + b1 + c1
Exit Do
Else
Error1 = MsgBox("您输入的数据不能组成三角形")
End If
Loop
Label4.Caption = "您输入的边长分别为:" & a1 & "," & b1 & "," & c1 & " " & "面积为:" & s
End Sub
习题4—8
Private Sub Command1_Click()
If Text1.Text <> "" Then
a = Text1.Text
Select Case a
Case Is <= 200
s = 0
Case Is <= 400
s = (a - 200) * 0.03
Case Is < 5000
s = 200 * 0.03 + (a - 400) * 0.04
Case Is >= 5000
s = (400 - 200) * 0.03 + (5000 - 400) * 0.04 + (a - 5000) * 0.05 End Select
Text2.Text = s
Else
error1 = MsgBox("请输入您的收入!")
End If
End Sub
Private Sub Form_Load()
Text2.Locked = True
End Sub
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
error1 = MsgBox("请输入数字")
End If
End Sub