Jump to content

Recommended Posts

Posted (edited)

Hi guys When I run this part of my script     If GUICtrlRead(Input1) = "" Then on_Close()      it closes that gui window but still sends 0

I want it to send nothing if the user don't type anything

anyone know how to fix this?

thanks

this is my full script       the   GUICtrlRead(input1) = "" Then on_Close()    is near the bottom of the script

#RequireAdmin
#include <IE.au3>
#include <ComboConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <AutoEmail.au3>


Opt("GUIOnEventMode", 1)
AutoItSetOption ( "TrayIconDebug", 1 )

Global $AutoEmail, $AutoReplace_GUI = 9999, $Gmail_Button, $Hotmail_Button, $AutoReplace_Button = 9999  ; Predeclare the variables with dummy values to prevent firing the Case statements
Global $Gmail1_Button, $Gmail2_Button, $Hotmail1_Button, $Hotmail2_Button, $Input1, $Input2, $Input3, $Input4
Global $Gmail, $Hotmail, $cCombo, $cCombo2
Global $sFilename = @ScriptFullPath
Global $DataFromUser

 GUI_AutoEmail()



 Func GUI_AutoEmail()

     $AutoEmail = GUICreate("Auto Email", 339, 125, @DesktopWidth, @DesktopHeight)
     $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
     $aWin = WinGetPos($AutoEmail)
     WinMove($AutoEmail, "", @DesktopWidth - $aWin[2] - 4, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 4)

     GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")                                                                      ; Call a common GUI close function
     $Gmail_Button = GUICtrlCreateButton("Gmail", 64, 16, 49, 41, $BS_ICON)
     GUICtrlSetImage(-1, "C:\Program Files\AutoEmail\gmail_icon.ico", 1)

     $Hotmail_Button = GUICtrlCreateButton("Hotmail", 223, 16, 49, 41, $BS_ICON)
     GUICtrlSetImage(-1, "C:\Program Files\AutoEmail\MSMail_icon.ico", 1)
     Global $cCombo = GUICtrlCreateCombo("", 16, 72, 145, 25)
     GUICtrlSetData(-1, "YourAccount1@gmail.com|YourAccount2@gmail.com", "YourAccount1@gmail.com")

     $cCombo2 = GUICtrlCreateCombo("", 176, 72, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
     GUICtrlSetData(-1, "YourAccount1@hotmail.com|YourAccount2@hotmail.com", "YourAccount1@hotmail.com")

     Global $msg

     GUICtrlSetOnEvent(3, "On_Button")

     GUICtrlSetOnEvent(4, "On_Button")

     GUICtrlSetOnEvent(-1, "On_Button")                                                                                ; Call a common button function

     $AutoReplace_Button = GUICtrlCreateButton("Add Your Email", 10, 100, 80, 30)

     GUICtrlSetOnEvent(-1, "On_Button")                                                                                ; Call a common button function
     GUISetState()


EndFunc

Func On_Button()
     Switch @GUI_CTRLID                                                                                                   ; See which button sent the message

         Case $Gmail_Button
              Gmail()

         Case $Hotmail_Button
             Hotmail()

         Case $AutoReplace_Button
             GUICtrlSetState($AutoReplace_Button, $GUI_DISABLE)
             GUI_AutoReplace()


         Case $Gmail1_Button
             AddEmail1()


         Case $Gmail2_Button
             AddEmail2()

         Case $Hotmail1_Button
             AddEmail3()

         Case $Hotmail2_Button
             AddEmail4()
EndSwitch
EndFunc
;--------------------------------------- This is the Main App Read Combos ---------------------------------------------------------------------


While 1
Sleep(10)
     WEnd


Func Gmail()
$DataFromUser = GUICtrlRead($cCombo)
If $DataFromUser = "YourAccount1@gmail.com" Then
gmail_login1()
EndIf

$DataFromUser = GUICtrlRead($cCombo)
If $DataFromUser = "YourAccount2@gmail.com" Then
gmail_login2()

EndIf
EndFunc

Func Hotmail()
$DataFromUser = GUICtrlRead($cCombo2)
If $DataFromUser = "YourAccount1@hotmail.com" Then
hotmail_login1()
EndIf

$DataFromUser = GUICtrlRead($cCombo2)
If $DataFromUser = "YourAccount2@hotmail.com" Then
hotmail_login2()

EndIf
EndFunc

;----------------------------------------------------- This sends account info to web Browser & Logs in ------------------------------------------------------------
Func gmail_login1()
Sleep (60)

Global $oIE =_IECreate ("https://accounts.google.com/ServiceLogin?sacu=1&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Dtopnav-about-en&hl=en&service=mail")

    local $username = _IEGetObjByName ($oIE, "Email")
    Local $password = _IEGetObjByName ($oIE, "Passwd")

    Local $Email_button = _IEGetObjByName ($oIE, "Email")
    Local $Signin_button = _IEGetObjByName ($oIE,"signIn")

    _IEFormElementSetValue ($username, "YourAccount1@gmail.com")      ;<=====   Here you put your Gmail Account Name
    _IEFormElementSetValue ($password, "Your Password")               ;<=====   Here you put your Gmail Account Password

    _IEAction ($Email_button, "click")
    _IEAction ($Signin_button, "click")

EndFunc


Func gmail_login2()
Sleep(60)

Global $oIE =_IECreate ("https://accounts.google.com/ServiceLogin?sacu=1&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Dtopnav-about-en&hl=en&service=mail")

    local $username = _IEGetObjByName ($oIE, "Email")
    Local $password = _IEGetObjByName ($oIE, "Passwd")

    Local $Email_button = _IEGetObjByName ($oIE, "account-email")
    Local $Signin_button = _IEGetObjByName ($oIE,"signIn")

    _IEFormElementSetValue ($username, "YourAccount2@gmail.com")     ;<=====   Here you put your 2nd Gmail Account Name
    _IEFormElementSetValue ($password, "Your Password")              ;<=====   Here you put your 2nd Gmail Account Password

    _IEAction ($Email_button, "click")
    _IEAction ($Signin_button, "click")

EndFunc


Func hotmail_login1()
Sleep(60)

Global $oIE =_IECreate ("http://www.live.com")

    local $username = _IEGetObjByName ($oIE, "login")
    Local $password = _IEGetObjByName ($oIE, "passwd")
    Local $Signin_button = _IEGetObjByName ($oIE,"SI")

    _IEFormElementSetValue ($username, "YourAccount1@hotmail.com")    ;<=====   Here you put your Hotmail Account Name
    _IEFormElementSetValue ($password, "Your Password")               ;<=====   Here you put your Hotmail Account Password
    _IEAction ($Signin_button, "click")

EndFunc


Func hotmail_login2()
Sleep(60)

Global $oIE =_IECreate ("http://www.live.com")

    local $username = _IEGetObjByName ($oIE, "login")
    Local $password = _IEGetObjByName ($oIE, "passwd")
    Local $Signin_button = _IEGetObjByName ($oIE,"SI")

    _IEFormElementSetValue ($username, "YourAccount2@hotmail.com")    ;<=====   Here you put your Hotmail Account Name
    _IEFormElementSetValue ($password, "Your Password")               ;<=====   Here you put your Hotmail Account Password
    _IEAction ($Signin_button, "click")

EndFunc


Func On_Close()
     Switch @GUI_WINHANDLE                                                                                              ; See which GUI sent the CLOSE message
         Case $AutoEmail
             Exit                                                                                                       ; If it was this GUI - we exit <<<<<<<<<<<<<<<
        Case $AutoReplace_GUI
             GUIDelete($AutoReplace_GUI)                                                                                             ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<<
             GUICtrlSetState($AutoReplace_Button, $GUI_ENABLE)
     EndSwitch
 EndFunc


Func GUI_AutoReplace()

     $AutoReplace_GUI = GUICreate("Auto Add Email", 474, 324, 969, 306)

     $Input1 = GUICtrlCreateInput("", 24, 32, 329, 21)
     $Gmail1_Button = GUICtrlCreateButton("Add Gmail", 360, 30, 89, 25)
     $Label_AddGmail1 = GUICtrlCreateLabel("Type Your Gmail Account1", 24, 8, 131, 17)

     $Input2 = GUICtrlCreateInput("", 24, 106, 329, 21)
     $Gmail2_Button = GUICtrlCreateButton("Add Gmail", 360, 104, 89, 25)
     $Label_AddGmail2 = GUICtrlCreateLabel("Type Your Gmail Account2", 24, 82, 131, 17)

     $Input3 = GUICtrlCreateInput("", 24, 183, 329, 21)
     $Hotmail1_Button = GUICtrlCreateButton("Add Hotmail", 360, 181, 89, 25)
     $Label1 = GUICtrlCreateLabel("Type Your Hotmail Account1", 21, 159, 140, 17)

     $Input4 = GUICtrlCreateInput("", 24, 257, 329, 21)
     $Hotmail2_Button = GUICtrlCreateButton("Add Hotmail", 360, 255, 89, 25)
     $Label2 = GUICtrlCreateLabel("Type Your Homail Account2", 21, 233, 137, 17)

     GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")                                                                        ; Call a common GUI close function

     GUICtrlSetOnEvent(-1, "On_Button")                                                                                 ; Call a common button function

     GUICtrlSetOnEvent(9, "On_Button")

     GUICtrlSetOnEvent(12, "On_Button")

     GUICtrlSetOnEvent(15, "On_Button")

     GUICtrlSetOnEvent(18, "On_Button")

     GUICtrlSetOnEvent(3, "On_Button")

     GUICtrlSetOnEvent(4, "On_Button")

     GUISetState()

EndFunc


Func AddEmail1()
If GUICtrlRead($Input1) = "" Then On_Close()

$DataFromUser = GUICtrlRead($Input1)
_ReplaceStringInFile ($sFilename, $sFindg1, $DataFromUser)
;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16)

EndFunc

Func AddEmail2()
If GUICtrlRead($Input2) = "" Then On_Close()

$DataFromUser = GUICtrlRead($Input2)
_ReplaceStringInFile ($sFilename, $sFindg2, $DataFromUser)
;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16)
EndFunc

Func AddEmail3()
If GUICtrlRead($Input3) = "" Then On_Close()

$DataFromUser = GUICtrlRead($Input3)
_ReplaceStringInFile ($sFilename, $sFindh1, $DataFromUser)
;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16)

EndFunc

Func AddEmail4()
If GUICtrlRead($Input4) = "" Then On_Close()

$DataFromUser = GUICtrlRead($Input4)
_ReplaceStringInFile ($sFilename, $sFindh2, $DataFromUser)
;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16)

EndFunc
Edited by iresolver
Posted (edited)

iresolver,

Reading a "blank" input control does NOT return "0" as demonstrated here...

#include <GUIConstantsEx.au3>

local $gui010 = guicreate('')
local $inp010 = guictrlcreateinput('',10,10,100,20)
guisetstate()

Local $aAc[1][2] = [["{ENTER}", $inp010]]
GUISetAccelerators($aAC,$gui010)

while 1
    switch guigetmsg()
        case $gui_event_close
            ConsoleWrite('Inp010 = [' & guictrlread($inp010) & ']' & @CRLF)
            Exit
        case $inp010
            ConsoleWrite('Inp010 = [' & guictrlread($inp010) & ']' & @CRLF)
    EndSwitch
WEnd

Trouble shooting your code is unnecessarily difficult because of:

1 - The code posted not being runnable

2 - The use of numbers in the guictrlsetonevent function

Why do you use a mix of var names and ctlid numbers anyway?

kylomas

edit: code correction

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

it's not going to work if you don't have my custom #include <AutoEmail.au3>

sorry about that

the script does a find and replace & I couldn't have what's in the AutoEmail.au3 in the main script or it would change that too so I put it in a separate include file

if anyone knows a better way to do this without a separate include file i would love hear it!

the #include file looks like this

 
Local $sFindyg1 = "yourAccount1@gmail.com"
Local $sFindyg2 = "yourAccount2@gmail.com"
Local $sFindyh1 = "yourAccount1@hotmail.com"
Local $sFindyh2 = "yourAccount2@hotmail.com"
 
Local $sFindygp1 = "your gmail password1"
Local $sFindygp2 = "your gmail password2"
Local $sFindyhp1 = "your hotmail password1"
Local $sFindyhp2 = "your hotmail password2"
Posted

iresolver,

Data like this

Local $sFindyg1 = "yourAccount1@gmail.com"

Local $sFindyg2 = "yourAccount2@gmail.com"

Local $sFindyh1 = "yourAccount1@hotmail.com"

Local $sFindyh2 = "yourAccount2@hotmail.com"

 

Local $sFindygp1 = "your gmail password1"

Local $sFindygp2 = "your gmail password2"

Local $sFindyhp1 = "your hotmail password1"

Local $sFindyhp2 = "your hotmail password2"

sometimes referred to as "external data" is better stored outside of the code itself.  This allows the code and data to be changed independently.  For simple data like this an INI file or simple flat file will do.

I still do not understand why you are referring to your controls by ID and not name.  And why not set the event immediately after creating the control and refer to it as "-1"?

kylomas

 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
×
×
  • Create New...