标题:新人求助,俄罗斯方块,vba写的,不会改了
只看楼主
as9876
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2023-5-11
结帖率:0
已结贴  问题点数:20 回复次数:4 
新人求助,俄罗斯方块,vba写的,不会改了
求助,最近学着编写了用vba俄罗斯方块,在wps2019表格里写的,方向键相应正常,在另一个电脑的excel2010下运行,方向键不响应,想请教一下,是vba在wps和excel里的差异造成的么,不知道从什么地方、怎么改起,大侠们帮着解惑,不胜感激。。。
excel练习-俄罗斯方块23.4.28.zip (50.21 KB)

Private Sub Workbook_Open()
Sheet1.Clear
Application.OnKey "{up}", "sheet1.UP"
Application.OnKey "{down}", "sheet1.DOWN"
Application.OnKey "{right}", "sheet1.RIGHT"
Application.OnKey "{left}", "sheet1.LEFT"
Range("A1").Select
End Sub
Sub main()
Dim Yanse As Integer
Cells(4, 5).Resize(20, 10).Interior.ColorIndex = 2
Cells(2, 9) = 0
Speed = 500
100:
No = Int(Rnd * 7) + 1
Zt = Int(Rnd * 4) + 1
Yanse = Int(Rnd * 7) + 1
Select Case Yanse
    Case Is = 1
        Color = 33
    Case Is = 2
        Color = 44
    Case Is = 3
        Color = 10
    Case Is = 4
        Color = 46
    Case Is = 5
        Color = 41
    Case Is = 6
        Color = 43
    Case Is = 7
        Color = 26
End Select
X = 4
Select Case No
    Case Is = 1
        Y = Int(Rnd * 10) + 5
    Case Is < 4
        Y = Int(Rnd * 9) + 5
    Case Is < 7
        Y = Int(Rnd * 8) + 5
End Select
Tetris CInt(No), CInt(Zt), CInt(Color), CInt(X), CInt(Y)
Hx = Minh(CInt(No), CInt(Zt), CInt(X), CInt(Y))
Do While Hx > 0
    Application.ScreenUpdating = False
    Tetris CInt(No), CInt(Zt), 2, CInt(X), CInt(Y)
    X = X + 1
    Tetris CInt(No), CInt(Zt), CInt(Color), CInt(X), CInt(Y)
    Hx = Minh(CInt(No), CInt(Zt), CInt(X), CInt(Y))
    Application.ScreenUpdating = True
    Sleep Speed
    DoEvents
Loop
kill
For j = 5 To 14
    If Cells(7, j).Interior.ColorIndex <> 2 Then
    MsgBox "GAME OVER!!": Score = Cells(2, 9): tiaozhanbang
    Exit Sub
    End If
Next
GoTo 100
200:
End Sub
搜索更多相关主题的帖子: Int Color Sub Application Case 
2023-05-11 10:21
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:10 
2016 也不好使

DO IT YOURSELF !
2023-05-11 10:35
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:10 
office2019运行键盘无反应,改用API获取键盘了

程序代码:
Do While Hx > 0
    Application.ScreenUpdating = False
    Tetris (No), (Zt), 2, (x), (y)
    x = x + 1
    Tetris (No), (Zt), (Color), (x), (y)
    Hx = Minh((No), (Zt), (x), (y))
    
    If PeekMessage(msgMessage, lXLhwnd, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE) Then
        iKeyCode = msgMessage.time
        If iKeyCode = vbKeyUp Or iKeyCode = vbKeyW Then UP
        If iKeyCode = vbKeyDown Or iKeyCode = vbKeyS Then DOWN
        If iKeyCode = vbKeyLeft Or iKeyCode = vbKeyA Then LEFT
        If iKeyCode = vbKeyRight Or iKeyCode = vbKeyD Then RIGHT
    End If
    
    Application.ScreenUpdating = True
    
    DoEvents
    Sleep Speed
Loop





excel练习-俄罗斯方块23.4.28.xls.7z (42.01 KB)
2023-05-11 21:06
as9876
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2023-5-11
得分:0 
感谢两位大侠帮助,附件好像下不来

[此贴子已经被作者于2023-5-17 16:35编辑过]

2023-05-12 16:21
as9876
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2023-5-11
得分:0 
下载了,试了键盘没反应,有能响应键盘的么
excel练习-俄罗斯方块.zip (37.79 KB)


[此贴子已经被作者于2023-5-17 16:34编辑过]

2023-05-15 08:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-512164-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.059007 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved