以前的三毛现在的照片:关于vb:大侠们,快来救我一把(如何在一个过程中调用另一个过程中的参数)
来源:百度文库 编辑:中科新闻网 时间:2024/05/14 20:04:33
如何在一个过程中调用另一个过程中的参数
比如:
Private Sub Command1_Click()
dim p as integer 'p局部变量
p=......
End Sub
-------------
Private Sub Timer3_Timer()
Dim x As Integer
x = Val(Text2.Text) / 10
If Shape4.Left < 7025 Then
Shape4.Left = Shape4.Left + x*p 'p是另一个过程中的参数
Shape4.Top = Shape4.Top - x*p
Else
Shape4.Left = Shape4.Left + x
End If
End Sub
想在Timer3_Timer() 中调用Command1_Click() 中的p
比如:
Private Sub Command1_Click()
dim p as integer 'p局部变量
p=......
End Sub
-------------
Private Sub Timer3_Timer()
Dim x As Integer
x = Val(Text2.Text) / 10
If Shape4.Left < 7025 Then
Shape4.Left = Shape4.Left + x*p 'p是另一个过程中的参数
Shape4.Top = Shape4.Top - x*p
Else
Shape4.Left = Shape4.Left + x
End If
End Sub
想在Timer3_Timer() 中调用Command1_Click() 中的p
Dim p As Integer 设置p全局变量
Dim pp As Boolean 设置pp,用于判断是否点击了command1
Private Sub Form_Load()
pp = False 设置pp为false
End Sub
Private Sub Command1_Click()
p=......
pp = True 点击command1后,设置pp为true
End Sub
Private Sub Timer3_Timer()
'……
If Shape4.Left < 7025 And pp = True Then 加入pp=true的判断,确定点击了command1
Shape4.Left = Shape4.Left + x * p
……
pp = False 设置pp为false
……
End Sub
这个P要是全局变量
建立个类模块
PUBLIC P AS integer
这样在各个地方都可以调用P,不需要在Command1_Click()中再定义P
把P 定义成全局变量
你把P设成全程变量不就行了?