Sign in to follow this  
Followers 0
rafoster

Subroutine vs. Function? Or am I just smoking crack?

8 posts in this topic

Hello, I am brand new to scripting, and I am working my way through my second AutoIT Script and trying to clean it up.

Basically, I was injecting long Sleep commands into my script to allow time for IE browser loads. This of course is not the ideal situation, as if the page loads, why wait? And of course, on a slow link the whole script will get bollocksed.

So, after reading the forums here I decided to try the StatusBarGetText command to determine when the page had finished loading. It seems very squirrely, however... and it's probably because I am just not doing it right.

Func BrowserWaitUntilDone()

$BrowserDone = StatusBarGetText("Internet Explorer", "", 1)

If $BrowserDone = "Done" Then

Sleep("100")

EndIf

EndFunc

If I then put BrowserWaitUntilDone() into my script, it should work?

Am I using a function the wrong way? Should I be using a subroutine of some kind?

Please excuse the newbness, and thank you in advance for the help! :lmao:

Share this post


Link to post
Share on other sites



Well, assuming the rest of it works, you're going to want to change at least this one thing:

Func BrowserWaitUntilDone()

$BrowserDone = StatusBarGetText("Internet Explorer", "", 1)

While $BrowserDone <> "Done"

Sleep(100)

WEnd

EndFunc

As you had it, the function would go through once. If it was already done, it would sleep for a tenth of a second and then end. If it wasn't done, it would simply end. That's not what you want. You want it to wait until it is done, sleeping until then. When it finally is done, you can end. Also, there's no need to put quotes " " around numbers.

Share this post


Link to post
Share on other sites

Well, assuming the rest of it works, you're going to want to change at least this one thing:

Func BrowserWaitUntilDone()

$BrowserDone = StatusBarGetText("Internet Explorer", "", 1)

While $BrowserDone <> "Done"

Sleep(100)

WEnd

EndFunc

As you had it, the function would go through once. If it was already done, it would sleep for a tenth of a second and then end. If it wasn't done, it would simply end. That's not what you want. You want it to wait until it is done, sleeping until then. When it finally is done, you can end. Also, there's no need to put quotes " " around numbers.

Awesome! What exactly does "WEnd" do? Does that just mean end the loop once the criteria has been met? In this case, loop until $BrowserDone = "Done"?

Thanks a lot!

Share this post


Link to post
Share on other sites

Yes, WEnd is the End to the While (get it? WhileEnd). So yes again on your second statement - loop until $BrowserDone = "Done".

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For more clarification on the While loop: http://www.autoitscript.com/autoit3/docs/keywords/While.htm

check out http://www.autoitscript.com/autoit3/docs/i.../lang_loops.htm for more info on loops in AutoIt.

By the way, you might be coming from a background of VB or something similar? "Subroutines" are referred to as UDFs (User Defined Functions) in Autoit. o:)

;)

Matt :lmao:

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

@theguy0000 - Thank you very much! I have been wrestling with that for awhile! I don't have a programming background, I've been in IT Hardware/Network Infrastructure operations for 7 years now, and have literally done everything by hand except for NT Batch files and scripts like Kixstart. This is pretty new to me... I have to unlearn a lot of stuff it looks like.

@ACalcutt I am going through that UDF Library just now! Thank you for the link.

Awesome forum, you guys are great... I have a lot of reading to do it looks like, I really appreciate the help.

Share this post


Link to post
Share on other sites

Well i am new in the field of javascript and i am a asp.net developer. Well coding in C# or visual basic is much simpler than doing work in javascript. This scripting language is very tuf to understand without intellisense. But as i came to know after vs2008 it is possible to write them and compile them in a good ways.

Thank you

sambrown

Crack Cocaine

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