【已解决】求助:怎样读取连续的变量并写入ini文件?
本帖最后由 lion.lee 于 2011-5-19 13:05 编辑目的:节约代码行数,用变量的方法自动读取QQ号码及密码自动写入ini文件中#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("QQ密码输入框", 502, 224, -1, -1)
GUISetBkColor(0xA6CAF0)
$passwordEdit = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input1 = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input2 = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input3 = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input5 = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input4 = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input6 = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input7 = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input8 = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input9 = GUICtrlCreateInput("password", 341, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Button1 = GUICtrlCreateButton("确定(&O)", 120, 176, 105, 33)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("取消(&C)", 261, 176, 105, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
$EnterPassLabel = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label1 = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label2 = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label3 = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label4 = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label5 = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label6 = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label7 = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label8 = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label9 = GUICtrlCreateLabel("QQ9", 261, 143, 64, 17, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
Exit
Case $Button1
#cs
代码是我自己想当然写成这个样子,还以为这是数组,呵呵!
我本来想用for函数,让$i从1到9变大后,ini文件的值也读到了。
各位大侠见笑了。
$i=1,$i=$Label
IniWrite("QQ密码","config",GUICtrlRead($Label))
#ce
EndSwitch
WEnd
完全不明白楼主的意思,并且代码也存在问题。 本帖最后由 netegg 于 2011-5-19 11:45 编辑
$i=1,$i=$Label,楼主,麻烦您解释下,$i到底取哪个值
如果是后者,请您指点下,这个label在什么地方定义并赋值的 完全不明白楼主的意思,并且代码也存在问题。
+1 发代码还把头文件给减掉了- -! 已经重新编辑了一下,各位请再帮忙看看!谢谢! $i=1,$i=$Label
IniWrite("QQ密码","config",GUICtrlRead($Label))
这两句代码让人百思不解. $i=1,$i=$Label
IniWrite("QQ密码","config",GUICtrlRead($Label))
这两句代码让人百思不解.
3mile 发表于 2011-5-19 12:06 http://www.autoitx.com/images/common/back.gif
这正是要在这向各位前辈求助的地方啊!这里不知道该怎么写? 回复 8# lion.lee
说句不太客气的话,你这么问也不会有结果,把你的ini贴出一部份上来,然后说明要如何操作或者得到什么结果,比你发错误代码可能效果更好 我不知道我有没理解错,你是不是想要这样的效果啊?#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("QQ密码输入框", 502, 224, -1, -1)
GUISetBkColor(0xA6CAF0)
Global $Input
$Input = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Button1 = GUICtrlCreateButton("确定(&O)", 120, 176, 105, 33)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("取消(&C)", 261, 176, 105, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
$EnterPassLabel = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label1 = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label2 = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label3 = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label4 = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label5 = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label6 = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label7 = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label8 = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label9 = GUICtrlCreateLabel("QQ9", 261, 143, 64, 17, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
Exit
Case $Button1
#cs
代码是我自己想当然写成这个样子,还以为这是数组,呵呵!
我本来想用for函数,让$i从1到9变大后,ini文件的值也读到了。
各位大侠见笑了。
$i=1,$i=$Label
IniWrite("QQ密码","config",GUICtrlRead($Label))
#ce
For $i=1 To 10
IniWrite("password.ini","config","QQ密码" & $i,GUICtrlRead($Input[$i]))
Next
EndSwitch
WEnd 我不知道我有没理解错,你是不是想要这样的效果啊?
ssjoe 发表于 2011-5-19 12:22 http://www.autoitx.com/images/common/back.gif
感谢这位大侠,我的目的基本达到了。谢谢!
还有一个问题,QQ号码没办法自动读取:
IniWrite("password.ini","config","QQ密码" & $i,GUICtrlRead($Input[$i]))
改为“IniWrite("password.ini","config",GUICtrlRead($Label[$i])
,GUICtrlRead($Input[$i]))”后报错$Label未声明。这咋整? 本帖最后由 netegg 于 2011-5-19 12:54 编辑
回复 11# lion.lee
GUICtrlRead($Label & $i)试试看,如果不行就把你前面的定义改了变量$label1改成$label,类推
楼主是不是基本函数的帮助都没看过就直接要代码来了 是不是这样?#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("QQ密码输入框", 502, 224, -1, -1)
GUISetBkColor(0xA6CAF0)
Global $Input,$Label
$Input = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Button1 = GUICtrlCreateButton("确定(&O)", 120, 176, 105, 33)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("取消(&C)", 261, 176, 105, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
$Label = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ9", 261, 143, 64, 17, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
Exit
Case $Button1
#cs
代码是我自己想当然写成这个样子,还以为这是数组,呵呵!
我本来想用for函数,让$i从1到9变大后,ini文件的值也读到了。
各位大侠见笑了。
$i=1,$i=$Label
IniWrite("QQ密码","config",GUICtrlRead($Label))
#ce
For $i=1 To 10
IniWrite("password.ini","config",GUICtrlRead($Label[$i]),GUICtrlRead($Input[$i]))
Next
EndSwitch
WEnd #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("QQ密码输入框", 502, 224, -1, -1)
GUISetBkColor(0xA6CAF0)
Global $Input
$Input = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input = GUICtrlCreateInput("password", 341, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Button1 = GUICtrlCreateButton("确定(&O)", 120, 176, 105, 33)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("取消(&C)", 261, 176, 105, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
Global $Label
$Label = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label = GUICtrlCreateLabel("QQ9", 261, 143, 64, 17, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
Exit
Case $Button1
For $i = 1 To 10
IniWrite("password.ini", "config", GUICtrlRead($Label[$i]), GUICtrlRead($Input[$i]))
Next
EndSwitch
WEnd
感谢这位大侠,我的目的基本达到了。谢谢!
还有一个问题,QQ号码没办法自动读取:
IniWrite("passwo ...
lion.lee 发表于 2011-5-19 12:42 http://www.autoitx.com/images/common/back.gif
已经搞定了,前面加一个Global $Label声明一下就好了,多谢! 回复 13# ssjoe
多谢回答!有各位热心的大大帮忙,是我们这些小菜的福气。再次感谢各位的帮忙!
页:
[1]