Jump to content
VollachR

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

Recommended Posts

VollachR

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

Share this post


Link to post
Share on other sites
VollachR

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

Share this post


Link to post
Share on other sites
Skeletor

@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"

Share this post


Link to post
Share on other sites
VollachR
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

Share this post


Link to post
Share on other sites
Skeletor

@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"

Share this post


Link to post
Share on other sites
Subz

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

 

Share this post


Link to post
Share on other sites
Chimp

... 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....

Share this post


Link to post
Share on other sites
VollachR
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

Share this post


Link to post
Share on other sites
Subz

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)

Share this post


Link to post
Share on other sites
VollachR
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

Share this post


Link to post
Share on other sites
Subz

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

 

  • Thanks 1

Share this post


Link to post
Share on other sites
VollachR
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

Share this post


Link to post
Share on other sites
Subz

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

 

  • Thanks 1

Share this post


Link to post
Share on other sites
VollachR
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

Share this post


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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • VollachR
      By VollachR
      Hi,
      I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.
      I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.
      What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.
      It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.
      Here are the relevant part of my script:
      The Custom Verification Arrays:
      ;Creating Arrays for INI Verification Global $aSettingsVerify[7] $aSettingsVerify[1] = "Conversion" $aSettingsVerify[2] = "AIO" $aSettingsVerify[3] = "Data" $aSettingsVerify[4] = "Redist" $aSettingsVerify[5] = "Split" $aSettingsVerify[6] = "Autorun" Global $aDataVerify[6] $aDataVerify[1] = "Compression" $aDataVerify[2] = "Exclude" $aDataVerify[3] = "LangExclude" $aDataVerify[4] = "PreCommands" $aDataVerify[5] = "PostCommands" The IniReadSectionNames verification part:
      Case $OK If StringInStr($ActiveConfig, "Settings.ini") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) SettingsGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf If StringInStr($ActiveConfig, "Data") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) DataGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)
      ;Compares Imported INI file with the Verification array Func _ArrayCompare(ByRef $a1, ByRef $a2) Local $nOldSize = UBound($a2) Local $a3[$nOldSize], $nNewSize = $nOldSize For $i = 0 To UBound($a1) - 1 For $j = 0 To $nOldSize - 1 If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then $a3[$j] = 1 $nNewSize -= 1 EndIf Next Next Local $a4[$nNewSize], $j = 0 For $i = 0 To $nOldSize - 1 If Not $a3[$i] Then $a4[$j] = $a2[$i] $j += 1 EndIf Next Return $a4 EndFunc ;==>_ArrayCompare  
      Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?
      Thanks
×