解决autoit中的多个条件问题

问题描述 投票:-1回答:1

我正在使用autoit中的程序。不幸的是,我在以下多个条件阶段遇到问题:

这是我的完整代码:

我的代码:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
; Create a GUI
Local $hGUI = GUICreate("my program", 300, 200)

; Create a combobox control.
Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20)
 Local $idButton = GUICtrlCreateButton("Activate", 210, 140, 85, 25)
Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "Arabic|French|English", "Arabic")

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

Local $sComboRead = ""

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idButton_Close
            ExitLoop

        Case $idButton
            $sComboRead = GUICtrlRead($idComboBox)
            ; defining language codes
            if $sComboRead = "Arabic" then  $slktar = "ar-MA"
            if $sComboRead = "French" then  $slktfr = "fr-FR"
            if $sComboRead = "English" then  $slkten = "en-US"

            local $slktlng = @ComSpec & " /K " & '"' & @ScriptDir & "\bin\prog.exe enable_language "       ;main operation witout the addinional language code
            case  $slktar
                 Run($slktlng & " " & $slktar, @ScriptDir & "\bin\", @SW_HIDE)      ; starting main operation + arabic language code          
            case $slktfr
                 Run($slktlng & " " & $slktfr, @ScriptDir & "\bin\", @SW_HIDE)      ; starting main operation + french language code
            case  $slkten
                 Run($slktlng & " " & $slkten, @ScriptDir & "\bin\", @SW_HIDE)    ; starting main operation + english language code

    EndSwitch
WEnd


GUIDelete($hGUI)
EndFunc

我不知道。任何帮助将非常感谢。

condition autoit
1个回答
0
投票
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sLanguage

    ; Create a GUI
    Local $hGUI = GUICreate("my program", 300, 200)

    ; Create a combobox control.
    Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20)
    Local $idButton = GUICtrlCreateButton("Activate", 210, 140, 85, 25)
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, "Arabic|French|English", "Arabic")

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $sComboRead = ""

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop

            Case $idButton
                $sComboRead = GUICtrlRead($idComboBox)

                local $slktlng = '"' & @ComSpec & '" /C "' & @ScriptDir & '\bin\prog.exe" enable_language'

                ; Define language code.
                Switch $sComboRead
                    Case "Arabic"
                        $sLanguage = "ar-MA"
                    Case "French"
                        $sLanguage = "fr-FR"
                    Case "English"
                        $sLanguage = "en-US"
                EndSwitch

                Run($slktlng & " " & $sLanguage, @ScriptDir & "\bin\", @SW_HIDE)
        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc

您可以使用另一个switch语句来定义语言代码。虽然我使用通用名称$sLanguage来分配所选的语言代码,但不确定为什么要为语言代码使用单独的变量名称。这有助于避免重复代码,即只需要一个Run()函数调用,而不是三个。

还修复了存储在$slktlng中的命令的引用。我将/K的论点改为/C所以ComSpec在完成时会自动关闭。

© www.soinside.com 2019 - 2024. All rights reserved.