| 
    
     |  | VBAで自機を動かすプログラム、敵機を自動で移動するプログラムはそれぞれ組めましたが、 その2つを同時に動かす段階で躓いています。
 
 Call '自機を動かすプログラム=aとします。
 Call ’敵機を動かすプログラム=bとします。
 とすると、aのプログラム終了後にbのプログラム処理となり、
 1つのプロシージャ内に両方入れようとすると上手くいきません。
 
 参考に、それぞれのソースを以下に貼り付けます。
 
 Sub 自機発生()
 
 Dim i As Integer
 Dim j As Integer
 
 Dim i2 As Integer
 Dim j2 As Integer
 
 
 Cells.Interior.ColorIndex = xlNone
 
 
 i = 10
 j = 10
 
 Cells(i, j).Interior.ColorIndex = 6
 
 
 Do
 
 '自機発生、操作
 
 If GetAsyncKeyState(37) <> 0 Then
 
 Cells(i, j).Interior.ColorIndex = xlNone
 If j <= 3 Then
 j = 17
 Else
 j = j - 1
 End If
 Cells(i, j).Interior.ColorIndex = 6
 
 End If
 
 If GetAsyncKeyState(38) <> 0 Then
 
 Cells(i, j).Interior.ColorIndex = xlNone
 If i <= 3 Then
 i = 17
 Else
 i = i - 1
 End If
 Cells(i, j).Interior.ColorIndex = 6
 
 End If
 
 If GetAsyncKeyState(39) <> 0 Then
 
 Cells(i, j).Interior.ColorIndex = xlNone
 If j >= 17 Then
 j = 3
 Else
 j = j + 1
 End If
 Cells(i, j).Interior.ColorIndex = 6
 
 End If
 
 If GetAsyncKeyState(40) <> 0 Then
 
 Cells(i, j).Interior.ColorIndex = xlNone
 If i >= 17 Then
 i = 3
 Else
 i = i + 1
 End If
 Cells(i, j).Interior.ColorIndex = 6
 
 End If
 
 If GetAsyncKeyState(13) <> 0 Then
 
 Exit Do
 
 End If
 
 DoEvents
 
 Sleep 90
 
 Loop
 
 
 End Sub
 
 Sub 発生()
 Dim i As Integer
 Dim j As Integer
 
 Randomize
 
 
 i = 3
 j = 15
 
 Do
 
 '敵機発生、ランダムで移動
 
 Cells(i, j).Interior.ColorIndex = xlNone
 
 
 If 0 <= Rnd And Rnd < 0.25 Then
 If i >= 17 Then
 i = 3
 Else
 i = i + 1
 End If
 Else
 If 0.25 <= Rnd And Rnd < 0.5 Then
 If j >= 17 Then
 j = 3
 Else
 j = j + 1
 End If
 Else
 If 0.5 <= Rnd And Rnd < 0.75 Then
 If i <= 3 Then
 i = 17
 Else
 i = i
 End If
 Else
 If 0.75 <= Rnd And Rnd < 1 Then
 If j <= 3 Then
 j = 17
 Else
 j = j - 1
 End If
 
 Cells(i, j).Interior.ColorIndex = 3
 
 End If
 
 If GetAsyncKeyState(13) <> 0 Then
 
 Exit Do
 
 End If
 
 DoEvents
 
 
 Sleep 90
 
 Loop
 
 
 End Sub
 
 よろしくお願いいたします。
 
 
 |  |