找回密码
 加入
搜索
查看: 1349|回复: 4

[AU3基础] (已解决)根据ini内的key值对窗体控件赋值

[复制链接]
发表于 2020-4-8 09:18:31 | 显示全部楼层 |阅读模式
本帖最后由 delux2004 于 2020-4-10 20:59 编辑

求助各位大神,小弟想制作一个程序,窗体内有较多控件;目的是想根据ini内的key值来对控件进行循环赋值,采用循环嵌套,但不成功,请大神指教,谢谢!

以下是代码和截图:


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 289, 305, 192, 124)
$Label1 = GUICtrlCreateLabel("姓名:", 32, 48, 40, 17)
$Name=GUICtrlCreateInput("", 85, 46, 121, 21)
$Label2 = GUICtrlCreateLabel("性别:", 32, 84, 40, 17)
$Sex =GUICtrlCreateInput("", 85, 82, 121, 21)
$Label3 = GUICtrlCreateLabel("年龄:", 32, 120, 40, 17)
$Age =GUICtrlCreateInput("", 85, 118, 121, 21)
$Label4 = GUICtrlCreateLabel("工号:", 32, 156, 40, 17)
$Number = GUICtrlCreateInput("", 85, 154, 121, 21)
$Label5= GUICtrlCreateLabel("基本工资", 32, 192, 52, 17)
$Wages =GUICtrlCreateInput("", 85, 190, 121, 21)
$Button1 = GUICtrlCreateButton("退出", 104, 248, 75, 25)
Data_Set()   ;调用函数赋值
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Exit
        EndSwitch
WEnd

Func Data_Set()
        Local $data[5][2]=[["姓名",$Name],["性别",$Sex],["年龄",$Age],["工号",$Number],["基本工资",$Wages]];将控件变量与控件名字合并为二维数组
        Local $var=IniReadSection("C:\config.ini", "config");读取config内的参数
                If @error Then
                        MsgBox(4096, "提示", "错误, 读取INI文件失败,请联系管理员!")
                Else
                        For $i=1 To $var[0][0]
                                For $j= 0 To $data[0][0]
                                        If $var[$i][0]=$data[$j][0] Then
                                                GUICtrlSetData($data[$j][1],$var[$i][1])                                                
                                        Endif
                                Next
                        Next
                Endif
               
Endfunc

本帖子中包含更多资源

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

×
发表于 2020-4-8 09:39:14 | 显示全部楼层
变通方法:在每个 $Labelx 的“下下”面读取 ini 并赋值。
发表于 2020-4-8 09:45:55 | 显示全部楼层
Func Data_Set()
        Local $data[5][2]=[["姓名",$Name],["性别",$Sex],["年龄",$Age],["工号",$Number],["基本工资",$Wages]];将控件变量与控件名字合并为二维数组
;~         Local $var=IniReadSection("C:\config.ini", "config");读取config内的参数
;~                 If @error Then
;~                         MsgBox(4096, "提示", "错误, 读取INI文件失败,请联系管理员!")
;~                 Else
;~                         For $i=1 To $var[0][0]
;~                                 For $j= 0 To $data[0][0]
;~                                         If $var[$i][0]=$data[$j][0] Then
;~                                                 GUICtrlSetData($data[$j][1],$var[$i][1])
;~                                         Endif
;~                                 Next
;~                         Next
;~                 Endif
        Local $var
        For $ii = 0 To 4
                $var = IniRead("C:\config.ini", 'config', $data[$ii][0], '')
                GUICtrlSetData($data[$ii][1], $var)
        Next
Endfunc
 楼主| 发表于 2020-4-8 10:42:56 | 显示全部楼层
chishingchan 发表于 2020-4-8 09:39
变通方法:在每个 $Labelx 的“下下”面读取 ini 并赋值。

好的,感谢!
 楼主| 发表于 2020-4-8 10:45:46 | 显示全部楼层

原来这么少代码就可以解决的问题,我还在里面绕了很久!
谢谢afan大神!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-18 23:51 , Processed in 0.073715 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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