人気ブログランキング | 話題のタグを見る

図形を動かす

今回は遊びで図形を動かしてみることにした。
図形といってもクリップアートを挿入しただけの手抜き作業だ・・・
キー操作(←、→)で図形の動く方向を決めて、スペースキーでこのマクロを中止してみる。
図形を動かす_e0080122_12515937.gif

Option Explicit
Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vkey As Long) As Long

Sub 動く車()
 Dim mycar As Shape
 Dim myflg As Boolean
 Dim x As Integer
  Set mycar = ActiveSheet.Shapes("車")
  myflg = True
  x = 0

  Do While myflg = True
     If GetAsyncKeyState(39) <> 0 Then'右方向キー
       x = 1
     End If

    If GetAsyncKeyState(37) <> 0 Then'左方向キー
      x = -1
    End If

    If GetAsyncKeyState(32) <> 0 Then'スペースキー
       myflg = False
    End If
        mycar.IncrementLeft x
          DoEvents
  Loop
End Sub
by slayer0210 | 2005-12-06 13:00 | マクロ


<< トリミングもどき 重複データを除く表を作成(関数) >>