VERSION 4.00 Begin VB.Form Form1 BackColor = &H00FFFFFF& Caption = "Form1" ClientHeight = 5340 ClientLeft = 2088 ClientTop = 2016 ClientWidth = 5772 Height = 5820 Left = 2040 LinkTopic = "Form1" ScaleHeight = 5340 ScaleWidth = 5772 Top = 1584 Width = 5868 Begin VB.CommandButton Command1 Caption = "click me" BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 19.2 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1092 Left = 1548 TabIndex = 0 Top = 1656 Width = 2712 End Begin VB.OptionButton MoveOption BackColor = &H00FFFFFF& Caption = "Run Away!" Height = 300 Index = 1 Left = 72 TabIndex = 2 Top = 288 Width = 1488 End Begin VB.OptionButton MoveOption BackColor = &H00FFFFFF& Caption = "Random Move" Height = 300 Index = 0 Left = 72 TabIndex = 1 Top = 36 Value = -1 'True Width = 1488 End End Attribute VB_Name = "Form1" Attribute VB_Creatable = False Attribute VB_Exposed = False 'A simple program to demonstrate how VB is driven by events Private Sub Command1_Click() 'these two lines create the new random position for the command button Command1.Left = Command1.Left + (Rnd() - 0.5) * 3000 Command1.Top = Command1.Top + (Rnd() - 0.5) * 3000 'these four lines make sure that the command button stays on the screen If Command1.Left < 0 Then Command1.Left = 0 If Command1.Left > Form1.Width - Command1.Width Then Command1.Left = Form1.Width - Command1.Width If Command1.Top < 0 Then Command1.Top = 0 If Command1.Top > Form1.Height - Command1.Height Then Command1.Top = Form1.Height - Command1.Height 'toggle the caption between thank you and click me If Command1.Caption = "Thank You" Then Command1.Caption = "Click Me" Else Command1.Caption = "Thank You" End If 'use the "Shell" function to start an outside program ' a = Shell("C:/DGF Software/Timer/Timer.exe", 1) End Sub Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'what to do when the mouse moves over the button 'if option 1 button is selected, run away! If MoveOption(1).Value = True Then 'run away from the mouse Command1.Top = Y + Command1.Top + 100 Command1.Left = X + Command1.Left + 100 'but don't let it run off screen If Command1.Top + Command1.Height > Form1.Height Then Command1.Top = 100 If Command1.Left + Command1.Width > Form1.Width Then Command1.Left = 100 End If End Sub