Jump to content

Help with my script please


Recommended Posts

Hello, i am completely new to using autoit and i am currently just creating pointless programs to learn the language. Ok basically i am trying to make a script that logs into my gmail account. There is a user interface for input of the username and password. My current problem is that i am trying to get my script to display a message i.e. You have not input a username and password.. when the "Go" button is pressed and the username and / or password box is blank. My problem is that i can not get my script to recognise that the values are blank i.e false when the button is pressed.. is this a problem with reading a variable created by GUICtrlCreateInput ?? My script is as follows.. any help is appreciated. Thanks :P

;-----------------

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include <IE.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 316, 131, 193, 125)

$Username = GUICtrlCreateInput("", 88, 24, 209, 21)

$Password = GUICtrlCreateInput("", 88, 56, 209, 21,$ES_PASSWORD)

$Label1 = GUICtrlCreateLabel("Username:", 24, 24, 55, 17)

$Label2 = GUICtrlCreateLabel("Password:", 24, 56, 53, 17)

$Button1 = GUICtrlCreateButton("Go!", 88, 88, 105, 33, 0)

GUISetState(@SW_SHOW)

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

GUICtrlSetData ($Username, "")

GUICtrlSetData ($Password, "")

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

if $Username and $Password = False Then

msgbox(0,"Error","Both a Username and Password are required to continue")

Elseif $username and $password = True then

_IECreate("http://gmail.google.com")

WinSetState("Google Mail - Windows Internet Explorer", "", @SW_MAXIMIZE)

Send(GUICtrlRead($Username))

Send("{TAB}")

Send(GUICtrlRead($Password))

ControlClick("Google Mail", "", "", "LEFT", "1", "1033", "260")

EndIf

EndSwitch

WEnd

;----------------

Link to comment
Share on other sites

@pilky1986

Welcome to autoit forum :P

Please use code tags for display your scripts in the forum...

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate('Form1', 316, 131, 193, 125)
$Username = GUICtrlCreateInput('', 88, 24, 209, 21)
$Password = GUICtrlCreateInput('', 88, 56, 209, 21, $ES_PASSWORD)
$Label1 = GUICtrlCreateLabel('Username:', 24, 24, 55, 17)
$Label2 = GUICtrlCreateLabel('Password:', 24, 56, 53, 17)
$Button1 = GUICtrlCreateButton('Go!', 88, 88, 105, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If GUICtrlRead($Username) = '' And GUICtrlRead($Password) = '' Then
                MsgBox(16, 'Error', 'Both a Username and Password are required to continue')
            ElseIf GUICtrlRead($Username) = '' Then
                MsgBox(16, 'Error', 'Username is required to continue')
            ElseIf GUICtrlRead($Password) = '' Then
                MsgBox(16, 'Error', 'Password is required to continue')
            ElseIf GUICtrlRead($Username) <> '' And GUICtrlRead($Password) <> '' Then
                _IECreate('http://gmail.google.com')
                WinSetState('Google Mail - Windows Internet Explorer', '', @SW_MAXIMIZE)
                Send(GUICtrlRead($Username))
                Send('{TAB}')
                Send(GUICtrlRead($Password))
                ControlClick('Google Mail', '', '', 'LEFT', '1', '1033', '260')
            EndIf
    EndSwitch
WEnd

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Excellent thank you very much firefox! So simple when you know how :P So basically to ready a variable from a gui you need to use the GUICtrlRead rather than just saying $variable = .. or whatever operator you are using. Thanks :unsure: . Do you ever use true and false.. or is it not recommended to ?

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...