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

[AU3基础] 【已解决】求助:怎样读取连续的变量并写入ini文件?

 火.. [复制链接]
发表于 2011-5-19 11:06:38 | 显示全部楼层 |阅读模式
本帖最后由 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[1]
                        IniWrite("QQ密码","config",GUICtrlRead($Label[i]))
#ce
        EndSwitch
WEnd
发表于 2011-5-19 11:38:51 | 显示全部楼层
完全不明白楼主的意思,并且代码也存在问题。
发表于 2011-5-19 11:43:54 | 显示全部楼层
本帖最后由 netegg 于 2011-5-19 11:45 编辑

$i=1,$i=$Label[1],楼主,麻烦您解释下,$i到底取哪个值
如果是后者,请您指点下,这个label[1]在什么地方定义并赋值的
发表于 2011-5-19 11:45:43 | 显示全部楼层
完全不明白楼主的意思,并且代码也存在问题。

+1
发表于 2011-5-19 11:50:54 | 显示全部楼层
发代码还把头文件给减掉了- -!
 楼主| 发表于 2011-5-19 11:56:24 | 显示全部楼层
已经重新编辑了一下,各位请再帮忙看看!谢谢!
发表于 2011-5-19 12:06:59 | 显示全部楼层
$i=1,$i=$Label[1]
IniWrite("QQ密码","config",GUICtrlRead($Label[i]))
这两句代码让人百思不解.
 楼主| 发表于 2011-5-19 12:13:56 | 显示全部楼层
$i=1,$i=$Label[1]
IniWrite("QQ密码","config",GUICtrlRead($Label))
这两句代码让人百思不解.
3mile 发表于 2011-5-19 12:06


这正是要在这向各位前辈求助的地方啊!这里不知道该怎么写?
发表于 2011-5-19 12:20:22 | 显示全部楼层
回复 8# lion.lee
说句不太客气的话,你这么问也不会有结果,把你的ini贴出一部份上来,然后说明要如何操作或者得到什么结果,比你发错误代码可能效果更好
发表于 2011-5-19 12:22:05 | 显示全部楼层
我不知道我有没理解错,你是不是想要这样的效果啊?
#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[11]
$Input[1] = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[2] = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[3] = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[4] = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[5] = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[6] = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[7] = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[8] = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[9] = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[10] = 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[1]
                        IniWrite("QQ密码","config",GUICtrlRead($Label[i]))
#ce


For $i=1 To 10
        IniWrite("password.ini","config","QQ密码" & $i,GUICtrlRead($Input[$i]))
Next


        EndSwitch
WEnd
 楼主| 发表于 2011-5-19 12:42:14 | 显示全部楼层
我不知道我有没理解错,你是不是想要这样的效果啊?
ssjoe 发表于 2011-5-19 12:22


感谢这位大侠,我的目的基本达到了。谢谢!
还有一个问题,QQ号码没办法自动读取:
IniWrite("password.ini","config","QQ密码" & $i,GUICtrlRead($Input[$i]))
改为“IniWrite("password.ini","config",GUICtrlRead($Label[$i])
,GUICtrlRead($Input[$i]))”后报错$Label未声明。这咋整?
发表于 2011-5-19 12:48:51 | 显示全部楼层
本帖最后由 netegg 于 2011-5-19 12:54 编辑

回复 11# lion.lee

GUICtrlRead($Label & $i)试试看,如果不行就把你前面的定义改了变量$label1改成$label[1],类推

楼主是不是基本函数的帮助都没看过就直接要代码来了
发表于 2011-5-19 12:56:08 | 显示全部楼层
是不是这样?
#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[11],$Label[11]
$Input[1] = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[2] = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[3] = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[4] = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[5] = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[6] = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[7] = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[8] = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[9] = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[10] = 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[1] = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label[2] = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label[3] = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label[4] = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label[5] = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label[6] = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label[7] = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label[8] = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label[9] = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label[10] = 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[1]
                        IniWrite("QQ密码","config",GUICtrlRead($Label[i]))
#ce


For $i=1 To 10
        IniWrite("password.ini","config",GUICtrlRead($Label[$i]),GUICtrlRead($Input[$i]))
Next


        EndSwitch
WEnd
 楼主| 发表于 2011-5-19 13:03:31 | 显示全部楼层
#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[11]
$Input[1] = GUICtrlCreateInput("password", 88, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[2] = GUICtrlCreateInput("password", 88, 48, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[3] = GUICtrlCreateInput("password", 88, 80, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[4] = GUICtrlCreateInput("password", 88, 112, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[5] = GUICtrlCreateInput("password", 88, 143, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[6] = GUICtrlCreateInput("password", 341, 16, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[7] = GUICtrlCreateInput("password", 341, 47, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[8] = GUICtrlCreateInput("password", 341, 79, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[9] = GUICtrlCreateInput("password", 341, 111, 137, 21, $GUI_SS_DEFAULT_INPUT)
$Input[10] = 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[11]
$Label[1] = GUICtrlCreateLabel("QQ", 8, 16, 52, 17, 0)
$Label[2] = GUICtrlCreateLabel("QQ1", 8, 48, 58, 17, 0)
$Label[3] = GUICtrlCreateLabel("QQ2", 8, 112, 58, 17, 0)
$Label[4] = GUICtrlCreateLabel("QQ3", 8, 80, 58, 17, 0)
$Label[5] = GUICtrlCreateLabel("QQ4", 8, 144, 64, 17, 0)
$Label[6] = GUICtrlCreateLabel("QQ5", 261, 15, 64, 17, 0)
$Label[7] = GUICtrlCreateLabel("QQ6", 261, 47, 64, 17, 0)
$Label[8] = GUICtrlCreateLabel("QQ7", 261, 111, 58, 17, 0)
$Label[9] = GUICtrlCreateLabel("QQ8", 261, 79, 64, 17, 0)
$Label[10] = 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


已经搞定了,前面加一个Global $Label[11]声明一下就好了,多谢!
 楼主| 发表于 2011-5-19 13:09:52 | 显示全部楼层
回复 13# ssjoe
多谢回答!有各位热心的大大帮忙,是我们这些小菜的福气。再次感谢各位的帮忙!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-13 01:37 , Processed in 0.091393 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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