极其有用的函数

'如需使用sleep函数 那么在程序的最开始加上下面这一行 注意调用的时候Sleep的S要大写
Private Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)

'生成一个指定范围的随机数
Private Function Rndz(a As Long, b As Long)
    Randomize
    Rndz = Int((a - b + 1) * Rnd() + b)
End Function

'按钮移动的核心代码,当鼠标移动到按钮的范围内的时候触发这个函数
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim 横坐标
Dim 纵坐标
'范围结合实际改一下
横坐标 = Rndz(0, 8000)
纵坐标 = Rndz(0, 6000)
Command1.Left = 横坐标
Command1.Top = 纵坐标
End Sub

'点击关闭按钮 取消关闭 并在生成一个窗体
Private Sub Form_Unload(Cancel As Integer)
Cancel = True
Dim f1 As New Form1
f1.Show

End Sub
原文地址:https://www.cnblogs.com/codepoetry/p/6104291.html