Jump to content
VollachR

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

Recommended Posts

VollachR

Hi,

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

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

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

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

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

Full Example:

Row2 of Array:

Col0 = Games# - Col1 = 5

Rows3-6

Col0 = Exe2 - Col1 = Path To File

Col0 = Exe3 - Col1 = Path To File

Col0 = Exe4 - Col1 = Path To File

Col0 = Exe5 - Col1 = Path To File

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

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

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

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

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

Help will be appreciated.


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

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

Share this post


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

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

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

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

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

    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
    • HardXOR
      By HardXOR
      Hello AutoIt community
      I run into speed problem in my script wich i cant solve myself, problem is with decoding texture loop - for better explanation, you need extract from file pallete (16x 16 RGB color) and picture data (224 * 128 byte), then use correct color for your picture data.... nothing extra hard and also texture is quite small 224*256
      it is for my car model viewer/later maybe editor GranTurismo 2 from Playstation 1, so its old dataformat and i cant understand why AutoIt take so long to decode texture when good old Playstation almost 2,5 decades old can do that nearly immediately (when you list through cars in shop or garage)
      My first atempt was create all trought dllstructure, because its easier approach, but it was soooo slow (40-50s for create textures) then i upgrade my routine via arrays, first 3D arrays later only 1D, next i put decoding colors outside loop but it is still not enough, my last version took cca 15s wich is still unacceptable for car model viewer when you click on one carmodel from listview (1100 cars for whole game) and you must wait 15-16s for model to load....  oh and i forgot mention some cars have more then 1 color (much more... 8-9-10 etc) soloading take 8-9-10 times more time
      in attachment i post texture file from GranTurismo 2 for one car (contain only 1 color) and also my dll struct version and array version code
      dll struct version - ± 40 sec (33 without saving)
      #include <FileConstants.au3> Global $IMDT[256][256][4] LoadTexture("ufs9r.cdp") Func LoadTexture($file) $fileHandle = FileOpen($file, $FO_BINARY) $header = FileRead($fileHandle, 0x20) ConsoleWrite("header> " & $header & @CRLF) $PAL = FileRead($fileHandle, 0x200) ConsoleWrite("PAL> " & $PAL & @CRLF) FileSetPos($fileHandle, 0x43A0, $FILE_BEGIN) $IMD = FileRead($fileHandle, 0x7000) ConsoleWrite("IMD> " & $IMD & @CRLF) $st = DllStructCreate("BYTE[512]") DllStructSetData($st, 1, $PAL) $struct_PAL = DllStructCreate("WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16];WORD[16]", DllStructGetPtr($st)) $struct_IMD = DllStructCreate("BYTE[" & 0x7000 & "]") DllStructSetData($struct_IMD, 1, $IMD) $start = TimerInit() For $i = 0 To 15 For $j = 0 To 223 $cn = 0 For $k = 0 To 127 $bt = DllStructGetData($struct_IMD, 1, $j * 128 + $k + 1) $blue = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), 7) $IMDT[$j][$cn][0] = $blue $green = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), 2) $IMDT[$j][$cn][1] = $green $red = BitShift(DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1), - 3) $IMDT[$j][$cn][2] = $red If DllStructGetData($struct_PAL, $i + 1, BitAND($bt, 0x0F) + 1) = 0 Then $IMDT[$j][$cn][3] = 0x00 Else $IMDT[$j][$cn][3] = 0xFF EndIf $cn += 1 $blue = BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), 7) $IMDT[$j][$cn][0] = $blue $green = BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), 2) $IMDT[$j][$cn][1] = $green $red = BitAND(BitShift(DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1), - 3), 0xFF) $IMDT[$j][$cn][2] = $red If DllStructGetData($struct_PAL, $i + 1, BitShift($bt, 4) + 1) = 0 Then $IMDT[$j][$cn][3] = 0x00 Else $IMDT[$j][$cn][3] = 0xFF EndIf $cn += 1 Next Next saveTGA($i) Next ConsoleWrite("t " & TimerDiff($start) & @CRLF) ; +- 40 seconds FileClose($fileHandle) EndFunc Func saveTGA($name) Local $tga[18] = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x20, 0x20] Local $data for $i = 0 To 17 $data &= Hex($tga[$i], 2) Next For $i = 0 To 255 For $j = 0 To 255 For $k = 0 To 3 $data &= hex($IMDT[$i][$j][$k], 2) Next Next Next $binary = FileOpen("test\" & $name & ".tga", BitOR($FO_BINARY, $FO_OVERWRITE, $FO_CREATEPATH)) FileWrite($binary, "0x" & $data) FileClose($binary) EndFunc  
      array version - ± 15 sec (under 10s without saving)
      #include <FileConstants.au3> LoadTexture2("ufs9r.cdp") Func LoadTexture2($file) $fileHandle = FileOpen($file, $FO_BINARY) $a = TimerInit() Global $header[0x20] For $i = 0 To UBound($header) - 1 $header[$i] = Int(String(FileRead($fileHandle, 1))) ; read 0x20 bytes Next ConsoleWrite("header " & TimerDiff($a) & @CRLF) $a = TimerInit() Global $PAL[0x100] For $i = 0 To UBound($PAL) - 1 $PAL[$i] = Number(FileRead($fileHandle, 2)) ; read 0x200 (16*16) words Next Global $PALcolor[16 * 16 * 4] For $i = 0 To UBound($PAL) - 1 $PALcolor[$i * 4 + 0] = BitShift($PAL[$i], 7) $PALcolor[$i * 4 + 1] = BitShift($PAL[$i], 2) $PALcolor[$i * 4 + 2] = BitShift($PAL[$i], -3) If $PAL[$i] = 0 Then $PALcolor[$i * 4 + 3] = 0x00 Else $PALcolor[$i * 4 + 3] = 0xFF EndIf Next ConsoleWrite("PAL " & TimerDiff($a) & @CRLF) $a = TimerInit() FileSetPos($fileHandle, 0x43A0, $FILE_BEGIN) Global $IMD[0x7000] For $i = 0 To UBound($IMD) - 1 $IMD[$i] = Int(String(FileRead($fileHandle, 1))) ; read 0x7000 bytes Next ConsoleWrite("IMD " & TimerDiff($a) & @CRLF) Global $IMDT[256*256*4] $a = TimerInit() For $i = 0 To 15 For $j = 0 To 223 $cn = 0 For $k = 0 To 127 $byte = $IMD[$j * 128 + $k] ; byte for decode $index = $j * 1024 + $cn * 4 $index2 = $i * 0x40 + BitAND($byte, 0x0F) * 4 $IMDT[$index + 0] = $PALcolor[$index2 + 0] ; blue $IMDT[$index + 1] = $PALcolor[$index2 + 1] ; green $IMDT[$index + 2] = $PALcolor[$index2 + 2] ; red $IMDT[$index + 3] = $PALcolor[$index2 + 3] ; alpha $cn += 1 $index = $j * 1024 + $cn * 4 $index2 = $i * 0x40 + BitShift($byte, 4) * 4 $IMDT[$index + 0] = $PALcolor[$index2 + 0] ; blue $IMDT[$index + 1] = $PALcolor[$index2 + 1] ; green $IMDT[$index + 2] = $PALcolor[$index2 + 2] ; red $IMDT[$index + 3] = $PALcolor[$index2 + 3] ; alpha $cn += 1 Next Next ;~ $b = TimerInit() saveTGA2($i) ;~ ConsoleWrite("save TGA " & TimerDiff($b) & @CRLF) Next ConsoleWrite("full time " & TimerDiff($a) & @CRLF) ; 16 seconds FileClose($fileHandle) EndFunc Func saveTGA2($name) Local $tga[18] = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x20, 0x20] Local $data For $i = 0 To 17 $data &= Hex($tga[$i], 2) Next For $i = 0 To UBound($IMDT) - 1 $data &= Hex($IMDT[$i], 2) Next $binary = FileOpen("test\" & $name & ".tga", BitOR($FO_BINARY, $FO_OVERWRITE, $FO_CREATEPATH)) FileWrite($binary, "0x" & $data) FileClose($binary) EndFunc if anyone can optimize my code I would be very grateful, or pointing me to better solution, thx
      ufs9r.cdp
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
    • PleaseHelpMEIWillLoveyou
      By PleaseHelpMEIWillLoveyou
      Is there a way to use a custom terminal or something from my pc and run a script on another pc.
      please let me know if its possible
      (not for anything bad just for a project im working on)
×