vb程序设计实验指导习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
P178 五 1
Private Sub Form_DblClick()
'双击窗体时,通过InputBox输入n,求1/2+1/2^2....+1/2^n
Dim n As Integer
n = InputBox("输入n的值:")
For i = 1 To n
s = s + 1 / 2 ^ i
Next
Print "1/2+1/2^2+...+1/2^" & n & "=" & s End Sub
P185五
Dim a(9) As Integer
Private Sub Command1_Click()
'在文本框显示10个两位随机整数,逗号分隔
Text1.Text = ""
For i = 0 To 9
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & a(i) & "," Next i
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command2_Click()
'消息框显示最小值
m = a(0)
For i = 1 To 9
If a(i) < m Then m = a(i)
Next
MsgBox "10个数的最小值为:" & m
End Sub
Private Sub Command3_Click()
'消息框显示最大值
m = a(0)
For i = 1 To 9
If a(i) > m Then m = a(i)
Next
MsgBox "10个数的最大值为:" & m
End Sub Private Sub Command4_Click()
'消息框显示平均值
For i = 0 To 9
m = m + a(i)
Next
MsgBox "10个数的平均值为:" & m / 10 End Sub
P169 2
P169 3
Private Sub Command1_Click()
Label1.Top = Label1.Top - Label1.Height / 2 Label1.Height = Label1.Height * 2
Label1.Left = Label1.Left - Label1.Width / 2 Label1.Width = Label1.Width * 2
Label1.FontSize = Label1.FontSize * 2
End Sub
P169 4
Private Sub VS1_Change()
Text1.Text = VS1.V alue
End Sub
Private Sub VS1_Scroll()
Text1.Text = VS1.V alue
End Sub
P169 5
Private Sub Command1_Click()
For i = List1.ListCount - 1 To 0 Step -1 List2.AddItem List1.List(i)
Next i
List1.Clear
End Sub
P177 2
Private Sub Text1_Change()
Label1.Caption = UCase(Text1.Text)
End Sub
P177 3
Private Sub Cmd1_Click()
Timer1.Enabled = True
End Sub
Private Sub Cmd2_Click()
End
End Sub
Private Sub Timer1_Timer()
a = Pic1.Picture
Pic1.Picture = Pic2.Picture
Pic2.Picture = a
End Sub
P177 4
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
If a < b Then
Label1.Caption = a
Else
Label1.Caption = b
End If
End Sub
P177 5
Private Sub Form_Load()
Image1.Picture = LoadPicture(App.Path & "/p1.gif")
HS1.Min = 500
HS1.Max = 1000
End Sub
Private Sub HS1_Change()
Image1.Width = HS1.Value
End Sub P184 2
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
a = Label1.BackColor
Label1.BackColor = Label1.ForeColor
Label1.ForeColor = a
End Sub
P184 3
Private Sub Check1_Click()
Text1.FontBold = Check1.Value
End Sub
P184 4
Private Sub Command1_Click()
Dim n As Integer
n = InputBox("请输入一个整数:")
For i = 1 To n
s = s + i ^ 2
Next i
Text1.Text = "从1到" & n & "的平方和为" & s
End Sub