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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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 JohnnyTries
      Hi Fellow Automators,
      Long time listener, first time caller. I've resisted posting on the forums as long as possible for fear of public lynching, but I'm stuck and could really use some help.
      Note: If this is the wrong side of the forum for this topic, I apologize.
      I've built a GUI and script to make our lab data collection easier. The app has a number of input boxes and a 'record' button. The user fills out the input boxes with various notes and then presses 'record', which in turn presses 'record' on two other, separate apps simultaneously, pulls those recordings together into one folder, and then takes the text from the input boxes and adds it in a new row at the bottom of an existing .xlsx spreadsheet. Everything works great, except that every time I open the app to start collecting data for the day, the 'headers' for the $aArray are added to a new row and then the text is added below it. Now, if I don't close the app between collections, subsequent 'recordings' are added to the spreadsheet as expected. If I close the app and open it, the 'first' recording of the day adds the headers to a new row. I don't need new 'header' info because I've already got that in row 1 of the spreadsheet.
      If someone could tell me where I'm !#$%ing up, I would greatly appreciate it. 
       
      #RequireAdmin #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Process.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <DirConstants.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <File.au3> #include <WinAPIShPath.au3> #include <Excel.au3> ;Declaring the $aArray and location of the speadsheet at the top of the script Local $aArray[1][9] = [["TestID","DateTimeStamp","Tamb_C","BGTemp_C", "GasType", "TrueFlow_slm", "Lens-BGDist_in", "Lens-LeakDist_In", "AddNotes"]] Local $sDataFilePath = @ScriptDir & "\Notes\DualCaptureNotes.xlsx" Func CaptureVideo() Global $TestID = GuiCtrlRead($TestIDInput) Global $timestamp = @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC Global $Cam1Dir = "C:\Archive" Global $Cam2Dir = "C:\ALD" ;Capture Cam1 Data WinActivate("Cam1 App") ControlFocus("Cam1 App", "Save",'WindowsForms10.Window.8.app.0.2099316_r7_ad114') ControlSend("Cam1 App", "Save", 'WindowsForms10.Window.8.app.0.2099316_r7_ad114', "{SPACE}") ;Capture Cam2 Data WinActivate("Cam2 App") ControlClick("Cam2 App", "", 'WindowsForms10.Window.8.app.0.1b0ed41_r7_ad122', '', 1, 10, 10) ;Wait to ensure data files have been fully written to their default locations Sleep(2000) ;Self-explanatorily named functions MoveData() RecordNotesToArray() RecordArraytoExcel() WinActivate("DualCapture") EndFunc ;==>CaptureVideo ;Skipping ahead to the .xlsx part.... Func RecordNotesToArray() _ArrayAdd($aArray, GUICtrlRead($TestIDInput) & "|" & $timestamp & "|" & GUICtrlRead($Tamb_CInput) & "|" & GUICtrlRead($BGTemp_CInput) & "|" & GUICtrlRead($GasTypeInput) & "|" & GUICtrlRead($TrueFlow_slmInput) & "|" & GUICtrlRead($Dist_BG_inInput) & "|" & GUICtrlRead($Dist_Leak_inInput) & "|" & GUICtrlRead($AddNotesInput)) EndFunc ;==>RecordNotesToArray() Func RecordArraytoExcel() Local $oExcel = _Excel_Open() Local $oWorkBook If Not FileExists($sDataFilePath) Then $oWorkBook = _Excel_BookNew($oExcel) Else $oWorkBook = _Excel_BookOpen($oExcel, $sDataFilePath) EndIf $oWorkBook.Worksheets("DataTable").Columns("A:I").AutoFit $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row $Rowrange = "A"&$LastRow+1 Consolewrite($Rowrange & @crlf) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray, $Rowrange) If FileExists($sDataFilePath) Then _Excel_BookSave($oWorkBook) Else _Excel_BookSaveAs($oWorkBook, $sDataFilePath) EndIf _Excel_BookClose($oWorkBook) _Excel_Close($oExcel) EndFunc ;==>RecordArrayToExcel() I appreciate your time and any help you can provide.
       
      Best,
      Johnny
       
    • By LeeSG
      (If translated with a translator, it may be written a little awkwardly. I would be grateful if you could understand my situation)
      As mentioned in the title, the icon file, which was applied well when compiled with exe, does not apply when compiled with a3x, and is displayed as the default autoit icon.
       
      #AutoIt3Wrapper_Icon=icon.ico
       
      I specified the icon file at the top, but why can't it be applied? Is there any way to compile with a3x including icons?
    • By sg08234
      Members 0   2 10 posts   Posted 1 minute ago I have a littel script:
      AutoItSetOption("MustDeclareVars", 1) #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $iReturn  ; Returnwert Local $iVar     ; Variable Local $iBit     ; Bitnummer $iVar=$Cmdline[2] $iBit=$Cmdline[3] Switch $Cmdline[1]     Case 1         $iReturn=BitOr ($ivar,2^$iBit)     Case 2         $iReturn=BitAnd ($iVar,2^$iBit)         if ($iReturn = 2^$iBit ) Then             $iReturn=0         Else             $iReturn=1         EndIf EndSwitch Exit $iReturn which does bit handling. It works as desired but: If I want to check the Returncode of the EXE created in the calling batch within an if-clause %ERRORLEVEL% does not match the Returncode  of my script (calling outside of an if-clause works as desired).
      My assumption for this behaviour is: I do not use  enabledelayedexpansion  in my batch-system and thus this special "variable" %ERRORLEVEL% is not defined in the if-clause. If my assumption is correct: How can I retransfer the Returncode to batch?
      Thanks - Michael
    • By HoangDung
      This is the function that returns the result from cmd, initially i connect to the network wait then i make a call to the above _GetDOSOutput($sCommand) function i want to wait 1 period of time netsh wlan connect name="name" actually but after starting to execute the netsh wlan show interfaces command i tried adding a timeout command it seems to have ignored the timeout command?
      #include <WindowsConstants.au3> #include <Constants.au3> Func _GetDOSOutput($sCommand) Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = '' Local $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $sOutput &= StdoutRead($iPID, False, False) If @error Then ExitLoop EndIf Sleep(10) WEnd Return $sOutput EndFunc Local $sCommand= 'netsh wlan delete profile name="wait" & netsh wlan connect name="name" interface="Wi-fi" & netsh wlan show interfaces' MsgBox(0,0,_GetDOSOutput($sCommand))  
    • By D3fr0s7
      I'm trying to make one tray item delete another, but when I do this, all tray items that were created after the deleted item don't work as intended, as if their controlID's were all shifted down one value, and their corresponding tray items now (after deletion) run the code of the tray item before it. Am I missing something? Is there a better way to accomplish what I'm trying to do?
      #include <TrayConstants.au3> #include <Array.au3> HotKeySet ( "{ESC}", "Abort" ) Opt ( "TrayMenuMode", 3 ) TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. Global $aTray[8] ; Defines array to hold tray items. $aTray[0] = TrayCreateItem ( "Test 1 (Name Test 5)" ) $aTray[1] = TrayCreateItem ( "Test 2 (Delete Test 5)" ) $aTray[2] = TrayCreateItem ( "Test 3 (Restore Test 5)" ) $aTray[3] = TrayCreateItem ( "Test 4 (Check if Test 5 is blank or space)" ) $aTray[4] = TrayCreateItem ( "Test 5 Delete Me" ) $aTray[5] = TrayCreateItem ( "Test 6 (Check Test 5 Text)" ) $aTray[6] = TrayCreateItem ( "Test 7 (Read Values)" ) $aTray[7] = TrayCreateItem ( "Test 8 (Count Blanks)" ) While 1 Switch TrayGetMsg() Case $aTray[0] ; "Test 1" Change Test 5 Text. If TrayItemGetText ( $aTray[0] ) <> "" Then Global $TrayText = InputBox ( "Test", "Choose text for Test 5", "Test 5 Delete Me" ) TrayItemSetText ( $aTray[4], $TrayText) EndIf Case $aTray[1] ; "Test 2" Deletes "Test 5". If TrayItemGetText ( $aTray[1] ) <> "" Then Global $TrayDeletedName = TrayItemGetText ( $aTray[4] ) TrayItemDelete ( $aTray[4] ) _ArrayInsert ( $aTray, 4 ) EndIf Case $aTray[2] ; "Test 3" Restores "Test 5". If TrayItemGetText ( $aTray[2] ) <> "" Then $aTray[4] = TrayCreateItem ( $TrayDeletedName ) EndIf Case $aTray[3] ; "Test 4" Check if Test 5 value is blank, space, or filled. If TrayItemGetText ( $aTray[3] ) <> "" Then If TrayItemGetText ( $aTray[4] ) = "" Then MsgBox ( 0, "Test", "Test 5 is blank" ) ElseIf TrayItemGetText ( $aTray[4] ) = " " Then MsgBox ( 0, "Test", "Test 5 is not blank (space)" ) Else MsgBox ( 0, "Test", "Test 5 is assigned a value" ) EndIf EndIf Case $aTray[4] ; "Test 5" (Item to test for, during, and after deletion). If TrayItemGetText ( $aTray[4] ) <> "" Then MsgBox ( 0, "Test", "I'm here!" ) EndIf Case $aTray[5] ; "Test 6" Displays Text from Test 5 item. If TrayItemGetText ( $aTray[5] ) <> "" Then $Test5Text = TrayItemGetText ( $aTray[4] ) MsgBox ( 0, "Test", "Test 5 Text: " & $Test5Text ) EndIf Case $aTray[6] ; "Test 7" Displays all item values. If TrayItemGetText ( $aTray[6] ) <> "" Then MsgBox ( 0, "Test", "$aTray[0]: " & $aTray[0] & @CRLF & _ "$aTray[1]: " & $aTray[1] & @CRLF & _ "$aTray[2]: " & $aTray[2] & @CRLF & _ "$aTray[3]: " & $aTray[3] & @CRLF & _ "$aTray[4]: " & $aTray[4] & @CRLF & _ "$aTray[5]: " & $aTray[5] & @CRLF & _ "$aTray[6]: " & $aTray[6] & @CRLF & _ "$aTray[7]: " & $aTray[7] & @CRLF ) EndIf Case $aTray[7] ; "Test 8" Counts all blanks in tray values. If TrayItemGetText ( $aTray[7] ) <> "" Then Global $blankCount = _ArrayFindAll ( $aTray, "" ) If $blankCount = -1 Then If @error = 6 Then MsgBox ( 0, "Test", "Error, No blanks present") EndIf Else MsgBox ( 0, "Test", "# of blanks: " & $blankCount ) EndIf EndIf EndSwitch WEnd Func Abort() Exit EndFunc Here is a test script I created to try to troubleshoot the problem on my own, with no luck. pay specific attention to "Test 2" ($aTray[1]), "Test 5" ($aTray[4]), and how every tray item after "Test 5" ($aTray[4]) behaves after deletion. Clicking "Test 2" will delete tray item "Test 5", after deletion every item runs the code of the tray item that was established before it (ex. "Test 3" and "Test 4" run their respective code, "Test 5" no longer exists, "Test 6" runs "Test 7", "Test 7" runs "Test 8"), and the last item ("Test 8" $aTray[7]) has no effect when the tray item is clicked. 

      I understand that deleting the tray item changes the controlID, but I don't know in what way it does, and therefore how I can fix it to be able to achieve what I want it to. I appreciate any help or guidance with this problem.

      To clarify, what I'm ultimately trying to do is create a 'while' loop with switch case functions that can exist without necessarily being linked to a tray item, so that I can add and delete them at liberty using the script's functions, without having to differentiate switch case functions with if functions (if $aTray[x] exists, then use this set of switch case functions, etc.). 

      Please, I am in pain. Water come school me again pls
×
×
  • Create New...