VB 编程求助!!!!!!编制一段程序,输入一个半径R,在屏幕上用"*"号拼成一个半径为R的圆

来源:百度知道 编辑:UC知道 时间:2024/05/23 00:12:23
VB 编程求助!!!!!!编制一段程序,输入一个半径R,在屏幕上用"*"号拼成一个半径为R的圆!!希望大虾帮忙!!
我自己编了一个,但是有的小问题,请大家帮忙知道!谢谢!
Private Sub Command1_Click()
Const PI = 3.1415926
Dim i As Integer
Dim R As Integer
R = 20
For i = 1 To R / 2

If i = 1 Then

Print Space(R); "*"

Else

Print Space(R - R * Cos(PI / 2 - i * (PI / 2) / R));
Print "*";
Print Space(2 * R * Cos(PI / 2 - i * (PI / 2) / R));
Print "*"

End If
Next i
For i = R / 2 To 1 Step -1

If i = 1 Then

Print Space(R); "*"

Else

Print Space(R - R * Cos(PI / 2 - i * (PI / 2) / R));
Print "*";
Print Space(2 * R * Cos(PI / 2 - i * (PI / 2) / R));

这里涉及三角函数计算来决定打印位置,VB代码中定义了xp打印函数,代码如下:
Option Explicit
Dim x As Integer
Dim y As Integer
Dim i As Integer
Dim fnt As Byte
Dim dd As Variant
Dim txt As String
Public Function xp(fnt As Variant, x As Variant, y As Variant, txt As Variant)
Me.CurrentX = x
Me.CurrentY = y
Me.FontSize = fnt
Me.Print txt
End Function

Private Sub Command1_Click()
Dim pi As Single
pi = 3.141592654
For i = 0 To 359 Step 3
x = 2500 + Sin((pi / 180) * i) * 2000
y = 2500 + Cos((pi / 180) * i) * 2000
fnt = 10
txt = "*"
dd = xp(fnt, x, y, txt)
Next
End Sub

Private Sub Form_Click()
Dim r As Integer
r = Val(Text1.Text)
For a = 0 To 2 * 3.1415926 Step 0.1
CurrentX = r * Cos(a): CurrentY = r * Sin(a)
Print "*"
Next a
End Sub

Private Sub Form_Load()
Scale (-10, 10)-(10, -10)
End Sub
使窗体的width和height一样就可以画出圆了.