找回密码
 加入
搜索
查看: 4569|回复: 5

[效率算法] 已解决——有关数组信息的获取

  [复制链接]
发表于 2014-3-4 19:35:52 | 显示全部楼层 |阅读模式
本帖最后由 levinfish 于 2014-3-4 22:06 编辑

整理了一个简单的代码,请高手们看一下。
问题有两个:
1. 如何快速的得到数组的二维信息。
我自己试了几种方法,可以得到数组$array[$i][$j]的$i和$j的值,但是感觉比较复杂,就是想看看有没有什么函数之类,直接就能得到二维信息。
按理说,数组是自己定义的,autoit应该保存了这方面的信息吧,方便随时调用。


2. 因为按钮组是随机生成的,如何在case的判定行里面,包含所有的按钮。
Case $array[1][1] To $array[1][$array[1][0]-1]  (第一列的所有按钮),$array[2][1] To $array[2][$array[2][0]-1](第二列的所有按钮)
如果生成了三列按钮,则上述语句未包含所有已生成的按钮,如果生成了一列按钮,上述判定语句溢出,程序出错
#include <EditConstants.au3>
#Include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <file.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <date.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <Misc.au3>



Mygui()
                        
Func Mygui()
;====================================================================================================================
;================================================定义变量==========================================================
;====================================================================================================================
Dim $array[8][10],$i,$j,$a,$b


;====================================================================================================================
;================================================生成界面==========================================================
;====================================================================================================================

$guiparent=GUICreate("测试", 1200, 600)

GUISetBkColor(0x00E0FFFF)
For $i=1 To Random(1,6,1)
        For $j=1 To Random(2,8,1)
                $array[$i][$j]=GUICtrlCreateButton('按钮',50+($i-1)*180,50+($j-1)*60,160,50)
        Next
        $array[$i][$j]=GUICtrlCreateButton('添加',50+($i-1)*180,50+($j-1)*60,160,50)
        $array[$i][0]=$j
Next
GUISetState()
 
;====================================================================================================================
;================================================执行部分==========================================================
;====================================================================================================================
 
        While 1
             $msg = GUIGetMsg()
                
                                Switch $msg
                                        
                                Case $GUI_EVENT_CLOSE
                                        Exit
                                Case $array[1][1] To $array[1][$array[1][0]-1],$array[2][1] To $array[2][$array[2][0]-1];问题1所在位置。
                                        myfunc($i,$j);$i,$j代表数组的位置,例如如果是$array[1][5],就把1和5作为参数传递给一个自定义函数
                                EndSwitch
        
        WEnd
        
EndFunc         
        
        

;====================================================================================================================
;================================================自定义函数==========================================================
;====================================================================================================================

Func myfunc($a , $b)
        
EndFunc
发表于 2014-3-4 19:58:15 | 显示全部楼层
楼主是不是自己把自己弄糊涂了,你到底想想做什么?
控件ID可能未知,但其存储所用的变量名不是由你设定吗?
按钮的定义名字?那不是控件的文本文字吗?

建议你直接放上代码,配合它来表述问题吧!
发表于 2014-3-4 20:04:25 | 显示全部楼层
这次连伪代码都省了…
 楼主| 发表于 2014-3-4 20:08:10 | 显示全部楼层
好的 我整理一下代码。
发表于 2014-3-4 21:07:28 | 显示全部楼层
Dim $aId[50][3], $ix = 3, $i, $j, $a, $b

$guiparent = GUICreate("测试", 1200, 600)
For $i = 1 To Random(1, 6, 1)
        For $j = 1 To Random(2, 8, 1)
                $aId[$ix][0] = $i
                $aId[$ix][1] = $j
                $aId[$ix][2] = GUICtrlCreateButton('按钮' & $i & '-' & $j, 50 + ($i - 1) * 180, 50 + ($j - 1) * 60, 160, 50)
                $ix += 1
        Next
Next
GUISetState()

While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case -3
                        Exit
                Case 3 To $aId[$ix - 1][2]
                        myfunc($aId[$msg][0], $aId[$msg][1])
        EndSwitch
WEnd

Func myfunc($a, $b)
        MsgBox(0, $a, $b)
EndFunc   ;==>myfunc
 楼主| 发表于 2014-3-4 21:54:33 | 显示全部楼层
完美解决,afan大神,收我为徒吧。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-10 19:41 , Processed in 0.079489 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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