Jump to content
VollachR

Check certain values according to another value in the same array?

Recommended Posts

Hi,

I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.

For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.

I thought on using a FOR loop but I have very little experience with those.

Can you suggest the best way to do what I need?

BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.

Full Example:

Row2 of Array:

Col0 = Games# - Col1 = 5

Rows3-6

Col0 = Exe2 - Col1 = Path To File

Col0 = Exe3 - Col1 = Path To File

Col0 = Exe4 - Col1 = Path To File

Col0 = Exe5 - Col1 = Path To File

I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.

So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.

I'm pretty sure I have the first line of the for look correct:

For $i = 1 To $aAIO[2][1]

Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.

Help will be appreciated.


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

Share this post


Link to post
Share on other sites
1 minute ago, Subz said:

Is this for game automation?  Can't help if it is.

No, it's a compression script that let you compress games to smaller size, it's a feature that verify the correct folder is selected by one or more executable checks


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

Share this post


Link to post
Share on other sites

OK, played around with it, the following seems to work, can somebody let me know if this code appears to be correct?

For $i = 3 To $aAIO[2][1] + 1               
                If Not FileExists($SourceDir & "\" & $aAIO[$i][1]) Then
                    AIOExeError()
                EndIf
            Next

The file paths in the array are relative to the Source folder in the $SourceDir variable


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

Share this post


Link to post
Share on other sites

Does your array look like:

#include <Array.au3>
Global $sSourceDir = "C:\"
Global $aPaths[7][2] = [["Paths#", 5], ["Path1.exe", "Path1"], ["Path2.exe", "Path2"], ["Path3.exe", "Path3"], ["Path4.exe", "Path4"], ["Path5.exe", "Path5"], ["Path6.exe", "Path6"]]
;~ The following will loop from Row 2 to the Last item in the Array
For $i = 2 To UBound($aPaths) - 1
    ;~ Check $sSourceDir & Row x Column1
    ;~ nb: If you don't have a backslash on $sSourceDir you will need to add it.
    If FileExists($sSourceDir & $aPaths[$i][1]) = 0 Then AIOExeError()
Next
_ArrayDisplay($aPaths)

 

Edited by Subz

Share this post


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

Does your array look like:

#include <Array.au3>
Global $sSourceDir = "C:\"
Global $aPaths[7][2] = [["Paths#", 5], ["Path1.exe", "Path1"], ["Path2.exe", "Path2"], ["Path3.exe", "Path3"], ["Path4.exe", "Path4"], ["Path5.exe", "Path5"], ["Path6.exe", "Path6"]]
;~ The following will loop from Row 2 to the Last item in the Array
For $i = 2 To UBound($aPaths) - 1
    ;~ Check $sSourceDir & Row x Column1
    ;~ nb: If you don't have a backslash on $sSourceDir you will need to add it.
    If FileExists($sSourceDir & $aPaths[$i][1]) = 0 Then AIOExeError()
Next
_ArrayDisplay($aPaths)

 

My array is created using IniReadSection So I guess so, something similar

Anyway, I think my little for loop I posted works but I'm having a problem stopping the loop before the last check if a file not exists and setting an error state.

There's a GUI with a START button that when clicked gets disabled and start these checks that if files exists continue to next part but I need a way to stop it without closing the GUI while re-enabling the Start button.

And I don't need to loop to last item in the array as some values may be empty in column 1, only till one row more than the number in Row2

 

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

You just use ExitLoop, I'm just trying to understand the logic when to exit the loop, I'm assuming something like:

#include <Array.au3>
Global $sSourceDir = "C:\"
Global $aAIO = IniReadSection(@ScriptDir & "\AIO.ini", "AIO")
    If @error Then Exit MsgBox(4096, "Error", "File not found.")
;~ The following will loop from Row 3 to the Last item in the Array
For $i = 3 To UBound($aAIO) - 1
    ;~ Check $sSourceDir & Column1
    ;~ nb: If you don't have a backslash on $sSourceDir you will need to add it.
;~  If FileExists($sSourceDir & $aAIO[$i][1]) = 0 Then AIOExeError()
    ;~ Check if Row x Column 0 equals EXE Row 2 Column 1 example EXE4 Then Exit Loop
    If $aAIO[$i][0] = "EXE" & $aAIO[2][1] Then ExitLoop MsgBox(4096, "Exit", "Exiting on Row: " & $i)
Next
_ArrayDisplay($aAIO)

 

Share this post


Link to post
Share on other sites

OK, I think I solved it, this is the full function script:

 

Func CheckExe()
    If $aAIO[1][1] = 0 Then
        If Not FileExists($SourceDir & "\" & $aConversion[12][1]) Then
            $ErrorState = SetError(1)
            MsgBox($MB_ICONERROR, "Exe Not Found!", "The " & $aConversion[9][1] & " Executable Could Not Be Found In The Following Location:" & @CRLF & @CRLF & $SourceDir & "\" & $aConversion[12][1] & _
                    @CRLF & @CRLF & "Please Verify The Location is Correct, Once The Problem is Fixed You Can Try the Conversion Again.")
            If $ErrorState = 1 Then GUICtrlSetState($Start, $GUI_ENABLE)
        EndIf
    EndIf
    If $aAIO[1][1] = 1 Then
        If Not FileExists($SourceDir & "\" & $aConversion[12][1]) Then
            $ErrorState = SetError(1)
            AIOExeError()
            If $ErrorState = 1 Then GUICtrlSetState($Start, $GUI_ENABLE)
        Else
            For $i = 3 To $aAIO[2][1] + 1
                If Not FileExists($SourceDir & "\" & $aAIO[$i][1]) Then
                    $ErrorState = SetError(1)
                    AIOExeError()
                    If $ErrorState = 1 Then GUICtrlSetState($Start, $GUI_ENABLE)
                    ExitLoop
                EndIf
            Next
        EndIf
    EndIf
EndFunc   ;==>CheckExe

Func AIOExeError()
    MsgBox($MB_ICONERROR, "Exe(s) Not Found!", "One or More of The " & $aConversion[9][1] & " Executable Files Could Not Be Found In The Selected Source Folder" & @CRLF & @CRLF & _
            "Please Verify It is Correct, Once The Problem is Fixed You Can Try the Conversion Again.")
EndFunc   ;==>AIOExeError

If I did everything right it it should check column 1 of the array from row 3 to row number +1 than the value in Row 2 (so if row 2 value is 5 it will check up to row6) and if any of the files don't exist it should display the error, re-enable the start button and exit the loop, essentially stopping the script before the start button can call the next function without exiting it altogether.

Not sure if the SetError lines are really needed though.

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

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

    • By adjist
      Hello all! 
       
      Getting this error :
      (22) : ==> Variable used without being declared.: if $vNumber = 0 Then if ^ ERROR  
      But I'm sure I have defined the variable, as in the top of my script has 
      Global $vNumber = 0  
      How would I go about fixing this?
       
    • By D2thunder
      Hi all, I wasnt active in this Forum forum for Years. 😅
      Since I need something with Json in AutoIt i write a little UDF to save a variable to file to read it with another language - and back. After a while until my other script grows i thought - lets integrate all variables wich is possible, because i want have arrays to.
      This is my first public UDF in Autoit - normaly my AutoIt scripts are quick an dirty.... - like the examples for this udf. - someone want to write nice examples?
      I tried to write this UDF properly, cared for processing speed, low mem consumption as possible, a short code, and a high usability without beeing very familiar with arrays.
      What is it for? - convert nearly all types of variables to a json string for saving it in a file or to an ini. Read it back in to a same formated variable and preserv variable types. All array types are supported with nested arrays, the only restriction is ram and array/stringsize - and time if the array is very big. You can use Filters for variable types and some other options.
      If anyone found a bug or any suggestions, please post it.
       
      get Json.au3 from here Json.au3
       
       
      JsonVar 2019.01.25.1.zip
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.19 contains 194 functions divided into these topics:
      window and screen mouse and GUI GUI controls logics and mathematics string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By Ho3ein
      Hi, i have a source code of "Danny35d" and i have 2 main question that are:
       How to extract this function's results (Datas are as Array) to combo-box without set number of datas?  When i type 1, 2 in _SystemUsers($AccountType = 0) to get only Local or Domain users, it just give me both of them, it's old problem of this function, please share us debugged code :)❤ #include <Array.au3> $Users = _ArrayToString(_SystemUsers(), "|", 1) ConsoleWrite($Users & @CRLF) #cs =============================================================================== Function: _SystemUsers($AccountType = 0) Description: Return an array with the local or domain username Parameter(s): $AccountType: Local, domain or both username 0 = Local and Domain usernames 1 = Local usernames only 2 = Domain usernames only Returns: An array with the list of usernames - Succeeded @error 1 - Didn't query any username @error 2 - Failed to create Win32_SystemUsers object @error 3 - Invalid $AccountType Author(s): Danny35d #ce =============================================================================== Func _SystemUsers($AccountType = 0) Local $aSystemUsers Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20 Local $colItems = "", $strComputer = "localhost" If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '') $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $Output = StringSplit($objItem.PartComponent, ',') If IsArray($Output) Then $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '') If $AccountType = 0 Or ($AccountType = 1 And @ComputerName = $Temp) Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' ElseIf $AccountType = 2 And @ComputerName <> $Temp Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' EndIf EndIf Next $aSystemUsers = StringTrimRight($aSystemUsers, 1) If $aSystemUsers = '' Then Return(SetError(1, 1, $aSystemUsers)) Return(SetError(0, 0, StringSplit($aSystemUsers, '|'))) Else $aSystemUsers = '' Return(SetError(2, 2, $aSystemUsers)) EndIf EndFunc ;==>_SystemUsers Thanks to your best Team.
    • By topgundcp
      Hi, 
      This is my very first post in this forum and am also new with Autoit programming so be easy on me.
      Below is the code that I am trying to get the index of the item selected. No problem getting the text.
      Case $listEdition   ; handle of the list             local $index=0             $item=GUICTRLRead($listEdition)    ; This will return the text in the list             ; ==============   The loop below always fails  ==================             ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ???????              For $i = 0 To $editionArray[0] - 1   ; The content of the list in an array where editionArray[0] contains total count of items                 If _GUICtrlListView_GetItemSelected($listEdition, $i) Then                     $index = $i                     exitloop                 EndIf              Next              ;===================================================             ConsoleWrite( "Select Edition:     " & $item & "  index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached.
      _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE.
      Another problem is on the list. It also populate  the total count of items from the Array. How can I skip this item from populating to the list ?.
      Please advise and thanks

×
×
  • Create New...