'粘贴下面代码即可, 不用添加任何控件
Private WithEvents Timer1 As Timer
Dim r&, r1&, t&, a1!, a2!, xb!, yb!, s!, b#
Private Sub Form_Load()
Me.Width = 4500: Me.Height = 4500
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.AutoRedraw = True
Me.Caption = "CBM666的万花筒"
Set Timer1 = Controls.Add("vb.timer", "Timer1")
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Randomize
r = 340 * Rnd
If r <> 0 Then
r1 = 500
s = r * Rnd
b = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
For t = 1 To 10000
a1 = t * 3.1415926 / 180
a2 = (r1 / r) * a1
xb 局桐= 500 + (-(r1 - r) * Cos(a1) - s * Cos(a2 - a1) + 420) * 4
卖腊谨yb = 500 + ((r1 - r) * Sin(a1) - s * Sin(a2 - a1) + 380) * 4
Me.PSet (xb, yb), 中基b
Next t
End If
End Sub
'添加一个TextBox 设置其慎搭MultiLine=True 示例代码如山老下:Private Sub Form_Click()
Dim a(1 To 100) As Integer
Randomize Timer
Print "随逗孝升机产生的100个数据是:"
For i = 1 To 100
a(i) = Int(Rnd * 90 + 10)
Print a(i)" "
If i Mod 10 = 0 Then Print
Next i
For i = 1 To 99
For j = i + 1 To 100
If a(i) >a(j) Then
c = a(i)
a(i) = a(j)
a(j) = c
End If
Next j
Next i
For i = 1 To 100
If a(i) >= 50 Then
Text1.Text = Text1.Text &a(i) &" "
b = b + 1
If b Mod 10 = 0 Then Text1.Text = Text1.Text &vbCrLf
End If
Next i
End Sub
第一行改为Public Sub sum(ByVal n As Integer, S As Integer)
已经调试通过
难道是因为你的陵宽text3.text为空或非数值,因此p=0,所以s3=0?
s1和s2是不是也为零?如果山告不是,就把
Dim s1, s2, s3 As Integer
改为
Dim s1, s2, s3
还有一个问题,所谓“溢出”也可能是你输入的数字或者计算过程超过了Integer的最大正数32767,如果是这样逗汪明,请把所有数值变量改为Long类型
sub是可以带参数的,也是可以传值的,但如果参数是ByVal的就不会传回实参。
当然,楼主的问题,最好还是用Function,这才是标准的用法
子程序也是可以用
call abc(a,b)
的形式调用的,而且a,b的值可以在子程序内部调用后(不是指直接对a,b的调用),再返回到子程序外部的,也就是说,a,b的值在调用子程序前后是可以变化的
ByRef是参数的默认调用方式,所以是可以省略的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)