找回密码
 加入
搜索
查看: 5382|回复: 7

[AU3基础] (已解决)如何用下拉框选择赋值给iniread中的字段名

  [复制链接]
发表于 2011-4-26 22:03:05 | 显示全部楼层 |阅读模式
本帖最后由 xiezhang6263 于 2011-4-30 23:06 编辑


下拉框里的值是从ini文件里获取
ini文件如下:
[A用户]
用户名=12345@163.com
密码=12345
[B用户]
用户名=12345@126.com
密码=12345
[C用户]
用户名=12345@yahoo.com.cn
密码=12345

现在请问如何将下拉框里选中的值赋值到IniRead($path,"字段名", "密码", "") 的字段名中,把”字段名“变为自己下拉框里选中的对象。
比如我选中A用户,用A用户的账号密码登录到网页中。
#NoTrayIcon
#include <IE.au3>
#include <Misc.au3>
#include <Date.au3>
#include <INet.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 256, 115, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 40, 32, 145, 25)
GUISetState(@SW_SHOW)
read()
#EndRegion ### END Koda GUI section ###


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


        EndSwitch
WEnd

Func read()
$var = IniReadSectionNames("setting.ini")
If @error Then 
    MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
    For $i = 1 To $var[0]
      $a=GUICtrlSetData($Combo1,$var[$i])
    Next
EndIf
EndFunc

$path = @ScriptDir & "\Setting.ini"
If Not FileExists($path) Then
        IniWrite($path, "配置", "用户名", "")
        IniWrite($path, "配置", "密码", "")
EndIf
$user = IniRead($path, "配置", "用户名", "")
$pwd = IniRead($path,"配置", "密码", "")                    ;这段代码如何把”字段名“变为自己下拉框里选中的对象。
If $user = "" Or $pwd = "" Then
        MsgBox(0, "警告", "配置文件中用户名或密码为空!")
        ShellExecute($path)
        Exit
        Else
                
                $oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.navigate('http://www.kaixin001.com/')
$oIE.height = @DesktopHeight
$oIE.width = @DesktopWidth
Do
Until $oIE.busy = False Or $oIE.readyState = 4
$oIE.document.getElementById('email').value = $user
$oIE.document.getElementById('password').value = $pwd
Sleep(2000)
$oIE.document.GetElementById('btn_dl').click           ;btn_dl为网页源码id部分

EndIf

本帖子中包含更多资源

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

×
发表于 2011-4-27 08:13:35 | 显示全部楼层
现在没空,空了研究一下,呵呵
发表于 2011-4-27 09:04:17 | 显示全部楼层
可以用guictrlread()读取combo中的值
发表于 2011-4-27 09:25:47 | 显示全部楼层
这个也正是我需要的,在你的基础上搜索了一下
ControlGetText($Form1, "", $Combo1)) 可以读取下拉列表的数据,但是在界面循环中需要添加一个按钮来执行,我直接加到退出的那个X上了,运行以后选择,然后点X试试看
而且很奇怪你为什么加了那么多include,需要哪个就加上,不需要的就去掉多好

#NoTrayIcon
#include <IE.au3>
#include <Misc.au3>
#include <Date.au3>
#include <INet.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$path = @ScriptDir & "\Setting.ini"
If Not FileExists($path) Then
        IniWrite($path, "配置", "用户名", "")
        IniWrite($path, "配置", "密码", "")
EndIf
$user = IniRead($path, "配置", "用户名", "")
$pwd = IniRead($path, "配置", "密码", "")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 256, 115, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 40, 32, 145, 25)
GUISetState(@SW_SHOW)
$var = IniReadSectionNames("setting.ini")
If @error Then
        MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
        For $i = 1 To $var[0]
                $a = GUICtrlSetData($Combo1, $var[$i])
        Next
EndIf
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        MsgBox(0, "你选中了:", ControlGetText($Form1, "", $Combo1))
                        ExitLoop

        EndSwitch
WEnd






$user = IniRead($path, ControlGetText($Form1, "", $Combo1), "用户名", "")
$pwd = IniRead($path, ControlGetText($Form1, "", $Combo1), "密码", "") ;
MsgBox(0, $user, $pwd)


发表于 2011-4-27 09:31:58 | 显示全部楼层
Setting.ini
[用户1]
用户名=1
密码=11
[用户2]
用户名=2
密码=22
[用户3]
用户名=3
密码=333
发表于 2011-4-27 10:21:46 | 显示全部楼层
本帖最后由 骗子 于 2011-4-27 10:25 编辑

重新优化了一下,去除下拉列表中的空选项,设置IE为最大化

#include <GUIConstantsEx.au3>
#NoTrayIcon

$path = @ScriptDir & "\Setting.ini"
If Not FileExists($path) Then
        IniWrite($path, "用户1", "用户名", "")
        IniWrite($path, "用户1", "密码", "")
EndIf 
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 256, 115, 192, 124)
$var = IniReadSectionNames("setting.ini")
If @error Then
        MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
        $Combo1 = GUICtrlCreateCombo($var[1], 40, 32, 145, 25)
        For $i = 2 To $var[0]
                $a = GUICtrlSetData($Combo1, $var[$i])
        Next
EndIf
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        ExitLoop
        EndSwitch
WEnd
$user = IniRead($path, GUICtrlRead ($Combo1), "用户名", "")
$pwd = IniRead($path, GUICtrlRead ($Combo1), "密码", "") 
MsgBox(0, "你选取了"&GUICtrlRead ($Combo1), "用户名:"&$user&@CRLF &"密码:"&$pwd)

$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.navigate('http://www.kaixin001.com/')
$oIE.top = 0
$oIE.left = 0
$oIE.height = @DesktopHeight
$oIE.width = @DesktopWidth ;窗口是大了,但是位置不太对
Do         
        Sleep (100)
Until $oIE.busy = False Or $oIE.readyState = 4
$oIE.document.getElementById('email').value = $user
$oIE.document.getElementById('password').value = $pwd
Do         
        Sleep (100)
Until $oIE.busy = False Or $oIE.readyState = 4
$oIE.document.GetElementById('btn_dl').click           ;btn_dl为网页源码id部分

 楼主| 发表于 2011-4-27 20:11:27 | 显示全部楼层
回复 6# 骗子

终于可以解决赋值的问题了。谢谢骗子
发表于 2011-4-27 21:20:05 | 显示全部楼层
回复  骗子

终于可以解决赋值的问题了。谢谢骗子
xiezhang6263 发表于 2011-4-27 20:11


谢谢骗子....
看着真别扭。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-27 01:02 , Processed in 0.085327 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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