找回密码
 加入
搜索
查看: 2521|回复: 14

[GUI管理] 如何来表示连续的控件ID[已解决]

[复制链接]
发表于 2018-8-31 11:41:22 | 显示全部楼层 |阅读模式
本帖最后由 p7749 于 2018-9-3 17:57 编辑

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=d:\autoit3\ppp\form1检测.kxf
$Form1 = GUICreate("检测预警", 313, 442, 376, 123)
$Label1 = GUICtrlCreateLabel("列", 0, 0, 16, 17)
$Label2 = GUICtrlCreateLabel("行", 32, 0, 16, 17)
$Label3 = GUICtrlCreateLabel("说明", 64, 0, 28, 17)
$Label4 = GUICtrlCreateLabel("值", 192, 0, 40, 17)
$Label5 = GUICtrlCreateLabel("差值", 248, 0, 52, 17)
$Input1 = GUICtrlCreateInput("", 0, 16, 25, 21)
$Input2 = GUICtrlCreateInput("", 32, 16, 25, 21)
$Input3 = GUICtrlCreateInput("", 64, 16, 121, 21)
$Input4 = GUICtrlCreateInput("", 192, 16, 41, 21)
$Input5 = GUICtrlCreateInput("", 248, 16, 49, 21)
$Input6 = GUICtrlCreateInput("", 0, 41, 25, 21)
$Input7 = GUICtrlCreateInput("", 32, 41, 25, 21)
$Input8 = GUICtrlCreateInput("", 64, 41, 121, 21)
$Input9 = GUICtrlCreateInput("", 192, 41, 41, 21)
$Input10 = GUICtrlCreateInput("", 248, 41, 49, 21)
$Input11 = GUICtrlCreateInput("", 0, 66, 25, 21)
$Input12 = GUICtrlCreateInput("", 32, 66, 25, 21)
$Input13 = GUICtrlCreateInput("", 64, 66, 121, 21)
$Input14 = GUICtrlCreateInput("", 192, 66, 41, 21)
$Input15 = GUICtrlCreateInput("", 248, 66, 49, 21)
$Input16 = GUICtrlCreateInput("", 0, 91, 25, 21)
$Input17 = GUICtrlCreateInput("", 32, 91, 25, 21)
$Input18 = GUICtrlCreateInput("", 64, 91, 121, 21)
$Input19 = GUICtrlCreateInput("", 192, 91, 41, 21)
$Input20 = GUICtrlCreateInput("", 248, 91, 49, 21)
$Input21 = GUICtrlCreateInput("", 0, 117, 25, 21)
$Input22 = GUICtrlCreateInput("", 32, 117, 25, 21)
$Input23 = GUICtrlCreateInput("", 64, 117, 121, 21)
$Input24 = GUICtrlCreateInput("", 192, 117, 41, 21)
$Input25 = GUICtrlCreateInput("", 248, 117, 49, 21)
$Input26 = GUICtrlCreateInput("", 0, 142, 25, 21)
$Input27 = GUICtrlCreateInput("", 32, 142, 25, 21)
$Input28 = GUICtrlCreateInput("", 64, 142, 121, 21)
$Input29 = GUICtrlCreateInput("", 192, 142, 41, 21)
$Input30 = GUICtrlCreateInput("", 248, 142, 49, 21)
$Input31 = GUICtrlCreateInput("", 0, 167, 25, 21)
$Input32 = GUICtrlCreateInput("", 32, 167, 25, 21)
$Input33 = GUICtrlCreateInput("", 64, 167, 121, 21)
$Input34 = GUICtrlCreateInput("", 192, 167, 41, 21)
$Input35 = GUICtrlCreateInput("", 248, 167, 49, 21)
$Input36 = GUICtrlCreateInput("", 0, 192, 25, 21)
$Input37 = GUICtrlCreateInput("", 32, 192, 25, 21)
$Input38 = GUICtrlCreateInput("", 64, 192, 121, 21)
$Input39 = GUICtrlCreateInput("", 192, 192, 41, 21)
$Input40 = GUICtrlCreateInput("", 248, 192, 49, 21)
$Input41 = GUICtrlCreateInput("", 0, 218, 25, 21)
$Input42 = GUICtrlCreateInput("", 32, 218, 25, 21)
$Input43 = GUICtrlCreateInput("", 64, 218, 121, 21)
$Input44 = GUICtrlCreateInput("", 192, 218, 41, 21)
$Input45 = GUICtrlCreateInput("", 248, 218, 49, 21)
$Input46 = GUICtrlCreateInput("", 0, 243, 25, 21)
$Input47 = GUICtrlCreateInput("", 32, 243, 25, 21)
$Input48 = GUICtrlCreateInput("", 64, 243, 121, 21)
$Input49 = GUICtrlCreateInput("", 192, 243, 41, 21)
$Input50 = GUICtrlCreateInput("", 248, 243, 49, 21)
$Input51 = GUICtrlCreateInput("", 0, 268, 25, 21)
$Input52 = GUICtrlCreateInput("", 32, 268, 25, 21)
$Input53 = GUICtrlCreateInput("", 64, 268, 121, 21)
$Input54 = GUICtrlCreateInput("", 192, 268, 41, 21)
$Input55 = GUICtrlCreateInput("", 248, 268, 49, 21)
$Input56 = GUICtrlCreateInput("", 0, 293, 25, 21)
$Input57 = GUICtrlCreateInput("", 32, 293, 25, 21)
$Input58 = GUICtrlCreateInput("", 64, 293, 121, 21)
$Input59 = GUICtrlCreateInput("", 192, 293, 41, 21)
$Input60 = GUICtrlCreateInput("", 248, 293, 49, 21)
$Input61 = GUICtrlCreateInput("", 0, 319, 25, 21)
$Input62 = GUICtrlCreateInput("", 32, 319, 25, 21)
$Input63 = GUICtrlCreateInput("", 64, 319, 121, 21)
$Input64 = GUICtrlCreateInput("", 192, 319, 41, 21)
$Input65 = GUICtrlCreateInput("", 248, 319, 49, 21)
$Input66 = GUICtrlCreateInput("", 0, 344, 25, 21)
$Input67 = GUICtrlCreateInput("", 32, 344, 25, 21)
$Input68 = GUICtrlCreateInput("", 64, 344, 121, 21)
$Input69 = GUICtrlCreateInput("", 192, 344, 41, 21)
$Input70 = GUICtrlCreateInput("", 248, 344, 49, 21)
$Input71 = GUICtrlCreateInput("", 0, 369, 25, 21)
$Input72 = GUICtrlCreateInput("", 32, 369, 25, 21)
$Input73 = GUICtrlCreateInput("", 64, 369, 121, 21)
$Input74 = GUICtrlCreateInput("", 192, 369, 41, 21)
$Input75 = GUICtrlCreateInput("", 248, 369, 49, 21)
$Input76 = GUICtrlCreateInput("", 0, 394, 25, 21)
$Input77 = GUICtrlCreateInput("", 32, 394, 25, 21)
$Input78 = GUICtrlCreateInput("", 64, 394, 121, 21)
$Input79 = GUICtrlCreateInput("", 192, 394, 41, 21)
$Input80 = GUICtrlCreateInput("", 248, 394, 49, 21)
$Button1 = GUICtrlCreateButton("保存", 248, 424, 49, 17)
GUISetState(@SW_SHOW)
;GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


_xieru()
Sleep(3000)
Exit


Func _xieru();数据写入文件
        For $i=1 To 80
                iniWrite(@AppDataDir & "\" & "configjw.ini", "检测", $i,GUICtrlRead($i, 0));控件ID怎么表示呢; $i+7 可以但没有什么道理
                ;设置一个变量 $a="$input"&$i   来代替不管用       直接用数组变量代替$input1 $input[1] 感觉麻烦
        Next
EndFunc

发表于 2018-8-31 11:52:08 | 显示全部楼层
本帖最后由 afan 于 2018-8-31 12:26 编辑

        For $i = $Input1 To $Label80
                iniWrite(@AppDataDir & "\configjw.ini", "检测", $i - $Input1 + 1, GUICtrlRead($i, 0));
不用数组还真是不习惯,上面的复制错误,改为 For $i = $Input1 To $Input80

发表于 2018-8-31 11:55:34 | 显示全部楼层
用数组存放控件创建后的ID
发表于 2018-8-31 12:21:58 | 显示全部楼层
afan 发表于 2018-8-31 11:52
For $i = $Input1 To $Label80
                iniWrite(@AppDataDir & "\configjw.ini", "检测" ...

你打错了 TO 值
        For $i = $Input1 To $Input80
                IniWrite(@DesktopDir & "\configjw.ini", "检测", "$Input" & $i - $Input1 + 1, GUICtrlRead($i, 0))
        Next

评分

参与人数 1金钱 +20 收起 理由
afan + 20 的确

查看全部评分

发表于 2018-8-31 15:39:17 | 显示全部楼层
$i = $Input1 这种用法这么精辟,学习了,比数组简单了点
发表于 2018-8-31 16:23:30 | 显示全部楼层
不知管用不管用。来一段试试。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=d:\autoit3\ppp\form1检测.kxf
$Form1 = GUICreate("检测预警", 313, 442, 376, 123)
$Label1 = GUICtrlCreateLabel("列", 0, 0, 16, 17)
$Label2 = GUICtrlCreateLabel("行", 32, 0, 16, 17)
$Label3 = GUICtrlCreateLabel("说明", 64, 0, 28, 17)
$Label4 = GUICtrlCreateLabel("值", 192, 0, 40, 17)
$Label5 = GUICtrlCreateLabel("差值", 248, 0, 52, 17)

$iy=0
$iH=0
For $i=1 To 16
        Assign('input'&($ih+1),GUICtrlCreateInput("", 0, 16+25*$iy, 25, 21))
        Assign('input'&($ih+2),GUICtrlCreateInput("", 32, 16+25*$iy, 25, 21))
        Assign('input'&($ih+3),GUICtrlCreateInput("", 64, 16+25*$iy, 121, 21))
        Assign('input'&($ih+4),GUICtrlCreateInput("", 192, 16+25*$iy, 41, 21))
        Assign('input'&($ih+5),GUICtrlCreateInput("", 248, 16+25*$iy, 49, 21))
        $iH+=5
        $iy+=1
Next        

$Button1 = GUICtrlCreateButton("保存", 248, 424, 49, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ##

_xieru()
Sleep(3000)
Exit


Func _xieru();数据写入文件
        For $i=1 To 80
                iniWrite(@AppDataDir & "\configjw.ini", "检测", $i,GUICtrlRead(Eval('input'&$i)));控件ID怎么表示呢; $i+7 可以但没有什么道理
                ;设置一个变量 $a="$input"&$i   来代替不管用       直接用数组变量代替$input1 $input[1] 感觉麻烦
        Next
EndFunc

发表于 2018-8-31 19:16:22 | 显示全部楼层
顽固不化 发表于 2018-8-31 16:23
不知管用不管用。来一段试试。

少用这种方式,弊端不少~
发表于 2018-8-31 19:42:10 | 显示全部楼层
afan 发表于 2018-8-31 19:16
少用这种方式,弊端不少~

很早以前,我记得我编写啥程序来,用这个方式减少不少代码
发表于 2018-8-31 19:44:57 | 显示全部楼层
顽固不化 发表于 2018-8-31 19:42
很早以前,我记得我编写啥程序来,用这个方式减少不少代码

我也用过,不过早弃用了。代码长一点弊端就明显了。
最好的方式,一定是数组。
发表于 2018-8-31 20:55:43 | 显示全部楼层
afan 发表于 2018-8-31 11:52
For $i = $Input1 To $Label80
                iniWrite(@AppDataDir & "\configjw.ini", "检测" ...

老大 如果想解決的是   $Input1 ~$Input80  這80個變數的話

有簡短的寫法嗎??
发表于 2018-8-31 21:00:37 | 显示全部楼层
kk_lee69 发表于 2018-8-31 20:55
老大 如果想解決的是   $Input1 ~$Input80  這80個變數的話

有簡短的寫法嗎??

用数组就好了啊,其元素下标比 变量名的序号更方便也更精准
发表于 2018-8-31 21:19:07 | 显示全部楼层
afan 发表于 2018-8-31 19:44
我也用过,不过早弃用了。代码长一点弊端就明显了。
最好的方式,一定是数组。

嗯嗯,说的有道理
发表于 2018-9-3 11:14:32 | 显示全部楼层
afan 发表于 2018-8-31 19:16
少用这种方式,弊端不少~

老大是少用 Assign 还是少用Eval啊?
发表于 2018-9-3 11:18:53 | 显示全部楼层
志艺风云 发表于 2018-9-3 11:14
老大是少用 Assign 还是少用Eval啊?

常规声明(如 Dim $input1) 与 Assign、Eval 使用&混用(如 Assign("input" & "1"))
发表于 2018-9-3 11:22:39 | 显示全部楼层
BTW, 楼主3日内不结贴将扣分并移至无意义区。此类扔下不管的贴,相关版主应该有所为。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-4 23:51 , Processed in 0.079340 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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