-1

I am working on a program in autoit. Unfortunately, I am getting problems in the following multiple conditions phase:

Here is my full code:

My code:

#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

I have no idea of it. Any help would be very much appreciated.

Compo
  • 36,585
  • 5
  • 27
  • 39
DREAMER
  • 1
  • 2

1 Answers1

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

You can use another switch statement to define the language code. Not sure why you would use separate variable names for the language code though I used a common name $sLanguage to be assigned the selected language code. This helps to avoid duplication of code i.e only one Run() function call needed, instead of three.

Also fixed the quoting of the command stored in $slktlng. I changed the argument of /K to /C so ComSpec automatically closes when done.

michael_heath
  • 5,262
  • 2
  • 12
  • 22