VB第三版课后实验I答案

VB第三版课后实验I答案
VB第三版课后实验I答案

1.首先在窗体上绘制一条line1,并将其index属性值附为1

Private Sub Command1_Click()

For i = 2 To 20

Load Line1(i)

Line1(i).X1 = Me.ScaleWidth * Rnd

Line1(i).Y1 = Me.ScaleHeight * Rnd

Line1(i).X2 = Me.ScaleWidth * Rnd

Line1(i).Y2 = Me.ScaleHeight * Rnd

Line1(i).BorderColor = RGB(Rnd * 256, Rnd * 256, Rnd * 256)

Line1(i).BorderWidth = Rnd * 10

Line1(i).Visible = True

Next i

End Sub

Private Sub Command2_Click()

For i = 2 To 20

Unload Line1(i)

Next i

Line1(1).Visible = False

End Sub

2.

Private Sub Command1_Click()

Dim x As Double, y As Double, a As Integer, b As Integer, c As Integer Form1.Scale (0, 0)-(400, -400)

For i = 1 To 200

Randomize

x = Rnd * Form1.ScaleWidth

y = Rnd * Form1.ScaleHeight

a = Int(Rnd * 256)

b = Int(Rnd * 256)

c = Int(Rn

d * 256)

DrawWidth = Int(Rnd * 4 + 3)

Form1.PSet (x, y), RGB(a, b, c)

Next i

End Sub

Private Sub Command2_Click()

Cls

End Sub

3.

Private Sub Command1_Click()

Form1.Caption = "玫瑰曲线"

Picture1.Cls

Picture1.Scale (-4, 4)-(4, -4)

r = 0.5 * Picture1.ScaleWidth

DrawWidth = 1

For i = 0 To 6.283 Step 0.001

x = r * Cos(4 * i) * Cos(i)

y = r * Cos(4 * i) * Sin(i)

Picture1.PSet (x, y)

Next i

End Sub

4.

Private Sub Command1_Click()

Form1.Cls

Form1.Scale (-4, 4)-(4, -8)

For i = 0 To 6.283 Step 0.1

x = i * Cos(i)

y = i * Sin(i)

Randomize

a = Int(Rnd * 256)

b = Int(Rnd * 256)

c = Int(Rn

d * 256)

Line (0, 0)-(x, y), RGB(a, b, c)

Next i

End Sub

5.

Private Sub Command1_Click()

x = Me.ScaleWidth / 2

y = Me.ScaleHeight / 2

r = Abs(Me.ScaleWidth / 4)

n = Val(InputBox("请问将圆几等分?"))

Form1.Circle (x, y), r

t = 3.1415926 * 2 / n

For i = 1 To n

X2 = r * Cos(i * t) + x

Y2 = r * Sin(i * t) + y

For j = i + 1 To n

If j <> i + n / 2 Then

x3 = r * Cos(j * t) + x

y3 = r * Sin(j * t) + y

Form1.Line (X2, Y2)-(x3, y3)

End If

Next j

Next i

End Su

6.

Private Sub Form_Click()

Form1.Scale (-4, 4)-(4, -4)

i = Abs(Me.ScaleWidth / 4)

DrawWidth = 2

For x = -i To i Step 0.2

r = 0.1 + r

Form1.Circle (x, 0), r

Next x

End Sub

7.

Option Base 1

Dim a(4) As Integer, b(4) As String

Sub xyz()

Form1.Cls

DrawWidth = 1

Form1.Scale (-2, 350)-(200, -30)

Form1.Line (0, 0)-(200, 0)

Form1.Line (0, 350)-(0, 0)

a(1) = 308: b(1) = "中国"

a(2) = 260: b(2) = "韩国"

a(3) = 189: b(3) = "日本"

a(4) = 76: b(4) = "哈萨克"

CurrentX = 0: CurrentY = -4

Print "数据:";

For i = 1 To 4

Print b(i); a(i); ",";

Next i

End Sub

Private Sub bing_Click()

Call xyz

For i = 1 To 4

s = a(i) + s

Next i

a1 = 0

a2 = 0

DrawWidth = 1

Form1.FillStyle = 0

For i = 1 To 4

a2 = a1 + 2 * 3.1415926 * a(i) / s

Form1.FillColor = QBColor(Rnd * 15)

Form1.Circle (100, 150), 50, , -a1, -a2

CurrentX = 100 + 60 * Cos((a1 + a2) / 2)

CurrentY = 150 + 60 * Sin((a1 + a2) / 2)

Print b(i); Format(a(i) / s * 100, "0.00"); "%"

a1 = a2

Next i

End Sub

Private Sub san_Click()

Call xyz

DrawWidth = 6

For i = 1 To 4

x = x + 40

Form1.PSet (x, a(i))

CurrentX = x + 2

CurrentY = a(i)

Print b(i)

Next i

End Sub

Private Sub zhe_Click()

Call xyz

DrawWidth = 8

For i = 1 To 4

x = x + 40

Form1.PSet (x, a(i))

CurrentX = x + 2

CurrentY = a(i)

Print b(i)

Next i

DrawWidth = 2

x = 0

For i = 1 To 3

x = x + 40

Form1.Line (x, a(i))-(x + 40, a(i + 1))

Next i

End Sub

Private Sub zhi_Click()

Call xyz

For i = 1 To 4

x = x + 40

Form1.Line (x, 0)-(x + 10, a(i)), QBColor(9), BF

CurrentX = x: CurrentY = a(i) + 15

Print b(i)

Next i

End Sub

8.

Option Base 1

Dim a(5) As Integer

Private Sub bing_Click()

Call xy

For i = 1 To 5

s = a(i) + s

Next i

a1 = 0

a2 = 0

DrawWidth = 1

Form1.FillStyle = 0

x = Abs(Me.ScaleHeight / 2)

y = Abs(Me.ScaleWidth / 2)

r = Abs(Me.ScaleHeight / 4)

For i = 1 To 5

a2 = a1 + 2 * 3.1415926 * a(i) / s

Form1.FillColor = QBColor(Rnd * 15)

Form1.Circle (x, y), r, , -a1, -a2

CurrentX = x + r * Cos((a1 + a2) / 2)

CurrentY = y + r * Sin((a1 + a2) / 2)

Print Format(a(i) / s * 100, "0.00"); "%"

a1 = a2

Next i

End Sub

Private Sub data_Click()

Call xy

Randomize

For i = 1 To 5

a(i) = Int(Rnd * 91 + 10)

Next i

CurrentX = 8: CurrentY = 110

Print "绘图数据"

CurrentX = 8: CurrentY = 103

For i = 1 To 5

Print a(i); " ";

Next i

End Sub

Sub xy()

DrawWidth = 1

Form1.Scale (-5, 110)-(100, -5)

Form1.Line (0, 0)-(100, 0)

Form1.Line (0, 110)-(0, 0)

CurrentX = 95: CurrentY = -0.5: Print "X"

CurrentX = 2: CurrentY = 105: Print "Y" End Sub

Private Sub san_Click()

Call xy

DrawWidth = 6

w = Me.ScaleWidth / 6

For i = 1 To 5

x = x + w

Form1.PSet (x, a(i))

CurrentX = x + 2

CurrentY = a(i) + 2

Print a(i)

Next i

End Sub

Private Sub zhe_Click()

Call xy

DrawWidth = 8

w = Me.ScaleWidth / 6

For i = 1 To 5

x = x + w

Form1.PSet (x, a(i))

Next i

DrawWidth = 2

x = 0

For i = 1 To 4

x = x + w

Form1.Line (x, a(i))-(x + w, a(i + 1))

CurrentX = x + 2

CurrentY = a(i) + 2

Print a(i)

Next i

CurrentX = x + w + 2

CurrentY = a(5) + 2

Print a(5)

End Sub

Private Sub zhi_Click()

Call xy

w = Me.ScaleWidth / 6

For i = 1 To 5

x = x + w

Form1.Line (x, 0)-(x + 5, a(i)), QBColor(9), BF

CurrentX = x

CurrentY = a(i) + 5

Print a(i)

Next i

End Sub

相关主题
相关文档
最新文档