Jump to content
Sign in to follow this  
agertnas

How do I get a GUI button to run a script?

Recommended Posts

CODE
#include <IE.au3>

$oIE = _IECreate("Site")

$oForm = _IEFormGetCollection($oIE, 0)

$Username = _IEFormElementGetObjByName($oForm, "Account")

$Password = _IEFormElementGetObjByName($oForm, "password")

_IEFormElementSetValue($Username, "username")

_IEFormElementSetValue($Password, "password")

_IEFormSubmit($oForm)

I want to get a button to run the above script without having to use the

CODE
Run ("AutoIt3.exe try1.au3")

Is there a way to just add the script that I want to add to the GUI button, without having to run it as a seperate script?

If you couldn't already tell, I'm a total beginner. I've searched up and down the site for this, and all over the help section. If its in the help section, and you'd rather just tell me what to search for, that would work too. :-)

Thanks..

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

$GUI = GUICreate ("GUI", 100, 100)

$Button = GUICtrlCreateButton ("Launch", 5, 5, 90, 90)

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg ()

Select

case $msg = -3

Exit

Case $msg = $button

_ButtonFunc ()

EndSelect

WEnd

Func _ButtonFunc ()

MsgBox (0, "", "The button was pressed! Your code would then be executed.")

EndFunc

Share this post


Link to post
Share on other sites

Hmm.. Well I got it to work once, but when I tried to repeat the situation with another button, nothing happens..

Here is my full code so far

CODE
#include <IE.au3>

#include <String.au3>

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Owner\Desktop\Myfirstscript\fantasylogin.kxf

$login = GUICreate("login", 616, 430, 205, 173)

GUISetBkColor(0x83B7E3)

$login1 = GUICtrlCreateButton("Login", 22, 27, 97, 33, 0)

$bt1 = GUICtrlCreateButton("B1", 24, 72, 89, 25, 0)

$bt2 = GUICtrlCreateButton("B2", 24, 104, 89, 25, 0)

$bt3 = GUICtrlCreateButton("B3", 24, 136, 89, 25, 0)

$bt4 = GUICtrlCreateButton("B4", 24, 168, 89, 25, 0)

$bt5 = GUICtrlCreateButton("B5", 24, 296, 89, 25, 0)

$bt6 = GUICtrlCreateButton("B6", 24, 264, 89, 25, 0)

$bt7 = GUICtrlCreateButton("B7", 24, 232, 89, 25, 0)

$bt8 = GUICtrlCreateButton("B8", 24, 200, 89, 25, 0)

$bt9 = GUICtrlCreateButton("B9", 24, 360, 89, 25, 0)

$bt10 = GUICtrlCreateButton("B10", 24, 328, 89, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$msg = GUIGetMsg ()

Select

Case $msg = -3

Exit

Case $msg = $login1

_ButtonFunc()

$oIE = _IECreate("site")

Sleep(2000)

$oForm = _IEFormGetCollection($oIE, 0)

$Username = _IEFormElementGetObjByName($oForm, "Account")

$Password = _IEFormElementGetObjByName($oForm, "password")

_IEFormElementSetValue($Username, "Username")

_IEFormElementSetValue($Password, "Password")

_IEFormSubmit($oForm)

Sleep(2000)

EndSelect

WEnd

Func _ButtonFunc()

MsgBox (0, "", "The button was pressed! Your code would then be executed.")

EndFunc

While 2

$msg2 = GUIGetmsg ()

Select

Case $msg2 = -3

Exit

Case $msg2 = $bt1

_ButtonFunc2()

$oIE = _IECreate("Site")

EndSelect

WEnd

Func _ButtonFunc2()

Msgbox (0,"","should work")

EndFunc

Any idea what I've done wrong? I'm sure there is something i'm missing. But, the second button just will not open another IE window. I'd prefer to use only 1 IE window, and keep reusing the same window, but I can't figure out how to do that either.

Share this post


Link to post
Share on other sites

Hmm.. Well I got it to work once, but when I tried to repeat the situation with another button, nothing happens..

Here is my full code so far

CODE
#include <IE.au3>

#include <String.au3>

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Owner\Desktop\Myfirstscript\fantasylogin.kxf

$login = GUICreate("login", 616, 430, 205, 173)

GUISetBkColor(0x83B7E3)

$login1 = GUICtrlCreateButton("Login", 22, 27, 97, 33, 0)

$bt1 = GUICtrlCreateButton("B1", 24, 72, 89, 25, 0)

$bt2 = GUICtrlCreateButton("B2", 24, 104, 89, 25, 0)

$bt3 = GUICtrlCreateButton("B3", 24, 136, 89, 25, 0)

$bt4 = GUICtrlCreateButton("B4", 24, 168, 89, 25, 0)

$bt5 = GUICtrlCreateButton("B5", 24, 296, 89, 25, 0)

$bt6 = GUICtrlCreateButton("B6", 24, 264, 89, 25, 0)

$bt7 = GUICtrlCreateButton("B7", 24, 232, 89, 25, 0)

$bt8 = GUICtrlCreateButton("B8", 24, 200, 89, 25, 0)

$bt9 = GUICtrlCreateButton("B9", 24, 360, 89, 25, 0)

$bt10 = GUICtrlCreateButton("B10", 24, 328, 89, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$msg = GUIGetMsg ()

Select

Case $msg = -3

Exit

Case $msg = $login1

_ButtonFunc()

$oIE = _IECreate("site")

Sleep(2000)

$oForm = _IEFormGetCollection($oIE, 0)

$Username = _IEFormElementGetObjByName($oForm, "Account")

$Password = _IEFormElementGetObjByName($oForm, "password")

_IEFormElementSetValue($Username, "Username")

_IEFormElementSetValue($Password, "Password")

_IEFormSubmit($oForm)

Sleep(2000)

EndSelect

WEnd

Func _ButtonFunc()

MsgBox (0, "", "The button was pressed! Your code would then be executed.")

EndFunc

While 2

$msg2 = GUIGetmsg ()

Select

Case $msg2 = -3

Exit

Case $msg2 = $bt1

_ButtonFunc2()

$oIE = _IECreate("Site")

EndSelect

WEnd

Func _ButtonFunc2()

Msgbox (0,"","should work")

EndFunc

Any idea what I've done wrong? I'm sure there is something i'm missing. But, the second button just will not open another IE window. I'd prefer to use only 1 IE window, and keep reusing the same window, but I can't figure out how to do that either.

NOnonononono... One loop. Look at it as this way:

+---------------------------------------+
|   Start Script                        |
+---------------------------------------+
                      |
                      |
+---------------------------------------+
|   Create and show GUI              |
+---------------------------------------+
                      |
                      |
                      |
+---------------------------------------+
|   Start First While Message Loop    |
+---------------------------------------+
     <<<<            |   +-----------------------------+ 
     \/  ^          +---+   If Exit Button Clicked  |
     \/  ^          |   +-----------------------------+
     \/  ^          |           |   +-----------------------------+ 
     \/  ^          |           +---+   Exit the script        |
     \/  ^          |               +-----------------------------+
     \/  ^          |   +-----------------------------+ 
     \/  ^          +---+   If first Button Clicked   |
     \/  ^          |   +-----------------------------+
     \/  ^          |           |   +-----------------------------+ 
     \/  ^          |           +---+   Do something              |
     \/  ^          |               +-----------------------------+
     \/  ^          |   +-----------------------------+ 
     \/  ^          +---+   If second Button Clicked  |
     \/  ^          |   +-----------------------------+
     \/  ^          |           |   +-----------------------------+ 
     \/  ^          |           +---+   Do something              |
     >>>>            |              +-----------------------------+
+---------------------------------------+
|   End First While Message Loop        |
+---------------------------------------+
                      |
                      |
+---------------------------------------+
|   End of the script                  |
+---------------------------------------+

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  

×
×
  • Create New...