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

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • milkmoron
      By milkmoron
      https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 At least we have an element title: [Entered By:] class: [WindowsForms10.EDIT.app.0.30495d1_r9_ad1] Having the following values for all properties: Title is: <Entered By:> Class := <WindowsForms10.EDIT.app.0.30495d1_r9_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354) 322;370;736;184 *** Parent Information top down *** 3: Title is: <View Activity> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 306;72;784;605 "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 2: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;768;542 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 1: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;749;451 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 0: Title is: <Delete> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;122;749;432 "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;View Activity _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP4","Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;Delete _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_action("EnteredBy:.mainwindow","setfocus") ;~ *** Standard code Flexible*** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") _UIA_action("EnteredBy:.mainwindow","setfocus") Need some help selecting this defining it as a variable to save and then insert the text within, to the same application but different account.
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
×