Jump to content
VollachR

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

Recommended Posts

VollachR
Posted (edited)

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
Posted (edited)

@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) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
VollachR
Posted (edited)
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"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

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
Posted (edited)
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

    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • iMacg3
      By iMacg3
      Hi,
      I was looking into a way to delete a registry key (not a specific value, an entire key) if it is present. I was considering using RegRead and RegDelete. However, RegRead appears to only read values, not just keys. Is there a way to delete an entire registry key if it is present? I have heard that the below function may help.
       
      #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","REG_SZ","REG_EXPAND_SZ","REG_BINARY","REG_DWORD","REG_DWORD_BIG_ENDIAN","REG_LINK","REG_MULTI_SZ","REG_RESOURCE_LIST","REG_FULL_RESOURCE_DESCRIPTOR","REG_RESOURCE_REQUIREMENTS_LIST","REG_QWORD"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFunc Thanks.
       
    • great77
      By great77
      ; put the root in a variable $sRoot = "C:\Project\PHexample\" Global $sCurrentTime = _NowCalc() ; We can use that variable here Global $aList = _FileListToArray($sRoot, Default, 2) If @error Then Exit ;;;;;;MsgBox(0, "Error", "_FileListToArray returned @error = " & @error) ;;;;;;;;;;;This is a loop that runs from 1 to the number of items listed in the first element of the returned  array For $i = 1 To UBound($aList) - 1     MsgBox(0, "Folder date", $sRoot & "" & $aList[$i] & @CRLF & @CRLF & FileGetTime($sRoot & "" & $aList[$i], 1, 1))     MsgBox(0, "Folder date", FileGetTime($sRoot & "" & $aList[$i], 1, 1))      $a_filenew = StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), ":", ""), " ", "")       MsgBox(0, "Folder date", $a_filenew) $adex =  _DateDiff('D', FileGetTime($sRoot & "" & $aList[$i], 1, 1), $a_filenew)  MsgBox(0,"ade", $adex) Next I have a code as seen above, but the difference in time is returning zero. I understand that the date yyyymmddhhmmss but how can I find the difference.
      The purpose is to try find the difference in days. Any suggestion?  
×