Sign in to follow this  
Followers 0
veerendra

Golbal Functions

13 posts in this topic

#1 ·  Posted (edited)

Hi, i tried to declare global function in my script but it was unable to run the script, no error is showing but it is not working

 

here is my code pls help me out

 
Opt("MouseCoordMode",0)

Global $first

$first=_WinWaitActivate("Web Page Blocked! - Mozilla Firefox","")



#region ---Au3Recorder generated code Start (v3.3.7.0)  ---

#region --- Internal functions Au3Recorder Start ---

Func _Au3RecordSetup()

Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc


#endregion --- Internal functions Au3Recorder End ---



Run('"C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe"')
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",91,249,1)
Sleep(1000)
MouseClick("left",377,470,1)
Sleep(1000)
MouseClick("left",490,465,1)
Sleep(1000)
MouseClick("left",363,241,1)
Sleep(1000)
MouseClick("left",345,342,1)
Sleep(1000)
_WinWaitActivate("Add Parental Control Exclusion","")
Sleep(1000)
MouseClick("left",256,71,1)
Sleep(1000)
Send("www.yahoo.com")
Sleep(1000)
MouseClick("left",226,134,1)
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",274,473,1)



Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
sleep(1000)
_WinWaitActivate("Google - Mozilla Firefox","")
sleep(1000)
MouseClick("left",269,90,1)
sleep(1000)
Send("{BACKSPACE}www.yahoo.com{DEL}{ENTER}")
sleep(1000)
_WinWaitActivate("Web Page Blocked! - Mozilla Firefox","")
Sleep(1000)
If $first<>_WinWaitActivate("Web Page Blocked! - Mozilla Firefox","") Then

    MouseClick("left",1256,15,1)
    Sleep(1000)
    _WinWaitActivate("Confirm close","")
    Sleep(1000)
    MouseClick("left",178,115,1)

Else
    _WinWaitActivate("FortiClient","")
    Sleep(1000)
    MouseClick("left",274,473,1)
EndIf
MouseClick("left",273,62,1)
sleep(1000)
_WinWaitActivate("New Tab - Mozilla Firefox","")
sleep(1000)
MouseClick("left",306,92,1)
sleep(1000)
Send("www.google.ca{ENTER}")
sleep(1000)
MouseClick("left",1256,15,1)
Sleep(1000)
_WinWaitActivate("Confirm close","")
Sleep(1000)
MouseClick("left",178,115,1)


_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",445,789,1)
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",489,465,1)
Sleep(1000)
MouseClick("left",351,169,1)
Sleep(1000)
MouseClick("left",385,347,1)
Sleep(1000)
_WinWaitActivate("Edit Parental Control Exclusion","")
Sleep(1000)
MouseClick("left",290,89,1)
Sleep(1000)
MouseClick("left",211,121,1)
Sleep(1000)
MouseClick("left",237,143,1)
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",275,472,1)

Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
Sleep(1000)
_WinWaitActivate("Google - Mozilla Firefox","")
Sleep(1000)
MouseClick("left",236,95,1)
Sleep(1000)
Send("{BACKSPACE}www.yahoo.com{DEL}{ENTER}")
Sleep(1000)
_WinWaitActivate("Yahoo Canada - Mozilla Firefox","")
Sleep(1000)
MouseClick("left",275,59,1)
Sleep(1000)
_WinWaitActivate("New Tab - Mozilla Firefox","")
Sleep(1000)
MouseClick("left",297,90,1)
Sleep(1000)
Send("www.yahoo.com{DEL}{ENTER}")
Sleep(1000)
MouseClick("left",1256,15,1)
Sleep(1000)
_WinWaitActivate("Confirm close","")
Sleep(1000)
MouseClick("left",178,115,1)

_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",446,793,1)
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",106,249,1)
Sleep(1000)
MouseClick("left",386,470,1)
Sleep(1000)
MouseClick("left",450,780,1)
Sleep(1000)
_WinWaitActivate("FortiClient","")
Sleep(1000)
MouseClick("left",463,466,1)
Sleep(1000)
MouseClick("left",350,169,1)
Sleep(1000)
MouseClick("left",366,344,1)
Sleep(1000)
MouseClick("left",262,471,1)
Sleep(1000)
MouseClick("left",610,-1,1)

#endregion --- Au3Recorder generated code End ---
Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



it is just startin. But not opening the application it self. 

If i remove Global=$first

$first= example and the IF condition . then it is running normally. But i want the IF conditions in my script.

Share this post


Link to post
Share on other sites

Please enclose your code in AutoIt tags (the blue AutoIt icon in the editor). This greatly enhances readability :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

veerendra,

Your if condition is comparing the content of $first to the return from the winwaitactivate function (a handle or 0).  What are you trying to compare?

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

Share this post


Link to post
Share on other sites

I am trying to winwaitactive only. I need if that window opens then only I have to run the script

Share this post


Link to post
Share on other sites

Your Function does not have a Return statement.  Therefore it will always return a value of 0.   See Return keyword in the help.

Share this post


Link to post
Share on other sites

I checked the return keyword, but i am not getting an idea how to use it here.

Share this post


Link to post
Share on other sites

veerendra,

If the expection for the value of $first is a window handle then this may help. Replace the current one with this one.

Func _WinWaitActivate($title, $text= "", $timeout = 0)
    If Not WinWait($title, $text, $timeout) Then Return 0
    If Not WinActive($title, $text) Then WinActivate($title, $text)
    Return WinWaitActive($title, $text, $timeout)
EndFunc

Returns a window handle on success. Returns 0 on failure, which would be timed out if a timeout is used.

:)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
sleep(1000)
_WinWaitActivate("Google - Mozilla Firefox","")
sleep(1000)
MouseClick("left",269,90,1)
sleep(1000)
Send("{BACKSPACE}www.yahoo.com{DEL}{ENTER}")
sleep(1000)
_WinWaitActivate("Yahoo Canada - Mozilla Firefox","")
Sleep(1000)
$first=_WinWaitActivate("Web Page Blocked!  - Mozilla Firefox","")
If $first<>_WinWaitActivate("Yahoo Canada - Mozilla Firefox","") Then
    MsgBox(0, "Error", "Please Check your Settings in Forticlient")
    Exit;
Else
MouseClick("left",273,62,1)
sleep(1000)
_WinWaitActivate("New Tab - Mozilla Firefox","")
sleep(1000)
MouseClick("left",306,92,1)
sleep(1000)
Send("www.google.ca{ENTER}")
sleep(1000)
MouseClick("left",1256,15,1)
Sleep(1000)
_WinWaitActivate("Confirm close","")
Sleep(1000)
MouseClick("left",178,115,1)
EndIf

Hi, here is my code, i am trying if Yahoo Canada <> $first then  exit the script with msg else should run the script. but even though it is <> to condition it is not processing forward

Edited by veerendra

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

AutoIt does not work well with Firefox. You'll have to use Internet Explorer, and the native IE functions. However, there are Firefox, Chrome, and Opera UDF's available on this Forum.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Hi, here is my code, i am trying if Yahoo Canada <> $first then  exit the script with msg else should run the script. but even though it is <> to condition it is not processing forward

Perhaps the vital part of your code could be like this?

Send("{BACKSPACE}www.yahoo.com{DEL}{ENTER}")
If WinWait("Yahoo Canada - Mozilla Firefox", "", 3) Then
    MsgBox(0, "Error", "Please Check your Settings in Forticlient")
    Exit
EndIf
_WinWaitActivate("Web Page Blocked!  - Mozilla Firefox","")

You could also use AdlibRegister to look for certain titles with WinExists and exit if detected. :)

Share this post


Link to post
Share on other sites

Perhaps the vital part of your code could be like this?

Send("{BACKSPACE}www.yahoo.com{DEL}{ENTER}")
If WinWait("Yahoo Canada - Mozilla Firefox", "", 3) Then
    MsgBox(0, "Error", "Please Check your Settings in Forticlient")
    Exit
EndIf
_WinWaitActivate("Web Page Blocked!  - Mozilla Firefox","")

You could also use AdlibRegister to look for certain titles with WinExists and exit if detected. :)

Thank you a lot it is working.... :)

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  
Followers 0