Sign in to follow this  
Followers 0
AndiDomiK

Adding Values to Arrays "on runtime"

19 posts in this topic

Hi Guys!

My Problem concerns that i haven't been able to assign these Values to an Array the proper way.

So here's the code that works as intended but looking rather ugly,.. i hope you understand my problem :oops:

$Pos = _CheckPlace($SubFolderID, $Place, $Space)

If IsArray($Pos) Then
  $i = $Pos[1] - $WinData[1]  +1
  $WindowCount = $WindowCount + 1
  If $WindowCount = 1 Then
   $Win1 = $Pos
  ElseIf $WindowCount = 2 Then
   $Win2 = $Pos
  ElseIf $WindowCount = 3 Then
   $Win3 = $Pos
  ElseIf $WindowCount = 4 Then
   $Win4 = $Pos
  ElseIf $WindowCount = 5 Then
   $Win5 = $Pos
  ElseIf $WindowCount = 6 Then
   $Win6 = $Pos
  ElseIf $WindowCount = 7 Then
   $Win7 = $Pos
  ElseIf $WindowCount = 8 Then
   $Win8 = $Pos
  ElseIf $WindowCount = 9 Then
   $Win9 = $Pos
  ElseIf $WindowCount = 10 Then
   $Win10 = $Pos
  ElseIf $WindowCount = 11 Then
   $Win11 = $Pos
  ElseIf $WindowCount = 12 Then
   $Win12 = $Pos
  ElseIf $WindowCount = 13 Then
   $Win13 = $Pos
  ElseIf $WindowCount = 14 Then
   $Win14 = $Pos
  ElseIf $WindowCount = 15 Then
   $Win15 = $Pos
  ElseIf $WindowCount = 16 Then
   $Win16 = $Pos
  ElseIf $WindowCount = 17 Then
   $Win17 = $Pos
  ElseIf $WindowCount = 18 Then
   $Win18 = $Pos
  ElseIf $WindowCount = 19 Then
   $Win19 = $Pos
  EndIf

Else
  $i=$i+58
EndIf
Next
  If $WindowCount = 0 Then
   Local $WindowArray = "Error"
  ElseIf $WindowCount = 1 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]]]
  ElseIf $WindowCount = 2 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]]]
  ElseIf $WindowCount = 3 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]]]
  ElseIf $WindowCount = 4 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]]]
  ElseIf $WindowCount = 5 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]]]
  ElseIf $WindowCount = 6 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]]]
  ElseIf $WindowCount = 7 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]]]
  ElseIf $WindowCount = 8 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]]]
  ElseIf $WindowCount = 9 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]]]
  ElseIf $WindowCount = 10 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]]]
  ElseIf $WindowCount = 11 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]]]
  ElseIf $WindowCount = 12 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]]]
  ElseIf $WindowCount = 13 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]]]
  ElseIf $WindowCount = 14 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]]]
  ElseIf $WindowCount = 15 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]]]
  ElseIf $WindowCount = 16 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]]]
  ElseIf $WindowCount = 17 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]]]
  ElseIf $WindowCount = 18 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]],[$Win18[0],$Win18[1]]]
  ElseIf $WindowCount = 19 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]],[$Win18[0],$Win18[1]],[$Win19[0],$Win19[1]]]
  EndIf


For $i = 0 to $WindowCount -1

MsgBox(0,"","Position of SubFolder "& $i+1&"in Folder X:"&$WindowArray[$i][0]&"and Y"&$WindowArray[$i][1])
Next

I tried for Hours getting it in the Form looking somewhat like this pseudocode

Local $WindowArray = ~~Placeholder Value

For $i to $o do

$WindowArray[$i] = [[$WindowArray[0],$WindowArray[1]], [[X],[Y]]

Next

But although i sometimes didn't get Errors it never gave me the intended solution, as the above code does.

Share this post


Link to post
Share on other sites



It would help if you'd explain what's supposed to be in $Pos after the function call. Right now all I can see is that you have a Next with no For statement, other than that I have no clue what the problem could be or what your error is because you never mention that either.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, thanks for the fast reply!

$Pos contains the position of a visible Subfolder.

There is no Error in the Code.

My problem is, i wan't to do this properly and without having a finite number of possible windows.

Meaning:

Something like this:

Local $WindowArray = ~~Placeholder Value
For $i to $o do
$WindowArray[$i] = [[[$WindowArray[0],$WindowArray[1]], [[Pos[0]],[Pos[1]]]]
Next
Edited by AndiDomiK

Share this post


Link to post
Share on other sites

What are the contents of $Pos for any of it's values, because there's no way to shorten this without knowing what _CheckPlace returns. If you could post a reproducer script that demonstrates how you get the contents of $Pos and what you're looking to do with it once you've gotten it, it would make it a lot easier to figure out how to fix this.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

just a quick idea...would ubound and redim work for you?

Or did i missunderstand waht you need?

Share this post


Link to post
Share on other sites

What are the contents of $Pos for any of it's values, because there's no way to shorten this without knowing what _CheckPlace returns. If you could post a reproducer script that demonstrates how you get the contents of $Pos and what you're looking to do with it once you've gotten it, it would make it a lot easier to figure out how to fix this.

Agreed. This looks overly complicated.

Share this post


Link to post
Share on other sites

$Pos = _CheckPlace($SubFolderID, $Place, $Space)

$Pos= Position of an Shortcut or program icon.

_Checkplace: Gets Data, to find out what icon is looked for(It's a multiple Pixelsearch build up like vektors: Find pixelcolor1, if pixelcolor 1 found, then there should be a pixel of the color "0x121212" at (Position of Color1 +2xpixels+2ypixels) etc.

$Place: To find out, how many Elements("Pictures") that match this result, i have to change the starting position after a positive, so the new $place is then sent back to the func with the new Position to start the search --> $Firstmatchx+1 $Firstmatchy+1

$Space: Depending on what you chose in desktop settings, there is a space where you dont have to search for the next image.

Ok so much for the setup.

Now when a match is found i want it to be saved in an array.

If IsArray($Pos) Then

$i = $Pos[1] - $WinData[1] +1

$WindowCount = $WindowCount + 1

If $WindowCount = 1 Then

$Win1 = $Pos

ElseIf $WindowCount = 2 Then

$Win2 = $Pos

ElseIf $WindowCount =

I solved this by having to make an if case for every enventuality of a find ranging from 0 to 19.

Position of match 1 is saved to $Win1 Position of match 2, IF there is a second match, is saved to $win2 etc.

This next part finally gets me to where i want to be, depending on how many matches i have, they are saved to an array, and

i can work with the array without having to deal with any case manually like i had to, to get to this array.

If $WindowCount = 0 Then

Local $WindowArray = "Error"

ElseIf $WindowCount = 1 Then

Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]]]

ElseIf $WindowCount = 2 Then

Local $WindowArray[$WindowCount][2]

So my actual problem:

This Code i posted works as it is intendet to, but there must be a better way to make autoit create the array i want.

Example why there has to be a better way:

ElseIf $WindowCount = 19 Then

Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]],[$Win18[0],$Win18[1]],[$Win19[0],$Win19[1]]]

EndIf

This is the code, for when the program finds 19 matching subfolders, lets say, i fill a folder with 1000 shortcuts, all with the same icon(=1000 matches)

Problem:

I wouldnt be able to Write the code for case 1-1000 in a reasonable amount of time,.. it would take days!

What I am looking for, is a way to write the code above in a way something like this:

If isarray($pos) then <- a matching window was found: The position of this Window has to be saved to $WindowArray

$WindowCount=WindowCount+1 <- starting value of windowcount is 0, so if this is the first match the program found, the position of this Window

shall be stored in $WindowArray[$i((in this case $i=1))

Share this post


Link to post
Share on other sites

...continued

so the code then would be:

$WindowArray[0] = [[place],[holder]]

If isarray($pos) then

$WindowCount=WindowCount+1

$WindowArray[$WindowCount] = $pos <-the coordinates of the first match shall be stored in $windowarray[1]..[0] and [1][1]

....

this above part is repeated, until the function returns Error, which meens no more window matches found.

I want the position of every match to be added to $WindowArray.

But as said, i dont know how to formulate it, to get to the same result as i did with the code postet in my first post.

Share this post


Link to post
Share on other sites

Ok so when you run _CheckPlace and it returns a find, what does the $pos array look like?

Share this post


Link to post
Share on other sites

as stated it has the coordinates stored:

it looks like $pos[1][2]= [[234],[567]]

Or what do you meen with look like?

Share this post


Link to post
Share on other sites

Maybe something like this would work for you?

Global $WindowArray[200][2]

While 1
    $Pos = _CheckPlace($SubFolderID, $Place, $Space)

    If IsArray($Pos) Then
        $i = $Pos[1] - $WinData[1] + 1
        $WindowCount = $WindowCount + 1
        If UBound($WindowArray) Then
            ReDim $WindowArray[UBound($WindowArray) * 2][2]
        EndIf
        $WindowArray[$WindowCount][0] = $Pos[0]
        $WindowArray[$WindowCount][1] = $Pos[1]
    Else
        $i = $i + 58
    EndIf
WEnd
; not sure how you tell you've run out of matches in your _CheckPlace so you'll need to have someway of using ExitLoop inside the While loop.
ReDim $WindowArray[$WindowCount][2]
For $i = 0 To UBound($WindowArray)

    MsgBox(0, "", "Position of SubFolder " & $i + 1 & "in Folder X:" & $WindowArray[$i][0] & "and Y" & $WindowArray[$i][1])
Next

As the comments in the script say, I have no way of knowing how you have determined you've run out of matches, so you will need to put an ExitLoop inside the While loop so that it has some way to exit the loop. Or use a For/Next loop instead of the While loop.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Maybe something like this would work for you?

Global $WindowArray[200][2]

While 1
    $Pos = _CheckPlace($SubFolderID, $Place, $Space)

    If IsArray($Pos) Then
        $i = $Pos[1] - $WinData[1] + 1
        $WindowCount = $WindowCount + 1
        If UBound($WindowArray) Then
            ReDim $WindowArray[UBound($WindowArray) * 2][2]
        EndIf
        $WindowArray[$WindowCount][0] = $Pos[0]
        $WindowArray[$WindowCount][1] = $Pos[1]
    Else
        $i = $i + 58
    EndIf
WEnd
; not sure how you tell you've run out of matches in your _CheckPlace so you'll need to have someway of using ExitLoop inside the While loop.
ReDim $WindowArray[$WindowCount][2]
For $i = 0 To UBound($WindowArray)

    MsgBox(0, "", "Position of SubFolder " & $i + 1 & "in Folder X:" & $WindowArray[$i][0] & "and Y" & $WindowArray[$i][1])
Next

As the comments in the script say, I have no way of knowing how you have determined you've run out of matches, so you will need to put an ExitLoop inside the While loop so that it has some way to exit the loop. Or use a For/Next loop instead of the While loop.

Thank you very much!

This is exactly what I ment, and I it works like a charm!

Sorry, forgot to look at the values of X and Y,.. i dont get an Error msg, however,.. there are no values shown, i rechecked with mousemove and it jumps to screenpos X:0 Y:0 ,.. got any clue what this inclines?

Edited by AndiDomiK

Share this post


Link to post
Share on other sites

No idea what it means, because I don't have anything to work with other than the arrays above. I'd need to see the whole script to figure out what might be the problem.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

$SearchPix5 = PixelSearch($SearchPix1[0] - 2, $SearchPix1[1], $SearchPix1[0] - 2, $SearchPix1[1], $DataArray[5][1], 10, 1)
    
       If IsArray($SearchPix5) Then
        $Pos = $SearchPix5
        Return $Pos  ;POS defined/ match found
        ExitLoop

This is what the UDF returns if it finds a match..

If it doesnt find a match it returns $Pos="Error"

but that doesn't get through the "if isarray() part,...

Here the whole script, posting Check Place.au3 doesnt help i believe, all it does is return the above

#include <Check Place.au3>

$WinData = WinGetPos("INSERT A WINDOWNAME")
$WindowCount = 0
$i = 0
For $k = 0 to $WinData[1]+$WinData[3]  ;Reached bottom of window
Local $Place[2][1] = [[$WinData[0]],[0+$i]]  ;Starting Pos
Local $Space[2][1] = [[$WinData[1],[210]] ;Reach
$SubFolderID = "INSERT INI SEKTIONNAME"
$Pos = _CheckPlace($SubFolderID, $Place, $Space)
Local $WindowArray[200][2]

If IsArray($Pos) Then
        $i = $Pos[1] - $WinData[1] + 1
        $WindowCount = $WindowCount + 1
        If UBound($WindowArray) Then
            ReDim $WindowArray[UBound($WindowArray) * 2][2]
        EndIf
        $WindowArray[$WindowCount][0] = $Pos[0]
        $WindowArray[$WindowCount][1] = $Pos[1]
    Else
        $i = $i + 58
    EndIf
Next

ReDim $WindowArray[$WindowCount][2]
For $i = 0 To UBound($WindowArray)-1
MsgBox(0, "", "Position of SubFolder " & $i + 1 & "in Folder X:" & $WindowArray[$i][0] & "and Y" & $WindowArray[$i][1])
;MouseMove($WindowArray[$i][0],$WindowArray[$i][1])
Next
Edited by AndiDomiK

Share this post


Link to post
Share on other sites

Where does $SuchPix1 come from? You're checking $SearchPix5 for an array, but you're setting $Pos to $SuchPix1. I'm lost as to what it is you're expecting without more of your code, because this is very confusing.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Heres some code that simulates the Problem i have Just run it on Google main page.. what i intendet was to get the coordinates of 5 "white" pixels.

Func _CheckPlace($1,$2,$3)

$pos = PixelSearch(20,500,21,501,0xFFFFFF,100)
Return $Pos
EndFunc

$WinData = WinGetPos("Google - Mozilla Firefox")
$WindowCount = 0
$i = 0
For $k = 0 to 5  ;Reached bottom of window
Local $Place[2][1] = [[$WinData[0]],[0+$i]]  ;Starting Pos
Local $Space[2][1] = [[$WinData[1]],[210]] ;Reach
$SubFolderID = "INSERT INI SEKTIONNAME"
$Pos = _CheckPlace($SubFolderID, $Place, $Space)
Local $WindowArray[200][2]

If IsArray($Pos) Then
        $i = $Pos[1] - $WinData[1] + 1
        $WindowCount = $WindowCount + 1
        If UBound($WindowArray) Then
            ReDim $WindowArray[UBound($WindowArray) * 2][2]
        EndIf
        $WindowArray[$WindowCount][0] = $Pos[0]
        $WindowArray[$WindowCount][1] = $Pos[1]
    Else
        $i = $i + 58
    EndIf

Next


ReDim $WindowArray[$WindowCount][2]
For $i = 0 To UBound($WindowArray)-1
MsgBox(0, "", "Position of SubFolder " & $i + 1 & "in Folder X:" & $WindowArray[$i][0] & "and Y" & $WindowArray[$i][1])
MouseMove($WindowArray[$i][0],$WindowArray[$i][1])
Next

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

And here is the Working version , but the one which looks so bulky and cant have infinite windows:

Func _CheckPlace($1,$2,$3)
$pos = PixelSearch(20,500,21,501,0xFFFFFF,100)
Return $Pos
EndFunc
$WinData = WinGetPos("Google - Mozilla Firefox")
$WindowCount = 0
$i=0
For $k = 0 to 5
Local $Place[2][1] = [[$WinData[0]],[0+$i]]  ;Starting Pos
Local $Space[2][1] = [[$WinData[1]],[210]] ;Reach
$SubFolderID = "INSERT INI SEKTIONNAME"
$Pos = _CheckPlace($SubFolderID, $Place, $Space)
If IsArray($Pos) Then
  $i = $Pos[1] - $WinData[1]  +1
  $WindowCount = $WindowCount + 1
  If $WindowCount = 1 Then
   $Win1 = $Pos
  ElseIf $WindowCount = 2 Then
   $Win2 = $Pos
  ElseIf $WindowCount = 3 Then
   $Win3 = $Pos
  ElseIf $WindowCount = 4 Then
   $Win4 = $Pos
  ElseIf $WindowCount = 5 Then
   $Win5 = $Pos
  ElseIf $WindowCount = 6 Then
   $Win6 = $Pos
  ElseIf $WindowCount = 7 Then
   $Win7 = $Pos
  ElseIf $WindowCount = 8 Then
   $Win8 = $Pos
  ElseIf $WindowCount = 9 Then
   $Win9 = $Pos
  ElseIf $WindowCount = 10 Then
   $Win10 = $Pos
  ElseIf $WindowCount = 11 Then
   $Win11 = $Pos
  ElseIf $WindowCount = 12 Then
   $Win12 = $Pos
  ElseIf $WindowCount = 13 Then
   $Win13 = $Pos
  ElseIf $WindowCount = 14 Then
   $Win14 = $Pos
  ElseIf $WindowCount = 15 Then
   $Win15 = $Pos
  ElseIf $WindowCount = 16 Then
   $Win16 = $Pos
  ElseIf $WindowCount = 17 Then
   $Win17 = $Pos
  ElseIf $WindowCount = 18 Then
   $Win18 = $Pos
  ElseIf $WindowCount = 19 Then
   $Win19 = $Pos
  EndIf

Else
  $i=$i+58
EndIf
Next
  If $WindowCount = 0 Then
   Local $WindowArray = "Error"
  ElseIf $WindowCount = 1 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]]]
  ElseIf $WindowCount = 2 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]]]
  ElseIf $WindowCount = 3 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]]]
  ElseIf $WindowCount = 4 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]]]
  ElseIf $WindowCount = 5 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]]]
  ElseIf $WindowCount = 6 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]]]
  ElseIf $WindowCount = 7 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]]]
  ElseIf $WindowCount = 8 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]]]
  ElseIf $WindowCount = 9 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]]]
  ElseIf $WindowCount = 10 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]]]
  ElseIf $WindowCount = 11 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]]]
  ElseIf $WindowCount = 12 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]]]
  ElseIf $WindowCount = 13 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]]]
  ElseIf $WindowCount = 14 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]]]
  ElseIf $WindowCount = 15 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]]]
  ElseIf $WindowCount = 16 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]]]
  ElseIf $WindowCount = 17 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]]]
  ElseIf $WindowCount = 18 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]],[$Win18[0],$Win18[1]]]
  ElseIf $WindowCount = 19 Then
   Local $WindowArray[$WindowCount][2] = [[$Win1[0],$Win1[1]],[$Win2[0],$Win2[1]],[$Win3[0],$Win3[1]],[$Win4[0],$Win4[1]],[$Win5[0],$Win5[1]],[$Win6[0],$Win6[1]],[$Win7[0],$Win7[1]],[$Win8[0],$Win8[1]],[$Win9[0],$Win9[1]],[$Win10[0],$Win10[1]],[$Win11[0],$Win11[1]],[$Win12[0],$Win12[1]],[$Win13[0],$Win13[1]],[$Win14[0],$Win14[1]],[$Win15[0],$Win15[1]],[$Win16[0],$Win16[1]],[$Win17[0],$Win17[1]],[$Win18[0],$Win18[1]],[$Win19[0],$Win19[1]]]
  EndIf
For $i = 0 To $WindowCount -1
MsgBox(0, "", "Position of SubFolder " & $i + 1 & "in Folder X:" & $WindowArray[$i][0] & "and Y" & $WindowArray[$i][1])
MouseMove($WindowArray[$i][0],$WindowArray[$i][1])
Next

If you compare the Message in the MSGBOX you see what i meen, the short version doesn't give me back the Position

Edited by AndiDomiK

Share this post


Link to post
Share on other sites

I've corrected the script so that you'll get the array done correctly, see the lines marked with "<<<<<<<<<<<<<" for comments.

#include <array.au3>

Func _CheckPlace($1, $2, $3)

    Local $pos = PixelSearch(20, 500, 21, 501, 0xFFFFFF, 100)
    Return $pos
EndFunc   ;==>_CheckPlace

$WinData = WinGetPos("Google - Mozilla Firefox")
$WindowCount = 0
$i = 0
Global $WindowArray[200][2] ; <<<<<<<<< Moved this outside of the loop, because you redeclared it every time through the loop
For $k = 0 To 5 ;Reached bottom of window
    Local $Place[2][1] = [[$WinData[0]],[0 + $i]] ;Starting Pos
    Local $Space[2][1] = [[$WinData[1]],[210]] ;Reach
    $SubFolderID = "INSERT INI SEKTIONNAME"
    $pos = _CheckPlace($SubFolderID, $Place, $Space)
    If IsArray($pos) Then
        $i = $pos[1] - $WinData[1] + 1
        $WindowCount = $WindowCount + 1
        If UBound($WindowArray) Then
            ReDim $WindowArray[UBound($WindowArray) * 2][2]
        EndIf
        $WindowArray[$WindowCount][0] = $pos[0]
        $WindowArray[$WindowCount][1] = $pos[1]
    Else
        $i = $i + 58
    EndIf
Next


ReDim $WindowArray[$WindowCount][2]
_ArrayDisplay($WindowArray) ; displays the contents of $WindowArray to make sure we're getting what we think we're supposed to. Debugging only
For $i = 1 To UBound($WindowArray) - 1 ; <<<<<<<< Changed it to 1 to Ubound, because $WindowArray starts at 1
    MsgBox(0, "", "Position of SubFolder " & $i & "in Folder X: " & $WindowArray[$i][0] & "and Y " & $WindowArray[$i][1]) ; Don't need $I + 1 any longer due to starting at 1 in the loop now
    MouseMove($WindowArray[$i][0], $WindowArray[$i][1])
Next
1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

WoW!

Don't know how to thank you.

Many thanks for your time and effort!

One small mistake was still in the code:

ReDim $WindowArray[$WindowCount][2] somehow gets alle the matches -1

ReDim $WindowArray[$WindowCount+1][2] does the trick

Edited by AndiDomiK

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
Sign in to follow this  
Followers 0