vb课后习题答案
- 格式:docx
- 大小:18.25 KB
- 文档页数:18
A2 Public Class SyA_2
Private Sub SyA_2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Click
MsgBox("欢迎您使用!")
End Sub
End Class
A3 Public Class SyA_3
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
Label3.Text = TextBox1.Text
End Sub
End Class
A4 Public Class SyA_4
Dim x As Integer, y As Integer, k As Integer
Dim flag As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
x = 250 : y = 250
Label7.Location = New Point(x - 100, y + 110)
PictureBox1.Location = New Point(x, y)
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Label6.Text = Label7.Left
If flag = True Then
y -= 1
Label7.Location = New Point(x - 100, y + 110)
PictureBox1.Location = New Point(x, y)
Label3.Text = "上"
Label7.BackColor = Color.Blue
Label7.ForeColor = Color.FloralWhite
If (Integer.Parse(Label5.Left) <= 0) Then
flag = False
End If
Else
y += 1 Label7.Location = New Point(x - 100, y + 110)
PictureBox1.Location = New Point(x, y)
Label3.Text = "下"
Label7.BackColor = Color.FloralWhite
Label7.ForeColor = Color.Blue
If (Integer.Parse(Label7.Top) + Integer.Parse(Label7.Height) >=
Integer.Parse(Me.Width)) Then
flag = True
End If
End If
End Sub
End Class
A5 Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Click
TextBox1.Text = Val(TextBox1.Text) + 1
End Sub
A6 Public Class SyA_6
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
TextBox3.Text = TextBox1.Text ^ TextBox2.Text
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button2.Click
If TextBox3.Text = TextBox1.Text ^ TextBox2.Text Then TextBox3.Text = "正确" Else TextBox3.Text = "错误"
End Sub
End Class
B1 Module Module1
Sub Main()
Dim a AsBoolean
Dim b AsBoolean
a = True
b = False
Console.WriteLine("{0} {1} {2} {3}", "a", True, "b", False)
Console.WriteLine("{0} {1} {2} {3} {4}", a, "AND", b, "为a", a And b)
Console.WriteLine("{0} {1} {2} {3} {4} {5}", a, "AND", "Not", b, "为a",
a AndNot b)
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} ", a, ">", b, "OR", b, "为a", a > b Or b)
Console.ReadLine()
EndSub
End Module
B2 Module Module2
Sub main()
Dim x As Integer
Dim y As Integer
Console.Write("Input x =")
x = Console.ReadLine
Console.Write("Input y =")
y = Console.ReadLine
Console.WriteLine("{0} {1}", "表达式1的结果为", Math.Sin(x) +
Math.Cos(y))
Console.WriteLine("{0} {1}", "表达式2的结果为", ((x ^ 2 + y ^ 2) /
Math.Abs(y)) ^ (1 / 3))
Console.WriteLine("{0} {1}", "表达式3的结果为", x + y > x ^ 2 - 10 * x)
Console.ReadLine()
End Sub
End Module
B3 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = Int(Rnd() * 100 + -49)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Int(Rnd() * 9998 + 1) * 0.01
End Sub
B4 Randomize()
Label1.Text = Int(Rnd() * 9000 + 1000)
Dim a, b, c, d As Integer
a = Label1.Text \ 1000
b = (Label1.Text Mod 1000) \ 100
c = (Label1.Text Mod (a * 1000 + b * 100)) \ 10
d = (Label1.Text Mod 10)
Label2.Text = c * 1000 + a * 100 + d * 10 + b
B5 Dim a As Double
a = TextBox1.Text
Label1.Text = Format(a, "##,###.0000")
Label2.Text = a
B10 TextBox1.Text = UCase(TextBox1.Text)
TextBox1.SelectionStart = Len(TextBox1.Text)
B6 Dim a = TextBox1.Text
Label1.Text = Microsoft.VisualBasic.Left(a, 16)
Label2.Text = Mid(a, 17, 6)
Label3.Text = Microsoft.VisualBasic.Right(a, 5)
B7
Dim a, b As String
a = TextBox1.Text
b = TextBox2.Text
Label1.Text = Replace(a, b, "")
B8 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim F = Val(TextBox1.Text), C = Val(TextBox2.Text)
C = (5 / 9) * (F - 32)
TextBox1.Text = Math.Round(C, 2)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim F = Val(TextBox1.Text), C = Val(TextBox2.Text)
F = (9 / 5) * C + 32
TextBox2.Text = Math.Round(F, 2)
End Sub
B9 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim p = 3.14, a = Val(TextBox1.Text)
TextBox2.Text = Format(p * a * a, "##.00")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim p = 3.14, a = Val(TextBox1.Text)
TextBox3.Text = Format(2 * p * a, "##.00")
End Sub