Jump to content

why wont button2 work?


Recommended Posts

i been trying more if endif while wend or else elseif i dont know why the button1 works but button2 dont.

what am i doing wrong

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 616, 552, 202, 132)
$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

EndSwitch

    If $nmsg = $Button1 Then
        #include <IE.au3>

        $user = "xxxxxxxx"
        $pass = "xxxxxxx"
        $oIE = _IECreate ("https://xxxxxxxxx")
        $oIE2 = _IECreate ("http://xxxxxxxxxxxxx")
        _IELoadWait ($oIE)

        $uForm = _IEFormGetObjByName ($oIE, "login_form")
        $uText = _IEFormElementGetObjByName ($uForm, "email")
        _IEFormElementSetValue ($uText,$user)

        $pText = _IEFormElementGetObjByName ($uForm, "pass")
        _IEFormElementSetValue ($pText,$pass)
        _IEFormSubmit ($uForm)
        Sleep ( 1500)

        _IENavigate ($oIE2, "xxxxxxxxxxxxxx")

        Or $nmsg = $Button2 Then
        #include <IE.au3>

        $user = "xxxxxxxx"
        $pass = "xxxxxxxxxxxxxx"
        $oIE = _IECreate ("https://")
        $oIE2 = _IECreate ("http://")
        _IELoadWait ($oIE)

        $uForm = _IEFormGetObjByName ($oIE, "login_form")
        $uText = _IEFormElementGetObjByName ($uForm, "email")
        _IEFormElementSetValue ($uText,$user)

        $pText = _IEFormElementGetObjByName ($uForm, "pass")
        _IEFormElementSetValue ($pText,$pass)
        _IEFormSubmit ($uForm)
        Sleep (1500)

        _IENavigate ($oIE2, "http://xxxxxxxxxxxxxxxxxx")

    EndIf
WEnd

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

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

$Form2 = GUICreate("Form2", 616, 552, 202, 132)

$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)

$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

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

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

If $nmsg = $Button1 Then

#include <IE.au3>

$user = "xxxxxxxx"

$pass = "xxxxxxx"

$oIE = _IECreate ("https://xxxxxxxxx")

$oIE2 = _IECreate ("http://xxxxxxxxxxxxx")

_IELoadWait ($oIE)

$uForm = _IEFormGetObjByName ($oIE, "login_form")

$uText = _IEFormElementGetObjByName ($uForm, "email")

_IEFormElementSetValue ($uText,$user)

$pText = _IEFormElementGetObjByName ($uForm, "pass")

_IEFormElementSetValue ($pText,$pass)

_IEFormSubmit ($uForm)

Sleep ( 1500)

_IENavigate ($oIE2, "xxxxxxxxxxxxxx")

ElseIf $nmsg = $Button2 Then

#include <IE.au3>

$user = "xxxxxxxx"

$pass = "xxxxxxxxxxxxxx"

$oIE = _IECreate ("https://")

$oIE2 = _IECreate ("http://")

_IELoadWait ($oIE)

$uForm = _IEFormGetObjByName ($oIE, "login_form")

$uText = _IEFormElementGetObjByName ($uForm, "email")

_IEFormElementSetValue ($uText,$user)

$pText = _IEFormElementGetObjByName ($uForm, "pass")

_IEFormElementSetValue ($pText,$pass)

_IEFormSubmit ($uForm)

Sleep (1500)

_IENavigate ($oIE2, "http://xxxxxxxxxxxxxxxxxx")

EndIf

WEnd

thankyou for your time

 
Edited by lostowl
Link to comment
Share on other sites

I dont know if you can include a udf in an if condition, but nonetheless it certainly isnt a good idea to do so in a while loop.

Also this is wrong "Or $nmsg = $Button2 Then"

And one more thing, the button dosent work because the code is badly flawed and dosent even run.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

lostowl, your code is wrong. You should try something like this:

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

$Form2 = GUICreate("Form2", 616, 552, 202, 132)
$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Login1()
        Case $Button2
            _Login2()
    EndSwitch
WEnd

Func _Login1()
    ;put your code for button1
    
EndFunc

Func _Login2()
    ;put your code for button2
    
EndFunc
Link to comment
Share on other sites

lostowl, your code is wrong. You should try something like this:

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

$Form2 = GUICreate("Form2", 616, 552, 202, 132)
$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Login1()
        Case $Button2
            _Login2()
    EndSwitch
WEnd

Func _Login1()
    ;put your code for button1
    
EndFunc

Func _Login2()
    ;put your code for button2
    
EndFunc

thanks works well now my only problem is how to set it so the red x in top right will close window and how to make it so once i press

button 1 i can press it agian or press button 2 without having to reopen the gui

Edited by lostowl
Link to comment
Share on other sites

lostowl, have you read the help file? It's located under %programfiles%\Autoit. This is the first thing you should do before using AutoIt.

... now my only problem is how to set it so the red x in top right will close window and how to make it so once i press

button 1 i can press it agian or press button 2 without having to reopen the gui

The code below does what you've just said above. I don't see any problem!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 600, 500)
$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Login1()
        Case $Button2
            _Login2()
    EndSwitch
WEnd

Func _Login1()
    ;put your code for button1
    MsgBox(0,"Congrats!","You've pressed button 1")
EndFunc

Func _Login2()
    ;put your code for button2
    MsgBox(0,"Congrats!","You've pressed button 2")
EndFunc
Link to comment
Share on other sites

lostowl, have you read the help file? It's located under %programfiles%\Autoit. This is the first thing you should do before using AutoIt.

The code below does what you've just said above. I don't see any problem!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 600, 500)
$Button1 = GUICtrlCreateButton("Button1", 0, 0, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 0, 24, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Login1()
        Case $Button2
            _Login2()
    EndSwitch
WEnd

Func _Login1()
    ;put your code for button1
    MsgBox(0,"Congrats!","You've pressed button 1")
EndFunc

Func _Login2()
    ;put your code for button2
    MsgBox(0,"Congrats!","You've pressed button 2")
EndFunc

yea it works bud i took out the MsgBox(0,"Congrats!","You've pressed button 2") line when i put in my code and it i cant click button 1 agian until message ok button is there anyway to take that option out so i dont need a popup?

thank you for your time

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