本帖最后由 .個朲綉√ 于 2011-9-1 12:54 编辑
点击父窗的配置控件后,进入子窗配置,配置好以后,保存,返回父窗
如果在返回父窗后,父窗能读取子窗写好的最新ini配置文件
不论我怎么弄,父窗读取的都是我之前一次子窗保存的数据,意思就是配置好以后,必需关掉软件,重新打开,父窗才能读取新配置。
如何不重启软件,读取最新配置呢?
应二楼这位兄台要求,秀一下GUI这段代码吧:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ExcelCOM_UDF.au3>
While 1
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("测试", 213, 178, 314, 177)
$Group1 = GUICtrlCreateGroup("数据查询系统", 0, 0, 209, 177)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button1 = GUICtrlCreateButton("开始", 120, 136, 75, 33)
$Button2 = GUICtrlCreateButton("配置",10,136,75,33)
$Label2 = GUICtrlCreateLabel("现在查询到第:", 15, 43, 100, 25)
$Label3 = GUICtrlCreateLabel("行。", 168, 43, 28, 25)
$Input2 = GUICtrlCreateInput("", 106, 37, 46, 25)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF0000)
$Input1 = GUICtrlCreateInput("手机号码", 34, 75, 145, 28)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF0000)
$Label1 = GUICtrlCreateLabel("请点击开始按钮", 68, 112, 116, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; GUISetState(@SW_SHOW)
;------------------第二个窗体----------------
Local $Config_File = @ScriptDir & "\Config.ini"
Local $Xls_File = IniRead($Config_File, "System", "Xls路径", "")
Local $Num_N = Number(IniRead($Config_File, "System", "号码列", ""));号码列
Local $Read_N = Number(IniRead($Config_File, "System", "读初始行", "3"));读初始行
Local $Write_N = Number(IniRead($Config_File, "System", "写记录列", "17"));写记录列
Local $Stop_N = Number(IniRead($Config_File, "System", "读号结束行", "502"));读号结束行
$Form2_2 = GUICreate("数据配置程序 by Subp", 326, 225, 192, 125)
$Label4 = GUICtrlCreateLabel("Excel路径:", 8, 16, 66, 17)
$XLS = GUICtrlCreateInput($Xls_File, 80, 16, 153, 21)
$Label9 = GUICtrlCreateLabel("例如:D:\数据库\数据.xls", 80, 40, 152, 17)
$Button3 = GUICtrlCreateButton("打开", 248, 16, 59, 25)
$Label6 = GUICtrlCreateLabel("号码列", 16, 72, 40, 17)
$Label8 = GUICtrlCreateLabel("写入列", 152, 72, 40, 17)
$Write = GUICtrlCreateInput($Write_N, 200, 72, 57, 21)
$Number = GUICtrlCreateInput($Num_N, 64, 72, 57, 21)
$Label7 = GUICtrlCreateLabel("开始行", 16, 128, 40, 17)
$Stop = GUICtrlCreateInput($Stop_N, 200, 128, 57, 21)
$Read = GUICtrlCreateInput($Read_N, 64, 128, 57, 21)
$Label5 = GUICtrlCreateLabel("结束行", 152, 128, 40, 17)
$Button4 = GUICtrlCreateButton("保存", 112, 176, 75, 25)
GUISetState(@SW_SHOW,$Form1_1)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
If $nMsg[1] == $Form1_1 Then
Exit
ElseIf $nMsg[1] == $Form2_2 Then
GUISetState(@SW_SHOW, $Form1_1)
GUISetState(@SW_HIDE, $Form2_2)
EndIf
Case $Button2
GUISetState(@SW_SHOW, $Form2_2)
GUISetState(@SW_HIDE, $Form1_1)
Case $Button3
open()
Case $Button4
IniWrite($Config_File,'System','Xls路径',GUICtrlRead($XLS))
IniWrite($Config_File,'System','号码列',GUICtrlRead($Number))
IniWrite($Config_File,'System','读初始行',GUICtrlRead($Read))
IniWrite($Config_File,'System','读号结束行',GUICtrlRead($Stop))
IniWrite($Config_File,'System','写记录列',GUICtrlRead($Write))
$oExcel = _ExcelBookOpen($Xls_File, 1)
If $oExcel = 0 Then
MsgBox(64, "提示:", $Xls_File & "打开失败.")
Exit
EndIf
; MsgBox(0,'保存配置文件','配置文件保存成功。',3)
GUISetState(@SW_SHOW, $Form1_1)
GUISetState(@SW_HIDE, $Form2_2)
Case $Button1
For $i = $Read_N To $Stop_N;遍历表格所有行
_Get_Num($i);读取号码
GUICtrlSetData($Input2,$i)
If _main($testnum,$i) = 1 Then ExitLoop
If $user_info[7][1] = 1200 Then
_ExcelWriteCell($oExcel,"到账",$i,$Write_N)
Else
_ExcelWriteCell($oExcel, $user_info[7][1], $i, $Write_N)
EndIf
Next
EndSwitch
WEnd
WEnd
Func open();浏览按钮,
$file=FileOpenDialog("请选择Excel文件",@ScriptDir,'Excel文件(*.xls)')
If FileExists($file) Then
GUICtrlSetData($XLS,$file)
EndIf
EndFunc
|