Jump to content

how to connect a script to a menu?


Recommended Posts

so i been trying to figure this out for days now i have this lesson 5 script i trying to modify to link "each day of the link" to run a different login script for each site i goto. instead of doing something random

lesson 5 from autoit 1 2 3

; Script Format Demonstration.

; 1. Place required include files.

; 2. Set Autoit options, as needed.

; 3. Declare Variables.

; 4. Set Desired Hot Keys.

; 5. Create the GUI.

; 6. Display the GUI.

; 7. Set/Update control information.

; 8. Set the Tray Menu

; 9. Start the Loop, and "Listen" for a message.

; 10. Create the Functions.

; here is an Example

; 1. Includes

#include <GuiConstants.au3>

#include <String.au3>

; 2. Autoit Options

Opt("GUICloseOnESC", 1)

;1 = ESC closes script, 0 = ESC won't close.

Opt("TrayMenuMode", 1)

; Default tray menu items (Script Paused/Exit) will not be shown.

Opt("TrayOnEventMode", 1)

;TraySetClick (16); right click

; 3. Declare Variables use, Dim, Global or Local.

Dim $Text, $Cloudy = 1

; see help for more info.

; 4. Set Hot Keys

HotKeySet("{F1}", "About_GUI")

; when F1 is pressed, goto function "About_GUI".

; 5. Create the GUI

$Window = GUICreate("My Weather Program")

$combo = GUICtrlCreateCombo("", 120, 50, 150, 20)

$button = GUICtrlCreateButton("Press here for Daily Weather Report", 100, 300, 200, 40)

; 6. Display the GUI

GUISetState()

; 7. Set the control information

; this will split the string called $days, by each comma.

$days = StringSplit("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ",")

; the return is an array $days[0] is 7, the total

; $days[1] contains "Sunday" ... $days[7] contains "Saturday"

; this will use a for/next loop to set the $combo information with the $days.

For $x = 1 To $days[0]

GUICtrlSetData($combo, $days[$x])

Next

; 8. Set the tray menu

$About_tray = TrayCreateItem("About Weather")

TrayItemSetOnEvent(-1, "About_GUI")

TrayCreateItem("")

$exit_tray = TrayCreateItem("Exit Weather")

TrayItemSetOnEvent(-1, "Set_Exit")

TraySetState()

; 9. Start the loop

While 1

; "Listen" for the message

$message = GUIGetMsg()

If $message = $GUI_EVENT_CLOSE Then Set_Exit()

If $message = $button Then

; read the selected day in the combo

$Text = GUICtrlRead($combo)

; call the function with the info

Day_Function($Text)

EndIf

WEnd

; 10. Create the Functions

Func Day_Function($Text)

If $Text = "" Then Return

; randomly choose amount of rain

$rain = Random(5, 100, 1)

; call another function for clouds

Cloud_Function()

If $Cloudy = 1 Then

$Clouds = "Cloudy"

Else

$Clouds = "Clear"

EndIf

; show the weather information.

MsgBox(64, "Your Weather", "On " & $Text & " You can expect, " & @CRLF & $Clouds & " skies in the afternoon and evening " & @CRLF & _

"The chance of rain is approximately " & $rain & " percent ")

EndFunc ;==>Day_Function

Func Cloud_Function()

If $Cloudy = 1 Then

$Cloudy = 2

; leave this function now

Return

EndIf

If $Cloudy = 2 Then

$Cloudy = 1

Return

EndIf

EndFunc ;==>Cloud_Function

Func About_GUI()

MsgBox(64, "Welcome!", " this is your Weather Service ")

EndFunc ;==>About_GUI

Func Set_Exit()

MsgBox(0, "", "Good-Bye!", 1)

Exit

EndFunc ;==>Set_Exit

; All of these functions are UDF's, User Defined Functions

; When you have completed a Script use Tidy under "Tools" above to "clean" it up.

; Then make a comment at the top, like this

#cs ===============================================================================

*AutoIt 1-2-3 ver 1.0.1 - 02.01.2006

Autor: Valuater

E-mail: XPCleanMenu@aol.com

Language: English

OSystem: Windows Xp

Requirements: Legal copy of Microsoft Windows Xp

Construction: AutoIt 3.1.1+, SciTE 1.64

Features: Automated Program, Reads Text, Runs Scripts, etc

- Use = Tutorials, Help Files, Installers, Presentations, etc

- ...

Thanks to all, Enjoy...

#ce ===============================================================================

and i want to make a different one of these scripts for each website i goto but cannot figure out how to link it to the buttons

#include <IE.au3>

$user = "xxxxxxxxxxxxxxxx"

$pass = "xxxxx"

$oIE = _IECreate ("https:")

_IELoadWait ($oIE)

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

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

_IEFormElementSetValue ($uText,$user)

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

_IEFormElementSetValue ($pText,$pass)

_IEFormSubmit ($uForm)

_IENavigate ($oIE, "http://www.autoitscript.com/forum/index.php?")

thankyou for your time

Link to comment
Share on other sites

This is...

Option 1:

; 1. Includes
#include <GuiConstants.au3>
#include <String.au3>
#include <IE.au3>

; 2. Autoit Options
Opt("GUICloseOnESC", 1)
;1 = ESC closes script, 0 = ESC won't close.
Opt("TrayMenuMode", 1)
; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode", 1)
;TraySetClick (16); right click

; 3. Declare Variables use, Dim, Global or Local.
Dim $Text, $Cloudy = 1
; see help for more info.

; 4. Set Hot Keys
HotKeySet("{F1}", "About_GUI")
; when F1 is pressed, goto function "About_GUI".

; 5. Create the GUI
$Window = GUICreate("My Weather Program")
$combo = GUICtrlCreateCombo("", 120, 50, 150, 20)
$button = GUICtrlCreateButton("Press here for Daily Weather Report", 100, 300, 200, 40)

; 6. Display the GUI
GUISetState()

; 7. Set the control information

; this will split the string called $days, by each comma.
$days = StringSplit("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ",")
; the return is an array $days[0] is 7, the total
; $days[1] contains "Sunday" ... $days[7] contains "Saturday"

; this will use a for/next loop to set the $combo information with the $days.
For $x = 1 To $days[0]
    GUICtrlSetData($combo, $days[$x])
Next

; 8. Set the tray menu
$About_tray = TrayCreateItem("About Weather")
TrayItemSetOnEvent(-1, "About_GUI")
TrayCreateItem("")
$exit_tray = TrayCreateItem("Exit Weather")
TrayItemSetOnEvent(-1, "Set_Exit")

TraySetState()

; 9. Start the loop
While 1
    ; "Listen" for the message
    $message = GUIGetMsg()

    If $message = $GUI_EVENT_CLOSE Then Set_Exit()

    If $message = $button Then
        ; read the selected day in the combo
        $Text = GUICtrlRead($combo)
        ; call the function with the info
        Day_Function($Text)
    EndIf

WEnd

; 10. Create the Functions

Func About_GUI()
    MsgBox(64, "Welcome!", " this is your Weather Service ")
EndFunc   ;==>About_GUI

Func Set_Exit()
    MsgBox(0, "", "Good-Bye!", 1)
    Exit
EndFunc   ;==>Set_Exit

Func Day_Function($Text)
    If $Text = "" Then Return   
    ; show the weather information. 
    Switch $Text
        Case "Sunday"
            _WebsiteSunday()
        Case "Monday"
            _WebsiteMonday()
        Case "Tuesday"
            _WebsiteTuesday()
        Case "Wednesday"
            _WebsiteWednesday()
        Case "Thursday"
            _WebsiteThursday()
        Case "Friday"
            _WebsiteFriday()
        Case "Saturday"
            _WebsiteSaturday()
        Case Else           
    EndSwitch
EndFunc   ;==>Day_Function

Func _WebsiteSunday()
    ;       
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteSunday

Func _WebsiteMonday()
    ;   
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteMonday

Func _WebsiteTuesday()
    ;
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteTuesday

Func _WebsiteWednesday()
    ;
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteWednesday

Func _WebsiteThursday()
    ;
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteThursday

Func _WebsiteFriday()
    ;
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteFriday

Func _WebsiteSaturday()
    ;
    $user = "xxxxxxxxxxxxxxxx"
    $pass = "xxxxx"
    $oIE = _IECreate("https:")
    _IELoadWait($oIE)

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
EndFunc     ;==>_WebsiteSaturday

Option 2:

; 1. Includes
#include <GuiConstants.au3>
#include <String.au3>
#include <IE.au3>

; 2. Autoit Options
Opt("GUICloseOnESC", 1)
;1 = ESC closes script, 0 = ESC won't close.
Opt("TrayMenuMode", 1)
; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode", 1)
;TraySetClick (16); right click

; 3. Declare Variables use, Dim, Global or Local.
Dim $Text, $Cloudy = 1
; see help for more info.

; 4. Set Hot Keys
HotKeySet("{F1}", "About_GUI")
; when F1 is pressed, goto function "About_GUI".

; 5. Create the GUI
$Window = GUICreate("My Weather Program")
$combo = GUICtrlCreateCombo("", 120, 50, 150, 20)
$button = GUICtrlCreateButton("Press here for Daily Weather Report", 100, 300, 200, 40)

; 6. Display the GUI
GUISetState()

; 7. Set the control information

; this will split the string called $days, by each comma.
$days = StringSplit("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ",")
; the return is an array $days[0] is 7, the total
; $days[1] contains "Sunday" ... $days[7] contains "Saturday"

; this will use a for/next loop to set the $combo information with the $days.
For $x = 1 To $days[0]
    GUICtrlSetData($combo, $days[$x])
Next

; 8. Set the tray menu
$About_tray = TrayCreateItem("About Weather")
TrayItemSetOnEvent(-1, "About_GUI")
TrayCreateItem("")
$exit_tray = TrayCreateItem("Exit Weather")
TrayItemSetOnEvent(-1, "Set_Exit")

TraySetState()

; 9. Start the loop
While 1
    ; "Listen" for the message
    $message = GUIGetMsg()

    If $message = $GUI_EVENT_CLOSE Then Set_Exit()

    If $message = $button Then
        ; read the selected day in the combo
        $Text = GUICtrlRead($combo)
        ; call the function with the info
        Day_Function($Text)
    EndIf

WEnd

; 10. Create the Functions

Func About_GUI()
    MsgBox(64, "Welcome!", " this is your Weather Service ")
EndFunc   ;==>About_GUI

Func Set_Exit()
    MsgBox(0, "", "Good-Bye!", 1)
    Exit
EndFunc   ;==>Set_Exit

Func Day_Function($Text)
    If $Text = "" Then Return   
    ; show the weather information. 
    Switch $Text
        Case "Sunday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Monday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Tuesday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Wednesday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Thursday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Friday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case "Saturday"
            $user = "xxxxxxxxxxxxxxxx"
            $pass = "xxxxx"
            $oIE = _IECreate("https:")
            _IELoadWait($oIE)
            _WebsiteConnect()
        Case Else           
    EndSwitch   
EndFunc   ;==>Day_Function

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

    $pText = _IEFormElementGetObjByName($uForm, "pass")
    _IEFormElementSetValue($pText, $pass)
    _IEFormSubmit($uForm)
    _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?")
    Return
EndFunc     ;==>_WebsiteConnect

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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