Excel VBA質問箱 IV

当質問箱は、有志のボランティア精神のおかげで成り立っています。
問題が解決したら、必ずお礼をしましょうね。
本サイトの基本方針をまとめました。こちら をご一読ください。

投稿種別の選択が必要です。ご注意ください。
迷惑投稿防止のため、URLの入力を制限しています。ご了承ください。


42974 / 76732 ←次へ | 前へ→

【38819】Re:VBAでボタンを作ってボタンを動か...
発言  漂流民  - 06/6/11(日) 15:36 -

引用なし
パスワード
   >もう一つのボタンをボールのように跳ねさして、
フツーに考えると落下かピンボールっぽい動きかな?
↓単純なやつ

Option Explicit
Private Declare Sub Sleep Lib "KERNEL32.dll" (ByVal dwMilliseconds As Long)
Public fh As Long
Public fw As Long
Public tsleep As Long

Private Sub UserForm_Initialize()
  fh = Me.InsideHeight
  fw = Me.InsideWidth
  tsleep = 10
  Me.CommandButton1.Caption = "徘徊"
  Call btr
End Sub

Private Sub CommandButton1_Click()
  If Me.CommandButton1.Caption = "徘徊" Then
    Call bttest1
  ElseIf Me.CommandButton1.Caption = "落下" Then
    Call bttest2
  ElseIf Me.CommandButton1.Caption = "ピンボール" Then
    Call bttest3
  End If
End Sub

Function bts()
  Me.CommandButton1.Height = 20
  Me.CommandButton1.Width = 20
  Me.CommandButton1.Caption = "■"
End Function
Function btr()
  Me.CommandButton1.Height = 25
  Me.CommandButton1.Width = 60
  Me.CommandButton1.Top = (fh / 2) - 12
  Me.CommandButton1.Left = (fw / 2) - 30
End Function

Function bst(x As Long, y As Long)
  DoEvents
  Me.CommandButton1.Left = x
  Me.CommandButton1.Top = y
  Sleep tsleep
End Function

Function bttest1()
  Dim bt1w As Long, bt1h As Long, x As Long, y As Long

  Call bts
  bt1w = Me.CommandButton1.Width
  bt1h = Me.CommandButton1.Height
  x = 1
  y = 1

  For x = 1 To (fw - bt1w)
    Call bst(x, y)
  Next x

  For y = 1 To (fh - bt1h)
    Call bst(x, y)
  Next y

  For x = (fw - bt1w) To 1 Step -1
    Call bst(x, y)
  Next x

  For y = (fh - bt1h) To 1 Step -1
    Call bst(x, y)
  Next y

  Call btr
  Me.CommandButton1.Caption = "落下"
End Function

Function bttest2()
  Dim bt1w As Long, bt1h As Long, lfw As Long, lfh As Long, _
    cf1 As Double, cf2 As Double, cf3 As Double, x As Double, y As Double

  Call bts
  bt1w = Me.CommandButton1.Width
  bt1h = Me.CommandButton1.Height
  lfw = fw - bt1w
  lfh = fh - bt1h
  cf1 = lfh / ((lfw / 3) * (lfw / 3))
  cf2 = (lfh / 2) / ((lfw / 6) * (lfw / 6))
  cf3 = (lfh / 4) / ((lfw / 6) * (lfw / 6))
  x = 1
  y = 1

  For x = 1 To lfw / 3
    y = cf1 * x * x
    Call bst(CLng(x), CLng(y))
  Next x

  For x = lfw / 3 To lfw / 3 * 2
    y = (cf2 * (x - (lfw / 2)) * (x - (lfw / 2))) + (lfh / 2)
    Call bst(CLng(x), CLng(y))
  Next x

  For x = lfw / 3 * 2 To lfw
    y = (cf3 * (x - (lfw * 5 / 6)) * (x - (lfw * 5 / 6))) + (lfh * 3 / 4)
    Call bst(CLng(x), CLng(y))
  Next x

  Call btr
  Me.CommandButton1.Caption = "ピンボール"
End Function

Function bttest3()
  Dim bt1w As Long, bt1h As Long, lfw As Long, lfh As Long, i As Long, _
    x As Long, y As Long, px As Long, py As Long

  Call bts
  bt1w = Me.CommandButton1.Width
  bt1h = Me.CommandButton1.Height
  lfw = fw - bt1w
  lfh = fh - bt1h
  x = 1
  y = 1

  For i = 1 To 1000
    If x = lfw Then
      px = -1
    ElseIf x = 1 Then
      px = 1
    End If

    If y = lfh Then
      py = -1
    ElseIf y = 1 Then
      py = 1
    End If

    x = x + px
    y = y + py
    Call bst(x, y)
  Next i

  Call btr
  Me.CommandButton1.Caption = "徘徊"
End Function

1 hits

【38764】VBAでボタンを作ってボタンを動かしたい os 06/6/9(金) 16:58 質問
【38775】Re:VBAでボタンを作ってボタンを動かし... マクロマン 06/6/9(金) 20:32 発言
【38784】Re:VBAでボタンを作ってボタンを動か... 漂流民 06/6/10(土) 1:24 発言
【38819】Re:VBAでボタンを作ってボタンを動か... 漂流民 06/6/11(日) 15:36 発言
【39687】Re:VBAでボタンを作ってボタンを動か... os 06/6/29(木) 0:18 お礼

42974 / 76732 ←次へ | 前へ→
ページ:  ┃  記事番号:
2610219
(SS)C-BOARD v3.8 is Free