找回密码
 加入
搜索
查看: 587|回复: 9

[网络通信] 【已解决】请问批量创建的case如何给每个case创建新的变量。

[复制链接]
发表于 2023-3-18 17:46:04 | 显示全部楼层 |阅读模式
本帖最后由 7tenlboy 于 2023-3-20 16:22 编辑

GUICreate('', 220)
Local $Button[9], $i = 1
Local $mmm
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        MsgBox(0, '', GUICtrlRead($nMsg))

$mmm =$mmm+1

   MsgBox(0, '', $mmm)

        EndSwitch
WEnd



需求点击不同按钮实现不同变量,
发表于 2023-3-22 03:28:55 | 显示全部楼层
Global $msgMap[]
GUICreate('', 220)
Local $Button[9], $i = 1
Local $mmm
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        $msgMap[$Button[$i]] = '我是第' & $i & '个按钮'
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        MsgBox(0, '', $msgMap[$nMsg])
        EndSwitch
WEnd

点评

这个方法很好。谢谢你  发表于 2023-3-23 12:38

评分

参与人数 1金钱 +20 收起 理由
7tenlboy + 20 赞一个!

查看全部评分

发表于 2023-3-18 18:05:57 | 显示全部楼层
GUICreate('', 220)
Local $Button[9]
Local $mmm
For $i = 1 To 8
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
Next
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        $mmm = $nMsg - 2
                        MsgBox(0, 'wh2' & $mmm, GUICtrlRead($nMsg))
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
7tenlboy + 20 很给力!

查看全部评分

 楼主| 发表于 2023-3-18 17:46:16 | 显示全部楼层
本帖最后由 7tenlboy 于 2023-3-18 17:48 编辑

这个是一种方法。但是不是理想的,手动打代码比较麻烦

GUICreate('', 220)
Local $Button[9], $i = 1
Local $mmm
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1]
                        MsgBox(0, '', GUICtrlRead($nMsg))

$mmm =1

   MsgBox(0, '', $mmm)


                   Case $Button[2]
                        MsgBox(0, '', GUICtrlRead($nMsg))

$mmm =2

   MsgBox(0, '', $mmm)

        EndSwitch
WEnd
 楼主| 发表于 2023-3-18 17:51:18 | 显示全部楼层
本帖最后由 7tenlboy 于 2023-3-18 17:55 编辑

这个也是一种方法。$nMsg不是可控的变量,结果也不是理想,






GUICreate('', 220)
Local $Button[9], $i = 1
Local $mmm
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        MsgBox(0, '', GUICtrlRead($nMsg))

        EndSwitch
WEnd



 楼主| 发表于 2023-3-18 18:00:41 | 显示全部楼层
请问 如何根据按钮数量变量以实现点击$Button1 弹窗wh21 $Button2 弹窗 wh22,$Button3  弹窗 wh23,$Button4  弹窗 wh24,以此类推
 楼主| 发表于 2023-3-18 18:15:28 | 显示全部楼层

很辛苦你来解答。请问还有没有不通过 GUIGetMsg() 的方法来增加变量呀。
发表于 2023-3-18 18:24:33 | 显示全部楼层
句柄、坐标、控件内容 都可以
发表于 2023-3-18 18:37:38 | 显示全部楼层
7tenlboy 发表于 2023-3-18 18:15
很辛苦你来解答。请问还有没有不通过 GUIGetMsg() 的方法来增加变量呀。

消息模式用 GUIGetMsg() 是最简单的,如果是事件模式则使用 @GUI_CtrlId
还有诸如查表的方法,字典、Map 之类,方法很多,看用途选用最简单合适的~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 02:39 , Processed in 0.085494 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表