找回密码
 加入
搜索
查看: 2497|回复: 6

[AU3基础] 求助.循环按钮读取INI配置文件问题(已解决)

[复制链接]
发表于 2011-6-30 03:53:17 | 显示全部楼层 |阅读模式
本帖最后由 夜猫猫 于 2011-7-7 12:06 编辑

测试半天还是不能点击相应按钮读取相应配置文件内容.
请帮忙下....谢谢


点价格按钮.自动读取价格.ini配置文件。点规格按钮就读取规格.INI配置文件。相对应按钮操作。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124, $WS_POPUP)
$Edit1 = GUICtrlCreateEdit("", 232, 48, 321, 305)
GUICtrlSetData(-1, "Edit1")
$Button1= GUICtrlCreateButton("退出", 500, 400, 97, 33)
GUICtrlSetOnEvent(-1, "_Exit")

$Cfg = @ScriptDir &"\config.ini"
$Hei = 40
$Car = IniReadSection($Cfg, "分类")
For $i = 1 To $Car[0][0]
       ;Msgbox ("","",$Car[$i][1])
           $Button= GUICtrlCreateButton($Car[$i][1], 24, $Hei, 97, 33)
       $Hei = $Hei +45
           GUICtrlSetOnEvent(-1, "Button")
   Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###   

While Sleep(10000)
WEnd

Func _Exit()
        Exit
EndFunc
        
Func Button()
        
                
EndFunc
config.ini

[分类]
0=价格
1=规格
2=个数

价格.ini

成品=15
半成品=24
赠送品=11

规格.ini

成品=12支
半成品=8支
赠送品=42支

数量.ini

成品=102箱
半成品=50箱
赠送品=24箱

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-6-30 09:59:35 | 显示全部楼层
你的问题应该在
$Button= GUICtrlCreateButton($Car[$i][1], 24, $Hei, 97, 33)
生成按扣时使用了相同变量而导致只有最后一个按扣有效
常试在前面加上
$Button="button"&$i
$Button= GUICtrlCreateButton($Car[$i][1], 24, $Hei, 97, 33)
顺便把
$Button1= GUICtrlCreateButton("退出", 500, 400, 97, 33)
这句改个名字
 楼主| 发表于 2011-6-30 12:00:39 | 显示全部楼层
不行.改那样后就不是我需要的效果了..
 楼主| 发表于 2011-7-7 02:29:36 | 显示全部楼层
本帖最后由 夜猫猫 于 2011-7-7 10:18 编辑

有点头目了...
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;Opt("GUIOnEventMode", 1)
Global $button[5]=[1,2,3,4,5]
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124, $WS_POPUP)
$Edit1 = GUICtrlCreateEdit("", 232, 48, 321, 305)
GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\规格.ini"))

$Button01= GUICtrlCreateButton("退出", 500, 400, 97, 33)
GUICtrlSetOnEvent(-1, "_Exit")

$Cfg = @ScriptDir &"\config.ini"
$Hei = 40
$Car = IniReadSection($Cfg, "分类")
For $i = 1 To $Car[0][0]
       ;Msgbox ("","",$Car[$i][1])
$button[$i]= GUICtrlCreateButton($Car[$i][1], 24, $Hei, 97, 33) 
$Hei = $Hei +45
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###   

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case  $Button[1]
              GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\规格.ini"))
                Case  $button[2]
             GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\价格.ini"))
                Case  $Button[3]
             GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\数量.ini"))
            Case  $Button01
             _Exit()
        EndSwitch
WEnd

Func _Exit()
        Exit
EndFunc
需要简化.
                     Case  $Button[1]
              GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\规格.ini"))
                Case  $button[2]
             GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\价格.ini"))
                Case  $Button[3]
             GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\数量.ini"))
 楼主| 发表于 2011-7-7 12:06:10 | 显示全部楼层
搞定!


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-7-10 15:33:01 | 显示全部楼层
看到最后~~好像解决方法和我说的相差的不是太大,都是通过决解按钮重名来解决的~~~~~

啥就不谢谢我呢~~~
 楼主| 发表于 2011-7-11 02:25:09 | 显示全部楼层
不是的.我的解决方法是通过鼠标点击事件来获取的.GUIGetCursorInfo
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-1 23:45 , Processed in 0.079389 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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