Jump to content

Need help re-creating part of my batch script in AutoIT


Recommended Posts

I'm quite new to AutoIT and I have a very big batch file that I'm trying to completely re-write in Autoit, so far it's been going well but I got stuck with a certain part, hope someone can help.

Here's the part of the batch script I'm currently stuck re-creating in AutoIT:

    :BeginLangMenu
    if "%OptNum%" gtr "0" goto ShowLangMenu
    
    ::Next Section code based on code supplied by Aacini from stackoverflow.com
    :DefineLangMenu
    for /L %%D in (1,1,99) do (
       if exist Common\Settings\Data%%D.ini for /F "eol=# tokens=1,2 delims==" %%a in (Common\Settings\Data%%D.ini) do (
    
          set line=%%a
          if "!line:~2,5!" neq "clude" (
             REM Define "normal" variables, i.e. Compressor, Method, etc.
             set %%a=
          ) else if "!line:~7!" neq "" (
    
             REM Define the base array elements, i.e. D1IncludeAR=%%b, D1ExcludeAR=%%b, ...
             set D%%D%%a=%%b
    
             REM Set Show?? array elements with value equal 1, i.e. ShowAR=1, ...
             REM when anyone of DiInclude?? or DiExclude?? corresponding elements was given
             if defined D%%D%%a set Show!line:~7!=1
    
          )
       )
    )
    
    REM Define a list of language abbreviations, i.e. "langs=AR CZ DE ..."
    REM and the corresponding language names array, i.e. lang[AR]=Arabic, ...
    REM At same time, calculate original OptNum
    
    for %%a in ("AR=Arabic" "CZ=Czech" "DE=German" "EN=English" "ES=Spanish" "ESMX=Spanish(Mexico)"
                "FR=French" "HU=Hungarian" "IT=Italian" "JP=Japanese" "KR=Korean" "PL=Polish"
                "PR=Portuguese" "PRBR=Portuguese(Brazil)" "RU=Russian" "ZH=Chinese") do (
       for /F "tokens=1,2 delims==" %%b in (%%a) do (
          set "langs=!langs! %%b"
          set "lang[%%b]=%%c"
          set /A "OptNum+=Show%%b"
    
       )
    )
    
    ::NEXT 2 SECTIONS DISPLAYS THE LANGUAGE SELECTION MENU IF APPLICABLE
    :ShowLangMenu
    set /a step=%step%+1
    :LangMenu
    if "%OptNum%"=="0" Goto checksplit
    echo %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% - Showing Language Selection Menu >> "%workdir%Conversion.log"
    REM Show the language menu
    set #=0
    for %%a in (%langs%) do (
       if defined Show%%a (
          set /A #+=1
    rem       echo [!#!] !lang[%%a]!
          echo !lang[%%a]! >> %b2eincfilepath%\Lang.txt
          set "option[!#!]=%%a" 
       )
    )
    
    
    %MYFILES1%\DROPDOWNBOX.exe /F:"%b2eincfilepath%\Lang.txt" "Choose Which Language to Compress" "STEP %step%: Language Selection"  /W:280 /RI /C:13 >nul > %b2eincfilepath%\LangAnswer.txt
    if %ERRORLEVEL% EQU 0 del %b2eincfilepath%\LangAnswer.txt
    if exist %b2eincfilepath%\LangAnswer.txt set /p "SelectLang="<%b2eincfilepath%\LangAnswer.txt
    if not defined SelectLang goto LangError
    if %SelectLang%==Arabic Set LangOpt=AR
    if %SelectLang%==Czech set LangOpt=CZ
    if %SelectLang%==German set LangOpt=DE
    if %SelectLang%==English set LangOpt=EN
    if %SelectLang%==Spanish set LangOpt=ES
    if %SelectLang%==Spanish(Mexico) set LangOpt=ESMX
    if %SelectLang%==French set LangOpt=FR
    if %SelectLang%==Hungarian set LangOpt=HU
    if %SelectLang%==Italian set LangOpt=IT
    if %SelectLang%==Japanese set LangOpt=JP
    if %SelectLang%==Korean set LangOpt=KR
    if %SelectLang%==Polish set LangOpt=PL
    if %SelectLang%==Portuguese set LangOpt=PR
    if %SelectLang%==Portuguese(Brazil) set LangOpt=PRBR
    if %SelectLang%==Russian set LangOpt=RU
    if %SelectLang%==Chinese set LangOpt=ZH
    if defined SelectLang Goto LangSet
    
    ::SETS THE LANGUAGE SELECTION ACCORDING TO USER INPUT IN LANGUAGE MENU
    :LangSet
    set "LangIs=%LangOpt%"

 

Basically, here's what I need to do:

  1.  Read from specific section of INI file but ONLY the Keys that have a Value. OR: A way to remove the keys without the values from the Array created by IniReadSection.
  2. A way to then take these stored values, and create a list of Languages based last 2-4 characters of the Key names.
  3. At this point, that said list is shown to user in DropDown box, after user make selection I need a way to move the Value of the Key related to the selected Language to a Variable, and ONLY the value for that specific Language.

That's it basically, the rest is more or less Variable manipulation which isn't a problem.

A little Example:

My INI file have a Section like this:

[LangInclude]
IncludeAR=a
IncludeCZ=
IncludeDE=b
IncludeEN=
IncludeES=c
IncludeESMX=
IncludeFR=
IncludeHU=d
IncludeIT=
IncludeJP=
IncludeKR=e
IncludePL=
IncludePR=
IncludePRBR=
IncludeRU=
IncludeZH=

I need to get Only the keys that are set, in this case: IncludeAR, IncludeDE, IncludeES, IncludeHU & IncludeKR.

I then need to convert these to a list of languages, in this example it will be (Arabic, German, Spanish, Hungarian, Korean).

That list will be turned to DropDown selection, that I can do easily once I get the list correctly.

After the user Selected, let us say for the example purpose Spanish, I need the Value of IncludeES to be moved into a Variable, like this: $Var=c

I hope somebody can help me because I'm stuck after Importing the INI section with IniReadSection, everything I tried so far failed, the best I managed to do is Sort the array to have all the keys with values either at the first rows or last rows.

I need some ideas.

Help appreciated.

Thanks
 

Edited by VollachR
Re-Phrased entire message

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

OK, figured out a way to do what I wanted, just not with IniReadSection, I used regular IniRead and lots of If...Then...Else statements, like this:

 

For $D = 1 To 99 Step +1
    if FileExists (@ScriptDir & "\Common\Settings\Data" & $D & ".ini") Then
        $ARi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeAR", "")
        $CZi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeCZ", "")
        $DEi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeDE", "")
        $ENi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeEN", "")
        $ESi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeES", "")
        $ESMXi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeESMX", "")
        $FRi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeFR", "")
        $HUi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeHU", "")
        $ITi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeIT", "")
        $JPi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeJP", "")
        $KRi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeKR", "")
        $PLi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludePL", "")
        $PRi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludePR", "")
        $PRBRi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludePRBR", "")
        $RUi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeRU", "")
        $ZHi = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangInclude", "IncludeZH", "")
        $ARe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeAR", "")
        $CZe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeCZ", "")
        $DEe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeDE", "")
        $ENe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeEN", "")
        $ESe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeES", "")
        $ESMXe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeESMX", "")
        $FRe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeFR", "")
        $HUe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeHU", "")
        $ITe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeIT", "")
        $JPe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeJP", "")
        $KRe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeKR", "")
        $PLe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludePL", "")
        $PRe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludePR", "")
        $PRBRe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludePRBR", "")
        $RUe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeRU", "")
        $ZHe = IniRead (@ScriptDir & "\Common\Settings\Data" & $D & ".ini", "LangExclude", "ExcludeZH", "")

Global $OptNum
Global $LangOptions

If Not IsDeclared ("AR") Then
    If Not $ARe = "" Or Not $ARi = "" Then $AR = "Arabic"
EndIf

If Not IsDeclared ("CZ") Then
    If Not $CZe = "" Or Not $CZi = "" Then $CZ = "Czech"
EndIf
If Not IsDeclared ("DE") Then
    If Not $DEe = "" Or Not $DEi = "" Then $DE = "German"
EndIf
If Not IsDeclared ("EN") Then
    If Not $ENe = "" Or Not $ENi = "" Then $EN = "English"
EndIf
If Not IsDeclared ("ES") Then
    If Not $ESe = "" Or Not $ESi = "" Then $ES = "Spanish"
EndIf
If Not IsDeclared ("ESMX") Then
    If Not $ESMXe = "" Or Not $ESMXi = "" Then $ESMX = "Spanish(Mexico)"
EndIf
If Not IsDeclared ("FR") Then
    If Not $FRe = "" Or Not $FRi = "" Then $FR = "French"
EndIf
If Not IsDeclared ("HU") Then
    If Not $HUe = "" Or Not $HUi = "" Then $HU = "Hungarian"
EndIf
If Not IsDeclared ("IT") Then
    If Not $ITe = "" Or Not $ITi = "" Then $IT = "Italian"
EndIf
If Not IsDeclared ("JP") Then
    If Not $JPe = "" Or Not $JPi = "" Then $JP = "Japanese"
EndIf
If Not IsDeclared ("KR") Then
    If Not $KRe = "" Or Not $KRi = "" Then $KR = "Korean"
EndIf
If Not IsDeclared ("PL") Then
    If Not $PLe = "" Or Not $PLi = "" Then $PL = "Polish"
EndIf
If Not IsDeclared ("PR") Then
    If Not $PRe = "" Or Not $PRi = "" Then $PR = "Portuguese"
EndIf
If Not IsDeclared ("PRBR") Then
    If Not $PRBRe = "" Or Not $PRBRi = "" Then $PRBR = "Portuguese(Brazil)"
EndIf
If Not IsDeclared ("RU") Then
    If Not $RUe = "" Or Not $RUi = "" Then $RU = "Russian"
EndIf
If Not IsDeclared ("ZH") Then
    If Not $ZHe = "" Or Not $ZHi = "" Then $ZH = "Chinese"
EndIf
    EndIf
    Next
if IsDeclared ("AR") then
    $OptNum+=1
    If $OptNum = 1 Then
        $LangOptions = "Arabic"
    EndIf
EndIf
if IsDeclared ("CZ") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Czech"
    Else
        $LangOptions = "Czech"
    EndIf
EndIf
if IsDeclared ("DE") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|German"
    Else
        $LangOptions = "German"
    EndIf
EndIf
if IsDeclared ("EN") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|English"
    Else
        $LangOptions = "English"
    EndIf
EndIf
if IsDeclared ("ES") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Spanish"
    Else
        $LangOptions = "Spanish"
    EndIf
EndIf
if IsDeclared ("ESMX") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Spanish(Mexico)"
    Else
        $LangOptions = "Spanish(Mexico)"
    EndIf
EndIf
if IsDeclared ("FR") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|French"
    Else
        $LangOptions = "French"
    EndIf
EndIf
if IsDeclared ("HU") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Hungarian"
    Else
        $LangOptions = "Hungarian"
    EndIf
EndIf
if IsDeclared ("IT") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Italian"
    Else
        $LangOptions = "Italian"
    EndIf
EndIf
if IsDeclared ("JP") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Japanese"
    Else
        $LangOptions = "Japanese"
    EndIf
EndIf
if IsDeclared ("KR") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Korean"
    Else
        $LangOptions = "Korean"
    EndIf
EndIf
if IsDeclared ("PL") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Polish"
    Else
        $LangOptions = "Polish"
    EndIf
EndIf
if IsDeclared ("PR") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Portuguese"
    Else
        $LangOptions = "Portuguese"
    EndIf
EndIf
if IsDeclared ("PRBR") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Portuguese(Brazil)"
    Else
        $LangOptions = "Portuguese(Brazil)"
    EndIf
EndIf
if IsDeclared ("RU") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Russian"
    Else
        $LangOptions = "Russian"
    EndIf
EndIf
if IsDeclared ("ZH") then
    $OptNum+=1
    If $OptNum > 1 Then
        $LangOptions = $LangOptions & "|Chinese"
    Else
        $LangOptions = "Chinese"
    EndIf
EndIf

 

Still, if someone have a better way of creating this than I'll be happy to hear.

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

@VollachR Welcome to Auto IT. 
Nice batch file by the way. 

In order to simplify this process, my take would be to save your batch file then have AutoIT store it in memory. You can take it to any computer and run it from your compiled AutoIT executable. 
Here's my code.  

;----------------------This section has been extracted from the help file----------------------
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.
; This will install the file New.bat to the script location.
If $bFileInstall Then FileInstall("New.bat", @ScriptDir & "\New.bat")
;----------------------------------------------------------------------------------------------

;----------------------Here you can point to you your bat file---------------------------------
Run(@ComSpec & " /c " & 'New.bat', "", @SW_SHOW)
;----------------------------------------------------------------------------------------------

;You can also make this batch file hidden by changing the @SW_SHOW to @SW_HIDE.
; But judging fby your batch, I would say leave it to @SW_SHOW
;Also in the help file.

 

Edited by Skeletor
Typo

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Link to post
Share on other sites
14 minutes ago, Skeletor said:

@VollachR Welcome to Auto IT. 
Nice batch file by the way. 

In order to simplify this process, my take would be to save your batch file then have AutoIT store it in memory. You can take it to any computer and run it from your compiled AutoIT executable. 
Here's my code.  

;----------------------This section has been extracted from the help file----------------------
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.
; This will install the file New.bat to the script location.
If $bFileInstall Then FileInstall("New.bat", @ScriptDir & "\New.bat")
;----------------------------------------------------------------------------------------------

;----------------------Here you can point to you your bat file---------------------------------
Run(@ComSpec & " /c " & 'New.bat', "", @SW_SHOW)
;----------------------------------------------------------------------------------------------

;You can also make this batch file hidden by changing the @SW_SHOW to @SW_HIDE.
; But judging fby your batch, I would say leave it to @SW_SHOW
;Also in the help file.

 

Thanks but Nah, I want to be rid of Batch files, the section of Batch file I posted here is just a very, very small part of the entire batch file, which Is a full blown program in batch file with over 2700 lines and over 186000 characters.

Problem is, some of the function in my Batch files are buggy and I already had to result to Batch/PowerShell/VBScript combinations, it is a big headache, I'm re-creating it all in AutoIT for few reasons.

1. It should protect my code better than Bat To Exe converters

2. It should make some of the functions easier to create (Like checking size of large folders & files which is a big headache in batch)

3. I've run into a bug in the batch file that other people reported but I can't re-create so I couldn't solve, had to bypass the problematic part of the script, and guess what, it is related to size checking.

 

Anyway, these are the main reasons I decided to abandon the archaic batch scripting and try to re-create my large script in AutoIT,

I've been working on that Batch File for around 4 years, updating and improving it all the time but now it's time for a better scripting language to replace it.

Edited by VollachR

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

@VollachR 

Okay, I kinda get what you want to do, so I made this sample here that reads from an INI file and outputs to the Edit Box. 

Note: The temp.ini file is placed in the same directory as where ever you save the "test" script for ease of use. 

 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 292, 252, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 32, 32, 225, 25)
$Combo11 = GUICtrlSetData($Combo1, "Arabic|German|Spanish|Hungarian|Korean")
$Edit1 = GUICtrlCreateEdit("", 32, 88, 225, 153, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            $ReadFrom = GuiCtrlRead($Combo1)
            If $ReadFrom = "Arabic" Then
            _Arabic()
                ElseIf $ReadFrom = "German" Then
                    _German()

                ElseIf $ReadFrom = "Spanish" Then
                    _Spanish()

                ElseIf $ReadFrom = "Hungarian" Then
                    _Hungarian()

                ElseIf $ReadFrom = "Korean" Then
                    _Korean()

                    EndIf



    EndSwitch
WEnd


Func _Arabic()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeAR", "")
    GUICtrlSetData($Edit1, "")
    GUICtrlSetData($Edit1, $ReadValue)
EndFunc


Func _German()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeDE", "")
    GUICtrlSetData($Edit1, "")
    GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Spanish()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeES", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Hungarian()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeHU", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Korean()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeKR", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

 

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Link to post
Share on other sites

Probably off base but what about:

#include <Array.au3>
#include <File.au3>
Global $aLanguages[1]
_GetLanguages()
_ArrayDisplay($aLanguages)

Func _GetLanguages()
    Local $aLanguageList[17][2] = [[16, ""], ["AR", "Arabic"], ["CZ", "Czech"], ["DE", "German"], ["EN", "English"], ["ES", "Spanish"], ["ESMX", "Spanish(Mexico)"], ["FR", "French"], ["HU", "Hungarian"], ["IT", "Italian"], ["JP", "Japanese"], ["KR", "Korean"], ["PL", "Polish"], ["PR", "Portuguese"], ["PRBR", "Portuguese(Brazil)"], ["RU", "Russian"], ["ZH", "Chinese"]]
    Local $aIniFileList = _FileListToArray(@ScriptDir & "\Common\Settings", "Data*.ini", 1, True)
    For $i = 1 To $aIniFileList[0]
        For $j = $aLanguageList[0][0] To 1 Step - 1
            IniRead($aIniFileList[$i], "LangInclude", "IncludeAR", "")
            If IniRead($aIniFileList[$i], "LangInclude", "Include" & $aLanguageList[$j][0], "") <> "" Then _ArrayAdd($aLanguages, $aLanguageList[$j][1])
        Next
    Next
    $aLanguages[0] = UBound($aLanguages) - 1
    _ArraySort($aLanguages, 0, 1)
EndFunc

 

Link to post
Share on other sites

... anther one you can try

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

Example()

Func Example()
    ; --------- INI file management zone ---------
    Local $sFilename = ".\Languages.ini" ; pathname of the ini file
    Local $sSessionName = "LangInclude" ; Session Name to read
    Local $Var ; <-- target of the selection (will contain the "value" part of the selected Key)

    ; 2D array with Abbreviation and Languages
    Local $aLanguages[][] = [['AR', 'Arabic'],['CZ', 'Czech'],['DE', 'German'],['EN', 'English'],['ES', 'Spanish'],['ESMX', 'Spanish(Mexico)'],['FR', 'French'],['HU', 'Hungarian'],['IT', 'Italian'],['JP', 'Japanese'],['KR', 'Korean'],['PL', 'Polish'],['PR', 'Portuguese'],['PRBR', 'Portuguese(Brazil)'],['RU', 'Russian'],['ZH', 'Chinese']]

    ; read all keys from the ini section and store keys/values in a 2D array
    Local $aData = IniReadSection($sFilename, $sSessionName)
    ; make room for 2 new columns
    ReDim $aData[UBound($aData)][4]

    ; Remove empty languages and fill new columns with needed data
    For $iIndex = $aData[0][0] To 1 Step -1
        If $aData[$iIndex][1] = "" Then
            _ArrayDelete($aData, $iIndex)
            $aData[0][0] -= 1
        Else ; set state abbreviation in column [2] and state name in column [3]
            $aData[$iIndex][2] = StringMid($aData[$iIndex][0], 8)
            $aData[$iIndex][3] = $aLanguages[_ArraySearch($aLanguages, $aData[$iIndex][2])][1]
        EndIf
    Next

    _ArrayDisplay($aData, "Resulting languages")
    ; -------- GUI Zone -------
    ; Create a GUI with controls.
    Local $hGUI = GUICreate("Example", 300, 200)

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

    ; Add items to the combobox.
    ; Items are Language names peeked from the column[3] of the $aData array
    GUICtrlSetData($idComboBox, _ArrayToString($aData, '', 1, -1, "|", 3, 3), "")

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

    Local $sComboRead = ""

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

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "You selected: " & $sComboRead, 0, $hGUI)

                $Var = $aData[_ArraySearch($aData, $sComboRead, 0, 0, 0, 0, 1, 4)][1]
                MsgBox($MB_SYSTEMMODAL, "", "The $Var variable has been setted" & @CRLF & "$Var contains --> " & $Var)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites
46 minutes ago, Skeletor said:

@VollachR 

Okay, I kinda get what you want to do, so I made this sample here that reads from an INI file and outputs to the Edit Box. 

Note: The temp.ini file is placed in the same directory as where ever you save the "test" script for ease of use. 

 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 292, 252, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 32, 32, 225, 25)
$Combo11 = GUICtrlSetData($Combo1, "Arabic|German|Spanish|Hungarian|Korean")
$Edit1 = GUICtrlCreateEdit("", 32, 88, 225, 153, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            $ReadFrom = GuiCtrlRead($Combo1)
            If $ReadFrom = "Arabic" Then
            _Arabic()
                ElseIf $ReadFrom = "German" Then
                    _German()

                ElseIf $ReadFrom = "Spanish" Then
                    _Spanish()

                ElseIf $ReadFrom = "Hungarian" Then
                    _Hungarian()

                ElseIf $ReadFrom = "Korean" Then
                    _Korean()

                    EndIf



    EndSwitch
WEnd


Func _Arabic()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeAR", "")
    GUICtrlSetData($Edit1, "")
    GUICtrlSetData($Edit1, $ReadValue)
EndFunc


Func _German()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeDE", "")
    GUICtrlSetData($Edit1, "")
    GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Spanish()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeES", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Hungarian()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeHU", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

Func _Korean()
    $sFilePath = "temp.ini"
    Local $ReadValue = IniRead($sFilePath, "LangInclude", "IncludeKR", "")
GUICtrlSetData($Edit1, "")
          GUICtrlSetData($Edit1, $ReadValue)
EndFunc

 

Not quite what I was looking for, I need the dropdown menu options to be dynamically set by which ever of the 16 keys in both LangInclude and LangExclude sections of the ini flies are defined, take a look at the crude script I create with IniRead to see what I mean, I'm reading both [LangInclude] & [LangExclude) and then check for each language if the key in any of the two section is defined.

27 minutes ago, Subz said:

Probably off base but what about:

#include <Array.au3>
#include <File.au3>
Global $aLanguages[1]
_GetLanguages()
_ArrayDisplay($aLanguages)

Func _GetLanguages()
    Local $aLanguageList[17][2] = [[16, ""], ["AR", "Arabic"], ["CZ", "Czech"], ["DE", "German"], ["EN", "English"], ["ES", "Spanish"], ["ESMX", "Spanish(Mexico)"], ["FR", "French"], ["HU", "Hungarian"], ["IT", "Italian"], ["JP", "Japanese"], ["KR", "Korean"], ["PL", "Polish"], ["PR", "Portuguese"], ["PRBR", "Portuguese(Brazil)"], ["RU", "Russian"], ["ZH", "Chinese"]]
    Local $aIniFileList = _FileListToArray(@ScriptDir & "\Common\Settings", "Data*.ini", 1, True)
    For $i = 1 To $aIniFileList[0]
        For $j = $aLanguageList[0][0] To 1 Step - 1
            IniRead($aIniFileList[$i], "LangInclude", "IncludeAR", "")
            If IniRead($aIniFileList[$i], "LangInclude", "Include" & $aLanguageList[$j][0], "") <> "" Then _ArrayAdd($aLanguages, $aLanguageList[$j][1])
        Next
    Next
    $aLanguages[0] = UBound($aLanguages) - 1
    _ArraySort($aLanguages, 0, 1)
EndFunc

 

This seems to work correctly, except it doesn't take into account the [LangExclude] section, I also couldn't understand how to use the created array to populate the ComboBox (Dropdown menu).

24 minutes ago, Chimp said:

... anther one you can try

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

Example()

Func Example()
    ; --------- INI file management zone ---------
    Local $sFilename = ".\Languages.ini" ; pathname of the ini file
    Local $sSessionName = "LangInclude" ; Session Name to read
    Local $Var ; <-- target of the selection (will contain the "value" part of the selected Key)

    ; 2D array with Abbreviation and Languages
    Local $aLanguages[][] = [['AR', 'Arabic'],['CZ', 'Czech'],['DE', 'German'],['EN', 'English'],['ES', 'Spanish'],['ESMX', 'Spanish(Mexico)'],['FR', 'French'],['HU', 'Hungarian'],['IT', 'Italian'],['JP', 'Japanese'],['KR', 'Korean'],['PL', 'Polish'],['PR', 'Portuguese'],['PRBR', 'Portuguese(Brazil)'],['RU', 'Russian'],['ZH', 'Chinese']]

    ; read all keys from the ini section and store keys/values in a 2D array
    Local $aData = IniReadSection($sFilename, $sSessionName)
    ; make room for 2 new columns
    ReDim $aData[UBound($aData)][4]

    ; Remove empty languages and fill new columns with needed data
    For $iIndex = $aData[0][0] To 1 Step -1
        If $aData[$iIndex][1] = "" Then
            _ArrayDelete($aData, $iIndex)
            $aData[0][0] -= 1
        Else ; set state abbreviation in column [2] and state name in column [3]
            $aData[$iIndex][2] = StringMid($aData[$iIndex][0], 8)
            $aData[$iIndex][3] = $aLanguages[_ArraySearch($aLanguages, $aData[$iIndex][2])][1]
        EndIf
    Next

    _ArrayDisplay($aData, "Resulting languages")
    ; -------- GUI Zone -------
    ; Create a GUI with controls.
    Local $hGUI = GUICreate("Example", 300, 200)

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

    ; Add items to the combobox.
    ; Items are Language names peeked from the column[3] of the $aData array
    GUICtrlSetData($idComboBox, _ArrayToString($aData, '', 1, -1, "|", 3, 3), "")

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

    Local $sComboRead = ""

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

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "You selected: " & $sComboRead, 0, $hGUI)

                $Var = $aData[_ArraySearch($aData, $sComboRead, 0, 0, 0, 0, 1, 4)][1]
                MsgBox($MB_SYSTEMMODAL, "", "The $Var variable has been setted" & @CRLF & "$Var contains --> " & $Var)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

This one was the best fit so far, just a question, how can I make it also check the [LangExclude] section in the same ini file and set the language if either or both Include & Exclude keys for the same language are defined?

For example:

[LangInclude]
IncludeAR=a
IncludeCZ=
IncludeDE=b
IncludeEN=
IncludeES=c
IncludeESMX=
IncludeFR=
IncludeHU=d
IncludeIT=
IncludeJP=
IncludeKR=e
IncludePL=
IncludePR=
IncludePRBR=
IncludeRU=
IncludeZH=


[LangExclude]
ExcludeAR=b
ExcludeCZ=c
ExcludeDE=f
ExcludeEN=g
ExcludeES=
ExcludeESMX=
ExcludeFR=
ExcludeHU=
ExcludeIT=
ExcludeJP=
ExcludeKR=
ExcludePL=
ExcludePR=
ExcludePRBR=
ExcludeRU=
ExcludeZH=

in this case, the list of language should be Arabic, German, Spanish, Hungarian, Czech, Korean & English

 

Thank you all.
 

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites
2 minutes ago, Subz said:

If the Language is in both LangInclude and LangExclude which one should win?  To add an array to combo you just use _ArrayToString (see Chimps code)

doesn't matter, as long as the end result is that the language appear in the list only once, that's why in my cruder script with IniRead I used OR to check if either of the two are defined and not AND to check if both are.

Technically I could possibly even remove the LangInclude section altogether and stay with the LangExclude alone but that's something to consider for the future, right now I want to get what I already have with my batch file working, later on I can look into ways to improve/simplify things.

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

Here is an alternative method based upon the @OSLang Macro (Used Chimps Example Gui)

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

Global $sLanguageDefault = ""
Global $aLanguageSelect[1][3]

_Example()

Func _Example()
    _GetLanguages()
    _ArrayDisplay($aLanguageSelect)
    ; -------- GUI Zone -------
    ; Create a GUI with controls.
    Local $hGUI = GUICreate("Example", 300, 200)

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

    ; Add items to the combobox.
    ; Items are Language names peeked from the column[3] of the $aData array
    GUICtrlSetData($idComboBox, _ArrayToString($aLanguageSelect, "", 1, -1, "|", 1, 1), $sLanguageDefault)

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

    Local $sComboRead = ""

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

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "You selected: " & $sComboRead, 0, $hGUI)

                $sLanguageDefault = $aLanguageSelect[_ArraySearch($aLanguageSelect, $sComboRead, 0, 0, 0, 0, 1, 1)][1]
                MsgBox($MB_SYSTEMMODAL, "", "The $Var variable has been setted" & @CRLF & "$Var contains --> " & $sLanguageDefault)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _GetLanguages()
    Local $aLanguageList[17][3] = [[16, "", ""], _ ;~ Language Count
        ["AR", "Arabic", "0401;0801;0C01;1001;1401;1801;1C01;2001;2401;2801;2C01;3001;3401;3801;3C01;4001"], _
        ["CZ", "Czech", "0405"], _
        ["DE", "German", "0407;0807;0C07;1007;1407"], _
        ["EN", "English", "0409;0809;0C09;1009;1409;1809;1c09;2009;2409;2809;2C09;3009;3409;4009;4409;4809"], _
        ["ES", "Spanish", "040A;0C0A"], _
        ["ESMX", "Spanish(Mexico)", "080A"], _
        ["FR", "French", "040C;080C;0C0C;100C;140C;180C"], _
        ["HU", "Hungarian", "040E"], _
        ["IT", "Italian", "0410;0810"], _
        ["JP", "Japanese", "0411"], _
        ["KR", "Korean", "0412"], _
        ["PL", "Polish", "0415"], _
        ["PR", "Portuguese", "0816"], _
        ["PRBR", "Portuguese(Brazil)", "0416"], _
        ["RU", "Russian", "0419"], _
        ["ZH", "Chinese", "0004;0404;0804;0C04;1004;1404;7C04"]]
    Local $aIniFileList = _FileListToArray(@ScriptDir & "\Common\Settings", "Data*.ini", 1, True)
    For $i = 1 To $aIniFileList[0]
        For $j = $aLanguageList[0][0] To 1 Step - 1
            If IniRead($aIniFileList[$i], "LangInclude", "Include" & $aLanguageList[$j][0], "") <> "" Then
                If StringInStr($aLanguageList[$j][2], @OSLang) Then $sLanguageDefault = $aLanguageList[$j][1] ;~ OS Default Language
                 _ArrayAdd($aLanguageSelect, $aLanguageList[$j][0] & "|" & $aLanguageList[$j][1] & "|" & $aLanguageList[$j][2])
                 ContinueLoop
            EndIf
            If IniRead($aIniFileList[$i], "LangExclude", "Exclude" & $aLanguageList[$j][0], "") <> "" Then
                If StringInStr($aLanguageList[$j][2], @OSLang) Then $sLanguageDefault = $aLanguageList[$j][1] ;~ OS Default Language
                _ArrayAdd($aLanguageSelect, $aLanguageList[$j][0] & "|" & $aLanguageList[$j][1] & "|" & $aLanguageList[$j][2])
            EndIf
        Next
    Next
    $aLanguageSelect[0][0] = UBound($aLanguageSelect) - 1
    _ArraySort($aLanguageSelect, 0, 1)
EndFunc

 

Link to post
Share on other sites
16 hours ago, Subz said:

Here is an alternative method based upon the @OSLang Macro (Used Chimps Example Gui)

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

Global $sLanguageDefault = ""
Global $aLanguageSelect[1][3]

_Example()

Func _Example()
    _GetLanguages()
    _ArrayDisplay($aLanguageSelect)
    ; -------- GUI Zone -------
    ; Create a GUI with controls.
    Local $hGUI = GUICreate("Example", 300, 200)

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

    ; Add items to the combobox.
    ; Items are Language names peeked from the column[3] of the $aData array
    GUICtrlSetData($idComboBox, _ArrayToString($aLanguageSelect, "", 1, -1, "|", 1, 1), $sLanguageDefault)

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

    Local $sComboRead = ""

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

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "You selected: " & $sComboRead, 0, $hGUI)

                $sLanguageDefault = $aLanguageSelect[_ArraySearch($aLanguageSelect, $sComboRead, 0, 0, 0, 0, 1, 1)][1]
                MsgBox($MB_SYSTEMMODAL, "", "The $Var variable has been setted" & @CRLF & "$Var contains --> " & $sLanguageDefault)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _GetLanguages()
    Local $aLanguageList[17][3] = [[16, "", ""], _ ;~ Language Count
        ["AR", "Arabic", "0401;0801;0C01;1001;1401;1801;1C01;2001;2401;2801;2C01;3001;3401;3801;3C01;4001"], _
        ["CZ", "Czech", "0405"], _
        ["DE", "German", "0407;0807;0C07;1007;1407"], _
        ["EN", "English", "0409;0809;0C09;1009;1409;1809;1c09;2009;2409;2809;2C09;3009;3409;4009;4409;4809"], _
        ["ES", "Spanish", "040A;0C0A"], _
        ["ESMX", "Spanish(Mexico)", "080A"], _
        ["FR", "French", "040C;080C;0C0C;100C;140C;180C"], _
        ["HU", "Hungarian", "040E"], _
        ["IT", "Italian", "0410;0810"], _
        ["JP", "Japanese", "0411"], _
        ["KR", "Korean", "0412"], _
        ["PL", "Polish", "0415"], _
        ["PR", "Portuguese", "0816"], _
        ["PRBR", "Portuguese(Brazil)", "0416"], _
        ["RU", "Russian", "0419"], _
        ["ZH", "Chinese", "0004;0404;0804;0C04;1004;1404;7C04"]]
    Local $aIniFileList = _FileListToArray(@ScriptDir & "\Common\Settings", "Data*.ini", 1, True)
    For $i = 1 To $aIniFileList[0]
        For $j = $aLanguageList[0][0] To 1 Step - 1
            If IniRead($aIniFileList[$i], "LangInclude", "Include" & $aLanguageList[$j][0], "") <> "" Then
                If StringInStr($aLanguageList[$j][2], @OSLang) Then $sLanguageDefault = $aLanguageList[$j][1] ;~ OS Default Language
                 _ArrayAdd($aLanguageSelect, $aLanguageList[$j][0] & "|" & $aLanguageList[$j][1] & "|" & $aLanguageList[$j][2])
                 ContinueLoop
            EndIf
            If IniRead($aIniFileList[$i], "LangExclude", "Exclude" & $aLanguageList[$j][0], "") <> "" Then
                If StringInStr($aLanguageList[$j][2], @OSLang) Then $sLanguageDefault = $aLanguageList[$j][1] ;~ OS Default Language
                _ArrayAdd($aLanguageSelect, $aLanguageList[$j][0] & "|" & $aLanguageList[$j][1] & "|" & $aLanguageList[$j][2])
            EndIf
        Next
    Next
    $aLanguageSelect[0][0] = UBound($aLanguageSelect) - 1
    _ArraySort($aLanguageSelect, 0, 1)
EndFunc

 

That seems to work really good so far, thanks.

Just one question, how can I add a check to see if the Array have 1 or 0 languages only in it, because in such a case I need to skip showing the menu?

I mean, I know it's with IF, just not sure how to check for the value of Row0 at Column0 in the array.

Sorry, I really find arrays hard to understand from some reason, hopefully I can learn something from your code.

BTW, What's all these numbers after each language in the script? Are they necessary? 

Also, I customized your example code to my needs obviously, with my own variable names and GUI, also removed the lines that defaulted the language to OS Language as I don't need that, the selection is to defined files for compression by language.

 

EDIT: Nevermind, figured out how to check for Row0 in Column 0 of the array so I got the menu to show correctly only if more than 1 Language available.

Still would like to know about those numbers though.

Edited by VollachR
Updated post

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

The numbers are actually OS Language Codes (see https://www.autoitscript.com/autoit3/docs/appendix/OSLangCodes.htm), but since you don't need them you can remove them.

With regards to Arrays you can use Ubound for this couple of examples:
One Dimensional Arrays
nb: Arrays are 0 Index based

Local $OneDimension[2]
$OneDimension[0] = "Row One - One Column"
$OneDimension[1] = "Row Two - One Column"

Using the example above you can use Ubound($OneDimension) to get the total number of rows, in this example 2

ConsoleWrite("Total Number of Rows: " & Ubound($OneDimension) & @CRLF)

If you were going to use this within a For Loop you could use something like Ubound($OneDimension) - 1 to get the last row index

For $i = 0 To Ubound($OneDimension) - 1
  ConsoleWrite("Row " & $i & " = " & $OneDimension[$i] & @CRLF)
Next

Two Dimensional Arrays
nb: Arrays are 0 Index based

Local $TwoDimension[2][2]
$TwoDimension[0][0] = "Row One - Column One"
$TwoDimension[0][1] = "Row One - Column Two"
$TwoDimension[1][0] = "Row Two Column One"
$TwoDimension[1][1] = "Row Two Column Two"

Using the example above you can use Ubound($OneDimension) to get the total number of rows, in this example 2
Using the example above you can use Ubound($OneDimension, 2) to get the total number of columns, in this example 2

ConsoleWrite("Total Number of Rows: " & Ubound($TwoDimension) & @CRLF)
ConsoleWrite("Total Number of Columns: " & Ubound($TwoDimension, 2) & @CRLF)

If you were going to use this within a For Loop you could use something like Ubound($OneDimension) - 1 to get the last row index
If you were going to use this within a For Loop you could use something like Ubound($OneDimension, 2) - 1 to get the last column index

For $i = 0 To Ubound($TwoDimension) - 1
    For $j = 0 To UBound($TwoDimension, 2) - 1
        ConsoleWrite("Row " & $i & ": " & "Column " & $j & " = " & $TwoDimension[$i][$j] & @CRLF)
    Next
Next

Anyway I hope that makes sense, really its just remembering that Arrays are 0 based so as you will notice with the last example it will read:

Row 0: Column 0 = Row One - Column One
Row 0: Column 1 = Row One - Column Two
Row 1: Column 0 = Row Two Column One
Row 1: Column 1 = Row Two Column Two

 

Link to post
Share on other sites
16 minutes ago, Subz said:

The numbers are actually OS Language Codes (see https://www.autoitscript.com/autoit3/docs/appendix/OSLangCodes.htm), but since you don't need them you can remove them.

With regards to Arrays you can use Ubound for this couple of examples:
One Dimensional Arrays
nb: Arrays are 0 Index based

Local $OneDimension[2]
$OneDimension[0] = "Row One - One Column"
$OneDimension[1] = "Row Two - One Column"

Using the example above you can use Ubound($OneDimension) to get the total number of rows, in this example 2

ConsoleWrite("Total Number of Rows: " & Ubound($OneDimension) & @CRLF)

If you were going to use this within a For Loop you could use something like Ubound($OneDimension) - 1 to get the last row index

For $i = 0 To Ubound($OneDimension) - 1
  ConsoleWrite("Row " & $i & " = " & $OneDimension[$i] & @CRLF)
Next

Two Dimensional Arrays
nb: Arrays are 0 Index based

Local $TwoDimension[2][2]
$TwoDimension[0][0] = "Row One - Column One"
$TwoDimension[0][1] = "Row One - Column Two"
$TwoDimension[1][0] = "Row Two Column One"
$TwoDimension[1][1] = "Row Two Column Two"

Using the example above you can use Ubound($OneDimension) to get the total number of rows, in this example 2
Using the example above you can use Ubound($OneDimension, 2) to get the total number of columns, in this example 2

ConsoleWrite("Total Number of Rows: " & Ubound($TwoDimension) & @CRLF)
ConsoleWrite("Total Number of Columns: " & Ubound($TwoDimension, 2) & @CRLF)

If you were going to use this within a For Loop you could use something like Ubound($OneDimension) - 1 to get the last row index
If you were going to use this within a For Loop you could use something like Ubound($OneDimension, 2) - 1 to get the last column index

For $i = 0 To Ubound($TwoDimension) - 1
    For $j = 0 To UBound($TwoDimension, 2) - 1
        ConsoleWrite("Row " & $i & ": " & "Column " & $j & " = " & $TwoDimension[$i][$j] & @CRLF)
    Next
Next

Anyway I hope that makes sense, really its just remembering that Arrays are 0 based so as you will notice with the last example it will read:

Row 0: Column 0 = Row One - Column One
Row 0: Column 1 = Row One - Column Two
Row 1: Column 0 = Row Two Column One
Row 1: Column 1 = Row Two Column Two

 

OK, So I removed those OS Lang Codes and everything still works as intended.

As for the above Arrays explanation, Thank you very much, I'll save it for future reference, Hopefully it will help me understand & use Arrays better, Time will tell.

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Hermes
      Hi, I am struggling in setting the value of a textarea based on the value of clipboard (that contains a long web page source codes). If I use _WD_SetElementValue, it freezes after some time, or appears to be pressing tab and goes out of focus. I can also use send keys but i need the script to run in the background.
      Here is the full script:
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "http://demo.borland.com/testsite/stadyn_largepagewithimages.html") _WD_LoadWait($sSession) Global $sSource = _WD_GetSource($sSession) Local $Paste = ClipPut($sSource) Local $sData = ClipGet() Local $aArray = 0, _ $iOffset = 1 While 1 $aArray = StringRegExp($sData, '(?s)<p>.*</p>', $STR_REGEXPARRAYMATCH, $iOffset) If @error Then ExitLoop $iOffset = @extended For $i = 0 To UBound($aArray) - 1 Local $Paste = ClipPut($aArray[$i]) Local $sRegExData = ClipGet() ;MsgBox(0, "", "$sRegExData = " & $sRegExData) Next WEnd _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_textarea_placeholder") _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") _WD_FrameEnter($sSession, $sElement1) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") $textarea = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") _WD_ElementAction($sSession, $textarea, 'click') ;WD SetElementValue(SsSession, Stextarea, $sRegExData) <-- I can do this but the focus goes out, or the browser freezes _WD_FrameLeave($sSession) sleep(2000) Send("^v") _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Can someone help me please, or re-direct me to the right path? TIA!
    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
×
×
  • Create New...