【问题标题】:If statement not working AutoIT如果语句不起作用 AutoIT
【发布时间】:2016-11-07 13:38:44
【问题描述】:

我正在编写的代码有问题。我有一张列出工作人员详细信息的表格。当您选择记录并右键单击时,我正在尝试将电子邮件地址复制到剪贴板。我有以下代码:

 #include <GUIConstantsEx.au3>
 #include <mssql.au3>
 #include <MsgBoxConstants.au3>
 #include <Array.au3>
 #include <WindowsConstants.au3>
 #include <AutoItConstants.au3>
 global $title = "E-Mail address lookup"
 global $name = InputBox($title,"Please type the name of the person you wish to find")
 global $sqlCon = _MSSQL_Con("server", "username", "password", "directory-plus")
 global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'")
 if StringLen(StringStripWS($name,3)) < 1 then
 MsgBox(0, $title, "Name cannot be empty")
 Else
 Global $rset = UBound($result) - 1
 Global $ControlID = GUICreate($title, 500, 150)
 Global $idListview = GUICtrlCreateListView("Deparment|E-Mail Address|Name|Telephone Number", 10, 10, 480, 150)
 for $count = 1 to $rset step 1
      GUICtrlCreateListViewItem($result[$count][0] & "|" & $result[$count][2] & "|" & $result[$count][1] & "|" & $result[$count][2], $idListview)
      if MouseClick($MOUSE_CLICK_RIGHT)==1 Then
           ClipPut($result[$count][2])
      EndIf
 Next
 GUISetState(@SW_SHOW)
 GUISetState()

While 1
Global $Msg = GUIGetMsg()
Switch $Msg
    Case -3, $ControlID
        Exit
EndSwitch
 WEnd
EndIf

我原以为我在 for 循环中的 IF 语句可以解决问题,但是,当我运行我的代码时,它只会复制最后一行电子邮件地址列中的任何内容,而实际上我希望它复制电子邮件地址当您右键单击特定行但我不知道该怎么做时。

【问题讨论】:

    标签: autoit


    【解决方案1】:

    您的代码有两个主要问题。第一个是 MouseClick() 不检查是否按下鼠标按钮,而是发送鼠标按钮单击。由于发送鼠标按钮单击会成功,因此 MouseClick($MOUSE_CLICK_RIGHT)==1 将评估为 true。对于您创建的每个列表视图项,您都将电子邮件地址放在剪贴板上。

    第二个问题是if语句放错了地方。它在您创建每个列表视图项后立即执行。

    改为如下更改您的 While 语句

    While 1
     Global $Msg = GUIGetMsg()
     Switch $Msg
      Case -3, $ControlID
       Exit
      case $GUI_EVENT_SECONDARYDOWN   
       $selecteditem=StringSplit(GUICtrlRead(GUICtrlRead($idListview)),"|")
       if @error=0 and $selecteditem[0]>1 Then
        ClipPut($selecteditem[2])
       EndIf
     EndSwitch
    WEnd
    

    【讨论】:

      猜你喜欢
      • 2012-12-26
      • 2013-06-20
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多