Jump to content

Button Clicks an Arrays


Recommended Posts

Hello,

I am trying to create a script that will fill in the "Username" and "Password" on a website. The site does not work with IE so I was going to just have it click the fields and type in the information from the array. I was wanting the button to move onto the next value in the array but cant figure out a way to do this.

Here what I currently have.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Acarr[5] = ["username", "username1", "username2", "username3", "username4", "username5"]
Global $test = 1
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Auto Login", 220, 82, 190, 124)
$Button1 = GUICtrlCreateButton("Next Account", 64, 8, 73, 33)
$Label1 = GUICtrlCreateLabel("Current account will be displayed here", 8, 56, 207, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        $guistat = GUIGetMsg()
        Select
            Case $guistat = $GUI_EVENT_CLOSE
                ExitLoop
            Case $guistat = $Button1
                $test = $Acarr[0] +1
                MsgBox(0, 'Current Value', '' & $test)
        EndSelect
    WEnd

Currently all it does is display 1 when the button is pushed because I am doing it wrong.

So if anyone knows a way to make it move to the next value in the array every time the button is pushed that would be awesome.

Link to comment
Share on other sites

I figured out how to do it on my own... :unsure:

For anyone that has this problem in the future.

I changed the while loop to this

$i = 0

While 1
        $guistat = GUIGetMsg()
        Select
            Case $guistat = $GUI_EVENT_CLOSE
                ExitLoop
            Case $guistat = $Button1
                $i = $i +1
                $test = $Acarr[$i]
                MsgBox(0, 'Current Value', '' & $test)
        EndSelect
    WEnd
Link to comment
Share on other sites

Hi Tomoya!

Since I am chilling around for an answer I might as well take a shot at yours:

First: $test = $Acarr[0] + 1, it is adding 1 to the zeroth element of $Acarr. That row gives you "username" + 1 and nothing else. You were probably thinking somewhere along the lines of $test = $Acarr[0+1] which means one step up on the array. This would result in "username1" instead.

Second: Even if you do as I say above you are not actually stepping up, you will only keep looping $Acarr[0+1] = $Acarr[1] = "username1" over and over again. So you have to step it up by adding a variable that steps up everytime. Something like this:

Dim $i
$i = 0
While 1
       $test = $Acarr[0+$i]
       MsgBox(0,'Current Value', "" & $test)
       $i = $i + 1
Wend

This would result int test being $Acarr[0] the first time through the loop, $Acarr[1] the second time and so on.

Third: The above code snippet might seem nice and feasible until you realize that it doesn't ever stop due to the While 1 loop, you will quickly reach index out of bounds for your array. I would personally use a for loop combined with Ubound instead:

For $i = 0 To Ubound($Acarr)-1
     $test = $Acarr[$i]
     MsgBox(0,'Current Value',"" & $test)
Next

Where Ubound returns the length of your array counting from 1. In your case Ubound would return the value 6, but since array indices start from 0 we do a Ubound - 1. Giving us $Acarr[0] - $Acarr[5].

I am pretty new at this too but hope this solves your problem.

Cheers

Ordeith

Edit: That's what you get for writing long answers I guess :unsure:

Edited by Ordeith
Link to comment
Share on other sites

Hi Tomoya!

Since I am chilling around for an answer I might as well take a shot at yours:

First: $test = $Acarr[0] + 1, it is adding 1 to the zeroth element of $Acarr. That row gives you "username" + 1 and nothing else. You were probably thinking somewhere along the lines of $test = $Acarr[0+1] which means one step up on the array. This would result in "username1" instead.

Second: Even if you do as I say above you are not actually stepping up, you will only keep looping $Acarr[0+1] = $Acarr[1] = "username1" over and over again. So you have to step it up by adding a variable that steps up everytime. Something like this:

Dim $i
$i = 0
While 1
       $test = $Acarr[0+$i]
       MsgBox(0,'Current Value', "" & $test)
       $i = $i + 1
Wend

This would result int test being $Acarr[0] the first time through the loop, $Acarr[1] the second time and so on.

Third: The above code snippet might seem nice and feasible until you realize that it doesn't ever stop due to the While 1 loop, you will quickly reach index out of bounds for your array. I would personally use a for loop combined with Ubound instead:

For $i = 0 To Ubound($Acarr)-1
     $test = $Acarr[$i]
     MsgBox(0,'Current Value',"" & $test)
Next

Where Ubound returns the length of your array counting from 1. In your case Ubound would return the value 6, but since array indices start from 0 we do a Ubound - 1. Giving us $Acarr[0] - $Acarr[5].

I am pretty new at this too but hope this solves your problem.

Cheers

Ordeith

Edit: That's what you get for writing long answers I guess :unsure:

Your answer was still high apreciated though! I will def see the problem with the while loop continuing forever and had read something about it earlier, but with the massive amount of data thats being jammed into my head (Just started autoit prob a hour or so ago) I am getting overwhelmed :>

Its nice to have some confirm that what you did was right. Made me laugh ;)

Edited by Tomoya
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...