Jump to content

Two Arrays within loop


manron
 Share

Recommended Posts

Hello,

I have searched the forum to find an answer to my question but to no success. The problem is, my mind currently cannot work out a solution ...
May I please share my problem.

Prehistory
1) My Script opens the Chrome Browser on windows and then adds 3 more tabs.
2) Then it opens a different GDrive Folder for each of the 4 tabs
3) The code works fine with Clipput ... here is the "old" code (I swaped the urls for my GDrive Folders with different urls):

$s = 10
MouseClick("right",200,1030,1,$s)  ;clicks on Chrome Icon
MouseClick("left",200,930,1,$s)      ;opens new Chrome window
Sleep(500)
ClipPut("https://www.youtube.com") 
Send("^v")
Send("{ENTER}")
MouseClick("left",270,20,1,$s)            ;2nd TAB
Sleep(500)
ClipPut("https://www.amazon.com") 
Send("^v")
Send("{ENTER}")
MouseClick("left",500,20,1,$s)            ;3rd TAB
Sleep(500)
ClipPut("https://www.nytimes.com") 
Send("^v")
Send("{ENTER}")
MouseClick("left",750,20,1,$s)            ;4th TAB
Sleep(500)
ClipPut("https://www.nike.com")
Send("^v")
Send("{ENTER}")

 

Then, I wanted to shorten the script with the help of two arrays, one for the Urls and the other one for the X-Coordinates of the Tabs (Y-Coordinate is always the same):
 

Local  $arr[4]
 $arr[0] = "https://www.youtube.com"
 $arr[1] = "https://www.amazon.com"
 $arr[2] = "https://www.nytimes.com"
$arr[3] = "https://www.nike.com"
$iMax = UBound($arr)

Local  $arr2[3]     ;This array is for the X Coordinate of the Tabs
 $arr2[0] = "270"
 $arr2[1] = "500"
 $arr2[2] = "750"
$iMax2 = UBound($arr2); get array size

$s = 10
MouseClick("right",200,1030,1,$s)  ;clicks on Chrome Icon
MouseClick("left",200,930,1,$s)      ;opens new Chrome window
Sleep(500)

For $i = 0 To  $iMax  -1
For $j = 0 To  $iMax2  -1
MouseClick("left",$arr2[$j],20,1,$s)
ClipPut($arr[$i]) 
Send("^v")
Send("{ENTER}")
Next
Next

I just cannot figure out, how to combine both arrays. Also they have uneven slots (4 and 3). Reasoning tells me that it should work like that:

For ...
Open Tab
Enter Url
Next

But my mind just cannot process it.

Would someone please help me?

Thank you very much for your time!
Manron


PS: Not so important but still I haven't found an answer for my other question that makes sense to me:
Why can't I use a variable for Sleep() (or others like Mouseclick) like
$a = Sleep(500)
$b = Mouseclick("left",100,150,1,0)
?
Using a Function for replacing just one line of code seems a bit too much.

Thank you again!

Link to comment
Share on other sites

Wouldn't it be easier just to open them all at once, for example:

#include <Array.au3>
Global $g_aSiteUrls[4]
    $g_aSiteUrls[0] = "https://www.youtube.com"
    $g_aSiteUrls[1] = "https://www.amazon.com"
    $g_aSiteUrls[2] = "https://www.nytimes.com"
    $g_aSiteUrls[3] = "https://www.nike.com"
Global $g_sGoogleChrome = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Chrome.exe", "")
    If FileExists($g_sGoogleChrome) = 0 Then Exit
Run($g_sGoogleChrome & " " &  _ArrayToString($g_aSiteUrls, " "))

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...